Page 1 of 1

Why doesn't this work?

Posted: Wed Sep 24, 2014 4:17 pm
by 8guawong
Hello every1! I decided to try to convert my script from ES to SP so I can use my scripts in CSGO :grin:
could some1 tell me why the following does not work?
it always print not allowed...

Syntax: Select all

from path import Path
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from filters.players import PlayerIter
from events import Event
from messages import SayText2

allowed_list = []

def load():
base_path = Path(__file__).parent
with open(base_path + '/allowed.txt', 'r') as open_allowed_file:
for line in open_allowed_file:
allowed_list.append(line.rstrip())

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if player.team == 3:
if not check_player(player.steamid):
player.set_team(2)
SayText2(message="You are not allowed on CT!").send()
else:
if not check_ratio():
player.set_team(2)
SayText2(message="Too many CT!").send()

def check_player(steamid):
if steamid in allowed_list:
return 1
return 0

def check_ratio():
ct = len(PlayerIter('ct'))
t = len(PlayerIter('t'))
ct_allowed = int(t/3)
if ct > ct_allowed:
return 0
else:
return 1


allowed.txt

Code: Select all

STEAM_1:0:16817999


also one question about steamid
steamid from http://steamidfinder.com/ is different from the steamid from csgo..
why??

Posted: Wed Sep 24, 2014 6:29 pm
by L'In20Cible
Please, always provide your entire code (including the imports, etc.) and the content of all related files (in your case, allowed.txt...), as well. That said, parsing the allowed.txt file every time a player spawn is a little bit excessive, no? You should parse it once in the global scope and/or into the load function. However, instead of closing the file yourself, you should take a look at the with statement which will take care of closing it for you.

Posted: Wed Sep 24, 2014 11:11 pm
by 8guawong
L'In20Cible wrote:Please, always provide your entire code (including the imports, etc.) and the content of all related files (in your case, allowed.txt...), as well. That said, parsing the allowed.txt file every time a player spawn is a little bit excessive, no? You should parse it once in the global scope and/or into the load function. However, instead of closing the file yourself, you should take a look at the with statement which will take care of closing it for you.


ok i posted the whole code
and the content of the allowed.txt

thanks!

Posted: Sun Oct 05, 2014 1:01 am
by satoon101
Sorry for not replying till now, I forgot about this thread. Are you still having issues with this?

I have a couple bits of advice. If you are testing for True and False, you should return those values instead of 1 and 0. Use 1 and 0 when you actually mean to return an integer. Also, the check_player function is really unnecessary. And instead of using an if/else in your check_ratio, you can return the value of the if statement:

Syntax: Select all

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if player.team != 3:
return

if not player.steamid in allowed_list:
player.set_team(2)
SayText2(message="You are not allowed on CT!").send(player.index)
elif not check_ratio():
player.set_team(2)
SayText2(message="Too many CT!").send(player.index)


def check_ratio():
ct = len(PlayerIter('ct'))
t = len(PlayerIter('t'))
ct_allowed = int(t/3)
return ct > ct_allowed

Posted: Sun Oct 05, 2014 1:09 am
by L'In20Cible
Well, I didn't reply either since the last time I had read this thread, he was saying it was working. :rolleyes:

Posted: Sun Oct 05, 2014 1:28 am
by 8guawong
satoon101 wrote:Sorry for not replying till now, I forgot about this thread. Are you still having issues with this?

I have a couple bits of advice. If you are testing for True and False, you should return those values instead of 1 and 0. Use 1 and 0 when you actually mean to return an integer. Also, the check_player function is really unnecessary. And instead of using an if/else in your check_ratio, you can return the value of the if statement:

Syntax: Select all

@Event
def player_spawn(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
if player.team != 3:
return

if not player.steamid in allowed_list:
player.set_team(2)
SayText2(message="You are not allowed on CT!").send(player.index)
elif not check_ratio():
player.set_team(2)
SayText2(message="Too many CT!").send(player.index)


def check_ratio():
ct = len(PlayerIter('ct'))
t = len(PlayerIter('t'))
ct_allowed = int(t/3)
return ct > ct_allowed


yea i don't have issue now........ donno why............... LOL