From 5bbdcbd2db630fdcc505e96ca42e81f4c57e9d9a Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Sat, 1 Apr 2017 02:21:12 +0700 Subject: [PATCH] Added final version of NPC armor appearance script, compatible with both HeroAppearance mod and `set_dude_obj` (NPC control) function #82 --- artifacts/mods/gl_highlighting.ssl | 2 + artifacts/mods/gl_npcarmor.int | Bin 0 -> 2618 bytes artifacts/mods/gl_npcarmor.ssl | 80 ++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 artifacts/mods/gl_npcarmor.int diff --git a/artifacts/mods/gl_highlighting.ssl b/artifacts/mods/gl_highlighting.ssl index a6290839..9b9cd23f 100644 --- a/artifacts/mods/gl_highlighting.ssl +++ b/artifacts/mods/gl_highlighting.ssl @@ -13,6 +13,8 @@ NOTE: this script requires compiler from sfall modderspack with -s option (short circuit evaluation) + version 1.0 + **/ #include "main.h" diff --git a/artifacts/mods/gl_npcarmor.int b/artifacts/mods/gl_npcarmor.int new file mode 100644 index 0000000000000000000000000000000000000000..2af91c20683fd3734ddfd3a2e33104c8421ebcde GIT binary patch literal 2618 zcmZo*I>5-lz#!DX3!<4!8dw?x8l)N&8l)N&8>AYP8l)PO8&n!p8`KyW7+4t?7}yw4 z08<2%YX_yF6j+>@fq@|eDgdRJ_dyw1P#Q|HT!1p_pfr?XErT)|7zFfC00RR9PfBW9 zVrfo^TV_fz0|QTDQEq-wKxT?>VgUmKM_xfPn86^DoRONG9S@d`PtHipOHXBBU=Yd7 zD@)BQ&rHopiO)#POUX$s0)<0jN>*ucNm?e7AX{-sVo?dh|NsC0GcYjxV_;%nU|`Z? zU|{o2EYJXjh^Cc7H3I_!i z%3@#;NKY+^&&M`JO&1+Zk7h4CWwn!A$pl7f#q4DCNMM@L-kjn=m*P#(ousk z)ICUkfSLgIEdy(V5vrfSx{!Pc_N@%AP=Jw1B=n#* zGlA5A{b>RXoouiwm|0+XP-)Qc5b7!hK64mVtPe0IOhV5Qfr1O%UHhaytja*Pxux1WBpv5D~U>VD%iJ zIAma8U~e#LFmEsbi@|aYM}tvQ7+3@v?;um4d{};BgP4Xa16IM-VAN#Zqz7ih>|kuL zgz~{IVe1lz*aU%3=2QCE} zpfSoh1Lh7e4VH)IM_9>;DAOQy4_FP{wJ>+U!WrsrP61FjgKA}HeS{P~O^~=`ZZLx8 U7B;9~U}lgM{u~RSHeo4g0g;k9uK)l5 literal 0 HcmV?d00001 diff --git a/artifacts/mods/gl_npcarmor.ssl b/artifacts/mods/gl_npcarmor.ssl index 9fe77704..2543ea3b 100644 --- a/artifacts/mods/gl_npcarmor.ssl +++ b/artifacts/mods/gl_npcarmor.ssl @@ -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" +#define IS_ARMOR(item) (obj_type(item) == OBJ_TYPE_ITEM and obj_item_subtype(item) == item_type_armor) + variable modIni := "npcarmor.ini", defaultFids, armorPidMap, // maps armor PID to it's "type" - leather armor, metal, power armor, etc. 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 - variable s, critter, item, slot, isWorn, npc, pid, armorType, fid; + variable critter, item, fid, slot, isWorn; critter := get_sfall_arg; item := get_sfall_arg; slot := get_sfall_arg; isWorn := get_sfall_arg; - s := "Wield: " + obj_name(critter); - if (item) then - s += ", " + obj_name(item); - s += ", " + slot + ", " + isWorn; - display_msg(s); - - if (critter and item and critter != dude_obj and npcMap[obj_pid(critter)] and obj_type(item) == item_type_armor) then begin - npc := npcMap[obj_pid(critter)]; - if (not isWorn) then begin - display_msg("No armor fid: " + npc["Default"]); - art_change_fid_num(critter, npc["Default"]); - end else if (item) then begin - armorType := armorPidMap[obj_pid(item)]; - fid := npc[armorType] or defaultFids[armorType]; - if (fid >= 1) then begin - display_msg("Change fid: " + fid); - art_change_fid_num(critter, fid); - end + if (critter and item and slot == INVEN_TYPE_WORN) then begin + fid := check_armor_change(critter, item, isWorn); + if (fid != -1) then begin + art_change_fid_num(critter, fid); + end + end +end + +// when changing armor from inventory while controlling other NPCs +procedure adjustfid_handler begin + variable fid, armor; + if (dude_obj != real_dude_obj) then begin + armor := critter_inven_obj(dude_obj, INVEN_TYPE_WORN); + fid := check_armor_change(dude_obj, armor, armor != 0); + if (fid != -1) then begin + set_sfall_return(fid); end end end @@ -46,10 +74,13 @@ procedure start begin variable sect, sects, armorTypes, armorType, npc, pid, pids, i; if game_loaded then begin register_hook_proc(HOOK_INVENWIELD, invenwield_handler); + register_hook_proc(HOOK_ADJUSTFID, adjustfid_handler); defaultFids := get_ini_section(modIni, "Default"); fix_array(defaultFids); - display_array(defaultFids); + foreach (armorType: i in defaultFids) begin + defaultFids[armorType] := atoi(i); + end armorPidMap := create_array_map; armorTypes := get_ini_section(modIni, "ArmorTypes"); @@ -59,7 +90,6 @@ procedure start begin armorPidMap[atoi(pid)] := armorType; end end - display_array(armorPidMap); npcMap := create_array_map; @@ -69,15 +99,15 @@ procedure start begin npc := create_array_map; npc["Default"] := atoi(sect["Default"]); foreach (armorType: pids in armorTypes) begin - npc[armorType] := atoi(sect[armorType]); + if (sect[armorType]) then begin + npc[armorType] := atoi(sect[armorType]); + end end npcMap[atoi(sect.PID)] := npc; i += 1; sect := get_ini_section(modIni, ""+i); end - - display_array(npcMap[16777734]); end end