Added final version of NPC armor appearance script, compatible with both HeroAppearance mod and set_dude_obj (NPC control) function #82

This commit is contained in:
phobos2077
2017-04-01 02:21:12 +07:00
parent 24e9dde577
commit 5bbdcbd2db
3 changed files with 57 additions and 25 deletions
+2
View File
@@ -13,6 +13,8 @@
NOTE: this script requires compiler from sfall modderspack with -s option NOTE: this script requires compiler from sfall modderspack with -s option
(short circuit evaluation) (short circuit evaluation)
version 1.0
**/ **/
#include "main.h" #include "main.h"
Binary file not shown.
+55 -25
View File
@@ -1,42 +1,70 @@
/* /*
WIP!!! NPC Armor Appearance mod
Used to replace the scripted part of B-Team mod.
Appropriate graphics are required for this mod to work.
Can be adopted to any mod by adjusting armor PIDs, NPC PIDs and NPC FIDs in INI file.
NOTE: this script requires compiler from sfall modderspack with -s option
(short circuit evaluation)
version 1.0
*/ */
#include "main.h" #include "main.h"
#define IS_ARMOR(item) (obj_type(item) == OBJ_TYPE_ITEM and obj_item_subtype(item) == item_type_armor)
variable variable
modIni := "npcarmor.ini", modIni := "npcarmor.ini",
defaultFids, defaultFids,
armorPidMap, // maps armor PID to it's "type" - leather armor, metal, power armor, etc. armorPidMap, // maps armor PID to it's "type" - leather armor, metal, power armor, etc.
npcMap; npcMap;
procedure check_armor_change(variable critter, variable item, variable isWorn) begin
variable npc, armorType, fid;
if (npcMap[obj_pid(critter)]) then begin
npc := npcMap[obj_pid(critter)];
if (not isWorn) then begin
// display_msg("No armor fid: " + npc["Default"]);
return npc["Default"];
end else if (item) then begin
armorType := armorPidMap[obj_pid(item)];
fid := npc[armorType] or defaultFids[armorType];
if (fid == 0 or fid == -1) then fid := npc["Default"];
// display_msg("Change fid: " + fid + ", npc: " + npc[armorType] + ", default:" + defaultFids[armorType]);
return fid;
end
end
return -1;
end
// for NPCs when they change armor themselves
procedure invenwield_handler begin procedure invenwield_handler begin
variable s, critter, item, slot, isWorn, npc, pid, armorType, fid; variable critter, item, fid, slot, isWorn;
critter := get_sfall_arg; critter := get_sfall_arg;
item := get_sfall_arg; item := get_sfall_arg;
slot := get_sfall_arg; slot := get_sfall_arg;
isWorn := get_sfall_arg; isWorn := get_sfall_arg;
s := "Wield: " + obj_name(critter); if (critter and item and slot == INVEN_TYPE_WORN) then begin
if (item) then fid := check_armor_change(critter, item, isWorn);
s += ", " + obj_name(item); if (fid != -1) then begin
s += ", " + slot + ", " + isWorn; art_change_fid_num(critter, fid);
display_msg(s); end
end
if (critter and item and critter != dude_obj and npcMap[obj_pid(critter)] and obj_type(item) == item_type_armor) then begin end
npc := npcMap[obj_pid(critter)];
if (not isWorn) then begin // when changing armor from inventory while controlling other NPCs
display_msg("No armor fid: " + npc["Default"]); procedure adjustfid_handler begin
art_change_fid_num(critter, npc["Default"]); variable fid, armor;
end else if (item) then begin if (dude_obj != real_dude_obj) then begin
armorType := armorPidMap[obj_pid(item)]; armor := critter_inven_obj(dude_obj, INVEN_TYPE_WORN);
fid := npc[armorType] or defaultFids[armorType]; fid := check_armor_change(dude_obj, armor, armor != 0);
if (fid >= 1) then begin if (fid != -1) then begin
display_msg("Change fid: " + fid); set_sfall_return(fid);
art_change_fid_num(critter, fid);
end
end end
end end
end end
@@ -46,10 +74,13 @@ procedure start begin
variable sect, sects, armorTypes, armorType, npc, pid, pids, i; variable sect, sects, armorTypes, armorType, npc, pid, pids, i;
if game_loaded then begin if game_loaded then begin
register_hook_proc(HOOK_INVENWIELD, invenwield_handler); register_hook_proc(HOOK_INVENWIELD, invenwield_handler);
register_hook_proc(HOOK_ADJUSTFID, adjustfid_handler);
defaultFids := get_ini_section(modIni, "Default"); defaultFids := get_ini_section(modIni, "Default");
fix_array(defaultFids); fix_array(defaultFids);
display_array(defaultFids); foreach (armorType: i in defaultFids) begin
defaultFids[armorType] := atoi(i);
end
armorPidMap := create_array_map; armorPidMap := create_array_map;
armorTypes := get_ini_section(modIni, "ArmorTypes"); armorTypes := get_ini_section(modIni, "ArmorTypes");
@@ -59,7 +90,6 @@ procedure start begin
armorPidMap[atoi(pid)] := armorType; armorPidMap[atoi(pid)] := armorType;
end end
end end
display_array(armorPidMap);
npcMap := create_array_map; npcMap := create_array_map;
@@ -69,15 +99,15 @@ procedure start begin
npc := create_array_map; npc := create_array_map;
npc["Default"] := atoi(sect["Default"]); npc["Default"] := atoi(sect["Default"]);
foreach (armorType: pids in armorTypes) begin foreach (armorType: pids in armorTypes) begin
npc[armorType] := atoi(sect[armorType]); if (sect[armorType]) then begin
npc[armorType] := atoi(sect[armorType]);
end
end end
npcMap[atoi(sect.PID)] := npc; npcMap[atoi(sect.PID)] := npc;
i += 1; i += 1;
sect := get_ini_section(modIni, ""+i); sect := get_ini_section(modIni, ""+i);
end end
display_array(npcMap[16777734]);
end end
end end