Link Search Menu Expand Document

Функции крючков

Функции


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

funcX

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 proc 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, 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!).

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. 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:

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 very similar to 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_*.int script). All scripts hooked to a single hook point with this function are executed in exact order of how they were registered, as opposed to the description below, which refers to using register_hook/register_hook_proc functions.


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(int 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.