need help using delay

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

need help using delay

Postby 8guawong » Fri Nov 14, 2014 11:28 am

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.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Nov 14, 2014 11:55 am

I guess you load your addon during a running round. So, when the round ends, "my_delay" is still 0.
8guawong
Senior Member
Posts: 148
Joined: Sat Sep 20, 2014 3:06 am

Postby 8guawong » Fri Nov 14, 2014 12:08 pm

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
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Nov 14, 2014 12:26 pm

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

Postby 8guawong » Sat Nov 15, 2014 12:13 am

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 :tongue:
anyway problem solved with canceling delay :cool:
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Nov 15, 2014 12:27 am

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

Postby 8guawong » Sat Nov 15, 2014 2:02 am

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 :cool:
but i DO remeber seeing the word repeat somewhere on the forum :cool:
but whatever using looped delay works for now :cool:

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 29 guests