From bb0f2bb8dbf23216b3ba3c6efe1b93629a76b5ad Mon Sep 17 00:00:00 2001 From: NovaRain Date: Fri, 24 Aug 2018 08:10:38 +0800 Subject: [PATCH] Changed the two example hook scripts to global scripts. --- ...plosivetimer.ssl => gl_explosivetimer.ssl} | 4 +- .../WithinPerception/gl_withinperception.ssl | 60 +++++++++++++++++++ .../WithinPerception/hs_withinperception.ssl | 58 ------------------ 3 files changed, 63 insertions(+), 59 deletions(-) rename artifacts/example_mods/ExplosiveTimer/{hs_explosivetimer.ssl => gl_explosivetimer.ssl} (92%) create mode 100644 artifacts/example_mods/WithinPerception/gl_withinperception.ssl delete mode 100644 artifacts/example_mods/WithinPerception/hs_withinperception.ssl diff --git a/artifacts/example_mods/ExplosiveTimer/hs_explosivetimer.ssl b/artifacts/example_mods/ExplosiveTimer/gl_explosivetimer.ssl similarity index 92% rename from artifacts/example_mods/ExplosiveTimer/hs_explosivetimer.ssl rename to artifacts/example_mods/ExplosiveTimer/gl_explosivetimer.ssl index 3b31fc6b..4628693a 100644 --- a/artifacts/example_mods/ExplosiveTimer/hs_explosivetimer.ssl +++ b/artifacts/example_mods/ExplosiveTimer/gl_explosivetimer.ssl @@ -14,7 +14,9 @@ procedure start; procedure start begin - if (init_hook == 0) then begin + if game_loaded then begin + register_hook(HOOK_EXPLOSIVETIMER); + end else begin variable time := get_sfall_arg, result := ROLL_CRITICAL_FAILURE; diff --git a/artifacts/example_mods/WithinPerception/gl_withinperception.ssl b/artifacts/example_mods/WithinPerception/gl_withinperception.ssl new file mode 100644 index 00000000..36690172 --- /dev/null +++ b/artifacts/example_mods/WithinPerception/gl_withinperception.ssl @@ -0,0 +1,60 @@ +/* + Example implementation of the algorithm of how the game engine checks if one critter sees another critter. + + NOTE: the AllowUnsafeScripting option must be enabled. +*/ + +#include "..\headers\define.h" +#include "..\headers\command.h" +#include "..\headers\sfall\sfall.h" +#include "..\headers\sfall\define_extra.h" + +#define can_see_(source, target) call_offset_r2(0x412BEC, source, target) +#define obj_dist_(target, source) call_offset_r2(0x48BBD4, target, source) + +procedure start; + +procedure start begin + if game_loaded then begin + register_hook(HOOK_WITHINPERCEPTION); + end else begin + variable + source := get_sfall_arg, + target := get_sfall_arg, + original := get_sfall_arg, + hookType := get_sfall_arg, /* new arg */ + result := 0, + distance; + + if target then begin + distance := get_critter_stat(source, STAT_pe); + + if can_see_(source, target) then begin + distance *= 5; + if (get_flags(target) bwand FLAG_TRANSGLASS) then distance /= 2; + end else if combat_is_initialized then begin + distance *= 2; + end + + if (target == dude_obj) then begin + if sneak_success then begin + distance /= 4; + if has_skill(target, SKILL_SNEAK) > 120 then distance -= 1; + end else if dude_is_sneaking then begin + distance := distance * 2 / 3; + end + end + + if obj_dist_(target, source) <= distance then result := 1; + + // example + if (result) then begin + display_msg("hs_withinperception: " + obj_name(source) + " sees " + obj_name(target) + " [original: " + original + " script: " + result + "]"); + end else begin + display_msg("hs_withinperception: " + obj_name(source) + " does not see " + obj_name(target) + " [original: " + original + " script: " + result + "]"); + end + end + + //set_sfall_return(result); + end +end diff --git a/artifacts/example_mods/WithinPerception/hs_withinperception.ssl b/artifacts/example_mods/WithinPerception/hs_withinperception.ssl deleted file mode 100644 index 2e8fd870..00000000 --- a/artifacts/example_mods/WithinPerception/hs_withinperception.ssl +++ /dev/null @@ -1,58 +0,0 @@ -/* - Example engine algorithm. - - * The AllowUnsafeScripting option must be enabled. -*/ - -#include "define_lite.h" -#include "command.h" - -#include "sfall.h" -#include "define_extra.h" - - -#define can_see_(source, target) call_offset_r2(0x412BEC, source, target) -#define obj_dist_(target, source) call_offset_r2(0x48BBD4, target, source) - -procedure start; - -procedure start begin - if not(init_hook) then begin - - variable source := get_sfall_arg, - target := get_sfall_arg, - original := get_sfall_arg, - type := get_sfall_arg, /* new arg */ - result := 0, - distance; - - if target then begin - distance := get_critter_stat(source, STAT_pe); - - if can_see_(source, target) then begin - distance *= 5; - if (get_flags(target) bwand FLAG_TRANSGLASS) then distance /= 2; - end - else if combat_is_initialized then distance *= 2; - - if target == dude_obj then begin - if sneak_success then begin - distance /= 4; - if has_skill(target, SKILL_SNEAK) > 120 then distance -= 1; - end - else if dude_is_sneaking then distance := distance * 2 / 3; - end - - if obj_dist_(target, source) <= distance then result := 1; - - // example - if (result) then begin - display_msg("hs_withinperception: " + obj_name(source) + " does he see > " + obj_name(target) + " [original: " + original + " script: " + result + "]"); - end else begin - display_msg("hs_withinperception: " + obj_name(source) + " he does not see > " + obj_name(target) + " [original: " + original + " script: " + result + "]"); - end - end - - //set_sfall_return(result); - end -end