Hook functions

Functions


get_sfall_arg

mixed get_sfall_arg()

Gets the next argument from sfall. Each time it’s called it returns the next argument, or otherwise it returns 0 if there are no more arguments left. You can arbitrarily get the value of any argument using the sfall_func1("get_sfall_arg_at", argNum) function.


get_sfall_arg_at

sfall.h

mixed get_sfall_arg_at(int argNum)

Gets the value of hook argument with the specified argument number (first argument of hook starts from 0)


get_sfall_args

int get_sfall_args()

Returns all hook arguments as a new temp array.


init_hook

int init_hook()

The hook script equivalent of game_loaded; it returns 1 when the script is loaded for the first time or when the player reloads the game, and 0 otherwise.


register_hook

void register_hook(int hookID)

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 procedure will be executed in current global script. You can use all above functions like normal.


register_hook_proc

void register_hook_proc(int hookID, proc procedure)

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 with no conflicts) and flexibility. You can place all related hook scripts for a specific mod in one global script!

Use zero (0) as second argument to unregister hook script from current global 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. 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.

Example: Sometimes you need to multiply certain value in a chain of hook scripts. Let’s say we have a Mod A which reduces all “to hit” chances by 50%. The code might look like this:

original_chance = get_sfall_arg;
set_sfall_return(original_chance / 2);

Mod B also want to affect hit chances globally, by increasing them by 50%. Now in order for both mods to work well together, we need to add this line to Mod A hook script:

set_sfall_arg(0, (original_chance / 2));

This basically changes hook argument for the next script. Mod B code:

original_chance = get_sfall_arg;
set_sfall_return(original_chance * 1.5);
set_sfall_arg(0, (original_chance * 1.5));

So if you combine both mods together, they will run in chain and the end result will be a 75% from original hit chance (hook register order doesn’t matter in this case, if you use set_sfall_arg in both hooks).

The defines to use for the hookID are in sfall.h.


register_hook_proc_spec

void register_hook_proc_spec(int hookID, procedure proc)

Works the same as register_hook_proc, except that it registers the current script at the end of the hook script execution chain (i.e. the script will be executed after all previously registered scripts for the same hook, including the hs_<name>.int script). In addition, all scripts hooked to a single hook point with this function are executed in the exact order of how they were registered. In the case of using register_hook and register_hook_proc functions, scripts are executed in reverse order of how they were registered. The execution chain of script procedures for a hook is as follows: 1. Procedures registered with register_hook and register_hook_proc functions (executed in reverse order of registration). 2. The hs_<name>.int script. 3. Procedures registered with the register_hook_proc_spec function (executed in the exact order of registration).


set_sfall_arg

void set_sfall_arg(int argNum, int value)

Changes argument value. The argument number (argNum) is 0-indexed. This is useful if you have several hook scripts attached to one hook point (see register_hook_proc).


set_sfall_return

void set_sfall_return(any value)

Used to return the new values from the script. Each time it’s called it sets the next value, or if you’ve already set all return values it does nothing.