Added a new hook: HOOK_STDPROCEDURE

Optimized execution for global/hook scripts.
This commit is contained in:
NovaRain
2019-09-11 12:40:18 +08:00
parent e55a4f95d2
commit 693b78f9db
12 changed files with 94 additions and 28 deletions
+13 -6
View File
@@ -10,8 +10,6 @@ To aid in mods compatibility, avoid using hs_xxx .int scripts. Instead it is rec
Example setup for a hook-script based mod:
procedure tohit_hook_handler begin
display_msg("Modifying hit_hook " + get_sfall_arg);
set_hit_chance_max(100);
@@ -25,8 +23,6 @@ procedure start begin
end
There are script functions available, specific to hook scripts:
> int init_hook()
@@ -48,7 +44,7 @@ Changes argument value. The argument number (argnum) is 0-indexed. This is usefu
Used from a normal global script if you want to run it at the same point a full hook script would normally run. In case of this function, "start" proc will be executed in a current global script. You can use all above functions like normal.
> void register_hook_proc(int hook, procedure proc)
The same as register_hook, except that you specifically define which procedure in the current script should be called as a hook (instead of "start"). Pass procedure the same as how you use dialog option functions. This IS the recommended way to use hook scripts, as it gives both modularity (each mod logic in a separate global script, no conflicts if you don't use "hs_*.int" scripts) and flexibility (you can place all related hook scripts for specific mod in a single script!).
The same as register_hook, except that you specifically define which procedure in the current script should be called as a hook (instead of "start" by default). Pass procedure the same as how you use dialog option functions. This IS the recommended way to use hook scripts, as it gives both modularity (each mod logic in a separate global script, no conflicts if you don't use "hs_*.int" scripts) and flexibility (you can place all related hook scripts for specific mod in a single script!).
NOTE: you can hook several scripts to a single hook point, for example if it's different mods from different authors or just some different aspects of one larger mod. In this case scripts are executed in reverse order of how they were registered. When one of the scripts in a chain returns value with "set_sfall_return", the next script may override this value if calls "set_sfall_return" again. Sometimes you need to multiply certain value in a chain of hook scripts.
Example: let's say we have a Mod A which reduces all "to hit" chances by 50%. The code might look like this:
@@ -336,7 +332,6 @@ int arg4 - Type of hook (0 - when subtracting ammo after single shot attack,
int ret1 - new ammo cost value (set to 0 for unlimited ammo)
-------------------------------------------
HOOK_KEYPRESS (hs_keypress.int)
@@ -633,3 +628,15 @@ Critter arg3 - the critter (usually dude_obj)
int ret1 - overrides the result of the Sneak check
int ret2 - overrides the duration time for the current result
-------------------------------------------
HOOK_STDPROCEDURE (hs_stdprocedure.int)
Runs once every time before executing the standard procedure (handler) in the script of an object.
int arg1 - number of the standard script handler (see define.h, except: start, critter_p_proc, and map_update_p_proc)
Obj arg2 - the object connected to the executed script (self_obj)
Obj arg3 - the object that called this handler (source_obj, can be 0)
int ret1 - pass -1 to cancel the execution of the handler