A Hooks Library?

All other Source.Python topics and issues.
User avatar
MiBShidobu
Junior Member
Posts: 2
Joined: Mon Jul 09, 2012 5:10 am
Location: United States

A Hooks Library?

Postby MiBShidobu » 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:

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 28, 2012 2:00 pm

This seems very silly to me. What exactly would be the point of including this? Maybe your example is confusing me, but it seems pointless.

Also, 2 things with your first bit of code. First, in future versions (committed changes last night), it will be:[python]from events import Event[/python]
Second, you cannot declare custom names for events like that, nor will that be added in the future.

Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Tue Aug 28, 2012 2:30 pm

I don't see the point of this either.

Or do you mean something like pre-hooking events and preventing them from fireing and/or chageing the attributes before they actually fire?
Logifl3x
Junior Member
Posts: 17
Joined: Sat Jul 07, 2012 3:53 am

Postby Logifl3x » Sun Jan 20, 2013 8:08 am

Even though this is bumping a few month old thread but I have the same question. Is pre-hooking/detouring available to do at the moment and if so could someone explain how to do it.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jan 20, 2013 8:13 am

Not yet. I'm not sure, at this point, "when" it will get implemented, but it definitely will be at some point. I really don't think that is what MiBShidobu was referencing, though.

Satoon
Logifl3x
Junior Member
Posts: 17
Joined: Sat Jul 07, 2012 3:53 am

Postby Logifl3x » Sun Jan 20, 2013 8:48 am

Yeah I understand what you mean. I just didn't want to recreate a topic when there's one with the same topic.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 37 guests