Page 1 of 1
need help using delay
Posted: Fri Nov 14, 2014 11:28 am
by 8guawong
Syntax: Select all
from events import Event
from filters.players import PlayerIter
from listeners.tick import tick_delays
stop_check = 0
my_delay = 0
@Event
def round_end(game_event):
global stop_check
stop_check = 0
tick_delays.cancel_delay(my_delay)
@Event
def round_start(game_event):
check_human()
@Event
def player_death(game_event):
global stop_check
stop_check = 1
def check_human():
global my_delay
if stop_check == 1:
if len(PlayerIter(['ct', 'alive'])) != 0:
my_delay = tick_delays.delay(3, check_human)
else:
for userid in PlayerIter(['ct', 'alive'], return_types = 'userid'):
print("last human")
tick_delays.cancel_delay(my_delay)
else:
print("test")
my_delay = tick_delays.delay(3, check_human)
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File '../addons/source-python/packages/source-python/events/listener.py', line 90, in fire_game_event
callback(game_event)
File '../addons/source-python/plugins/test/test.py', line 21, in round_end
tick_delays.cancel_delay(my_delay)
File '../addons/source-python/packages/source-python/listeners/tick/delays.py', line 207, in cancel_delay
'tick_delays.cancel_delay requires a _Delay instance.')
TypeError: tick_delays.cancel_delay requires a _Delay instance.
Posted: Fri Nov 14, 2014 11:55 am
by Ayuto
I guess you load your addon during a running round. So, when the round ends, "my_delay" is still 0.
Posted: Fri Nov 14, 2014 12:08 pm
by 8guawong
ic i'll do some more testing
is there anyway to stop all the running delays?
because when i unload the script the delay is still running ... XD
Posted: Fri Nov 14, 2014 12:26 pm
by Ayuto
You have to cancel your delay when you unload your addon. But you don't really need a delay here (or even better a repeat). You can just use this snippet to get notified instantly without a possible delay.
Syntax: Select all
from events import Event
from filters.players import PlayerIter
@Event
def player_death(game_event):
check_last_human_ct()
@Event
def player_team(game_event):
# Called if a player disconnects or changes the team
check_last_human_ct()
def check_last_human_ct():
if len(PlayerIter(['ct', 'alive'])) == 1:
print('Last human CT')
Posted: Sat Nov 15, 2014 12:13 am
by 8guawong
Ayuto wrote:You have to cancel your delay when you unload your addon. But you don't really need a delay here (or even better a repeat). You can just use this snippet to get notified instantly without a possible delay.
Syntax: Select all
from events import Event
from filters.players import PlayerIter
@Event
def player_death(game_event):
check_last_human_ct()
@Event
def player_team(game_event):
# Called if a player disconnects or changes the team
check_last_human_ct()
def check_last_human_ct():
if len(PlayerIter(['ct', 'alive'])) == 1:
print('Last human CT')
yea i know i can do that but i just want to play with delay
anyway problem solved with canceling delay

Posted: Sat Nov 15, 2014 12:27 am
by satoon101
As Ayuto mentioned, though, if you want a repeating delay, it would be better to use a TickRepeat. I will work on that Wiki page tonight, but I think examples exist on the forums, somewhere.
Posted: Sat Nov 15, 2014 2:02 am
by 8guawong
satoon101 wrote:As Ayuto mentioned, though, if you want a repeating delay, it would be better to use a TickRepeat. I will work on that Wiki page tonight, but I think examples exist on the forums, somewhere.
yea i was searching for repeat but i couldn't find it
but i DO remeber seeing the word repeat somewhere on the forum
but whatever using looped delay works for now
