Page 1 of 1

PreEvent player_jump

Posted: Mon Dec 28, 2015 3:30 am
by roflmuffin
Hi there,

I cannot seem to use the @PreEvent decorator to hook the 'player_jump' event in CSGO. When I use the below:

Syntax: Select all

@Event('player_jump')
def jump_event(game_event):
print('Jump')


I receive 'Jump' in console everytime I jump, but this is of course a post hook. When I use the below code:

Syntax: Select all

@PreEvent('player_jump')
def jump_event(game_event):
print('Pre Jump')
return EventAction.CONTINUE


I never receive any output in console and it appears that the function is never run. Other pre hooks run fine (I tested player_spawn, player_death pre events). This is on SP version 205.

Posted: Mon Dec 28, 2015 5:33 am
by satoon101
I honestly don't know what to tell you. It works perfectly fine for me.

Posted: Mon Dec 28, 2015 2:25 pm
by stonedegg
Be sure you have 2 different function names for Event and PreEvent. If you have registered an Event with the function jump_event, you may not use jump_event for PreEvent, instead name it pre_jump_event or something.

Posted: Mon Dec 28, 2015 3:52 pm
by satoon101
I don't think that has ever been true. There was previously an issue where, if you used the same function name multiple times, only the last would be unloaded. Recent changes have fixed that, though. But, from what I can remember, there has never been an issue with registering using the same name.

I actually tested with the following before posting my last reply, and both messages were sent properly:

Syntax: Select all

from events import Event
from events.hooks import PreEvent

@Event('player_jump')
def player_jump(game_event):
print('Jump Event')

@PreEvent('player_jump')
def player_jump(game_event):
print('Pre Jump Event')

Posted: Fri Jan 01, 2016 1:25 pm
by BackRaw
Yeah, the function's address is stored as a callback by the decorator class, therefore the name sort of doesn't matter. Am I right?

Posted: Fri Jan 01, 2016 1:27 pm
by L'In20Cible
Correct, the name of the function itself doesn't matter.

Posted: Fri Jan 01, 2016 2:00 pm
by satoon101
Yes, it did used to matter on unload when we iterated over the __dir__ of each module.