Why doesn't this work?

Please post any questions about developing your plugin here. Please use the search function before posting!
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Why doesn't this work?

Postby 8guawong » Wed Sep 24, 2014 4:17 pm

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??
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Sep 24, 2014 6:29 pm

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.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Wed Sep 24, 2014 11:11 pm

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!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Oct 05, 2014 1:01 am

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
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Oct 05, 2014 1:09 am

Well, I didn't reply either since the last time I had read this thread, he was saying it was working. :rolleyes:
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Sun Oct 05, 2014 1:28 am

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 159 guests