whats a/the best "python" way to run a prehook for time x1 - x2 ?
i want to execute the prehook only for a specific amount of time.. thanks
create during-prehook
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
Re: create during-prehook
my guess ofc is creating a thread for this, but im wondering about the utilization in conjunction with the prehook decorator
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
Re: create during-prehook
this is the first way that comes to my mind, this doesnt handle a during mode, but the best performance probably?
Syntax: Select all
prehook_on = 0
@PreHook(user_message)
def pre_send_user_message(args):
if prehook_on:
print(args)
#dostuff
@SayCommand("1")
def say_test(command, index, team_only):
global prehook_on
prehook_on = 1
@SayCommand("2")
def say_test(command, index, team_only):
global prehook_on
prehook_on = 0
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
Re: create during-prehook
is this the best for an interval? :
Syntax: Select all
time_0 = 0
time_1 = 999999999999
@PreHook(user_message)
def pre_send_user_message(args):
if time_0 < time.time() < time_1:
print(args)
# do stuff
#just set time_0, time_1
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
Re: create during-prehook
ill use the last one, that will just work fine for my case. i forgot that sp can run multiple prehooks
Re: create during-prehook
All virtual functions can be hooked without needing to use the Pre/PostHook decorators. Just use the <vfunc>.add_hook method. Example below:
Sorry this is all typed on phone but hopes this helps ;)
Syntax: Select all
from entities.hooks import HookType
from events import Event
from players.entity import Player
g_hooked = False
@Event('player_spawn')
def _blah(event_data):
if g_hooked:
return
player = Player.from_userid(event_data['userid'])
player.drop_weapon.add_hook(HookType.PreHook, _new_callback)
global g_hooked
g_hooked = True
## I think you can use <vfunc>.remove_hook(<callback>)
## to delete it. I am unsure of the naming of that method :s
Sorry this is all typed on phone but hopes this helps ;)
Re: create during-prehook
For reference https://github.com/Source-Python-Dev-Te ... function.h
You could use .is_hooked instead of using a global after further reading, but that would require retrieving the Player instance all the time which is bad... Unless Ayuto/Satoon/L'Inc can enlighten me on a way to store the function reliably :D
You could use .is_hooked instead of using a global after further reading, but that would require retrieving the Player instance all the time which is bad... Unless Ayuto/Satoon/L'Inc can enlighten me on a way to store the function reliably :D
- PhantomDancer
- Member
- Posts: 42
- Joined: Wed Mar 15, 2017 10:39 am
- Location: The Great Arctic Hemispheres
Re: create during-prehook
you may misunderstand me a bit here. i was just wondering if it was possible to pause/resume a prehook "as simple as possible". to increase performance. i didnt know the performance drainage when i opened the thread. but i cant even close it too now. :P ( btw i was trying to write a sp performance display tool a year ago or so exactly for issues like this... so i wouldnt have to ask so much )
i came across this implementing the votemenu, listening on the send-usermsg prehook, thinking the client would send (multiple) some sort of replies, although i found out user"votes" come in through events, not usermsgs. usrmsgs send replies back via usrmsgs to other users about the vote, that technically could serve to intercept the votes, but its easier to hook the initial vote-event. satoon actually explained well in a github issue how the server sends the usermsgs. so i didnt need this anyway.
for whoever still wonders about this, i think in general it isnt a performance problem running "empty" pre/post hooks, much rather then loading/unloading them, looking at sps code on github. but i havent tested it. thanks for trying to help though predz
i came across this implementing the votemenu, listening on the send-usermsg prehook, thinking the client would send (multiple) some sort of replies, although i found out user"votes" come in through events, not usermsgs. usrmsgs send replies back via usrmsgs to other users about the vote, that technically could serve to intercept the votes, but its easier to hook the initial vote-event. satoon actually explained well in a github issue how the server sends the usermsgs. so i didnt need this anyway.
for whoever still wonders about this, i think in general it isnt a performance problem running "empty" pre/post hooks, much rather then loading/unloading them, looking at sps code on github. but i havent tested it. thanks for trying to help though predz
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 106 guests