A Hooks Library?
Posted: Tue Aug 28, 2012 12:53 pm
I was wondering if Source.Python will come with a hooking module for scripts. Sorta like how scripts can fire custom events but can instead make custom listeners/hooks that can return information back to the calling script. Sorta of like this:
And then another script can do this:
This way scripts can extend their functionality with hooks to change how it was gonna handle stuff.
Syntax: Select all
from Source import Player
from events.decorator import Event
from hooks import CallHook
@Event("player_activate")
def OnPlayerActivate(game_event):
# variable(list/tuple) = CallHook(<hookname>, <input variables>)
hook_args = CallHook("player_should_get_health", (Player.EdictOfUserid(game_event.GetInt('userid')), ))
if hook_args:
# do stuff
And then another script can do this:
Syntax: Select all
from hooks import Hook
# Works same way as Event method from events.decorator module.
@Hook("player_should_get_health")
def OnPlayerShouldGetHealth(player)
return (true, )
This way scripts can extend their functionality with hooks to change how it was gonna handle stuff.