/* 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