Code changes to the previous commit

Changed HOOK_CANUSEWEAPON to run for both the player and NPCs.
Updated gl_npcarmor script.
This commit is contained in:
NovaRain
2021-09-02 11:23:24 +08:00
parent 428cf42c7d
commit 569bde5fab
8 changed files with 96 additions and 39 deletions
Binary file not shown.
+3 -3
View File
@@ -65,7 +65,7 @@ procedure check_weapon_change(variable critter, variable weapon, variable isWiel
weaponAnimList := npc["WeaponAnims"];
if (weaponAnimList != 0) then begin
foreach (i in string_split(weaponAnimList, ",")) begin
if (newWeaponAnim == atoi(i)) then return -1; // can use (engine default)
if (newWeaponAnim == atoi(i) and not(weapon_is_unusable(weapon))) then return -1; // can use (engine default)
end
end
return 0; // can't use
@@ -226,10 +226,10 @@ end
procedure canuseweapon_handler begin
variable critter, canWield;
critter := get_sfall_arg;
//if (critter) then begin
if (critter != dude_obj) then begin
canWield := check_weapon_change(critter, get_sfall_arg, true);
// override result
set_sfall_arg(3, canWield);
set_sfall_return(canWield);
//end
end
end
+5 -3
View File
@@ -289,9 +289,11 @@
// checks if the specified PID number exists in the list of registered protos
#define check_pid(pid) (get_proto_data(pid, 0) != -1)
// sets the status of a broken weapon that cannot be used in combat (the hand slot will not be available for use)
#define set_broken_weapon_state_on(item) set_object_data(item, OBJ_DATA_MISC_FLAGS, get_object_data(item, OBJ_DATA_MISC_FLAGS) bwor 0x00000010)
#define set_broken_weapon_state_off(item) set_object_data(item, OBJ_DATA_MISC_FLAGS, get_object_data(item, OBJ_DATA_MISC_FLAGS) bwand 0xFFFFFFEF)
// sets the status of an unusable weapon that cannot be used in combat
// use the HOOK_CANUSEWEAPON hook with weapon_is_unusable macro to override the engine value
#define set_weapon_unusable(item) set_object_data(item, OBJ_DATA_MISC_FLAGS, get_object_data(item, OBJ_DATA_MISC_FLAGS) bwor 0x00000010)
#define set_weapon_usable(item) set_object_data(item, OBJ_DATA_MISC_FLAGS, get_object_data(item, OBJ_DATA_MISC_FLAGS) bwand 0xFFFFFFEF)
#define weapon_is_unusable(item) (get_object_data(item, OBJ_DATA_MISC_FLAGS) bwand 0x00000010)
/* SFALL_FUNCX MACROS */
+5 -4
View File
@@ -897,13 +897,14 @@ Item ret0 - overrides the chosen best weapon
#### `HOOK_CANUSEWEAPON (hs_canuseweapon.int)`
Run when the AI checks whether it can use a weapon.
This mostly happens when NPCs try to find weapons in their inventory or on the map.
Run when the AI checks whether it can use a weapon, or when the game checks whether the player can use a weapon.
For AI, this mostly happens when NPCs try to find weapons in their inventory or on the map.
For the player, this happens when the game redraws the interface bar.
```
Critter arg0 - the critter doing the check
Item arg1 - the weapon being checked
int arg2 - attack type (see ATKTYPE_* constants)
Item arg1 - the item being checked
int arg2 - attack type (see ATKTYPE_* constants), or -1 for dude_obj
int arg3 - original result of engine function: 1 - can use, 0 - can't use
int ret0 - overrides the result of engine function. Any non-zero value allows using the weapon