Here's what is essentially GoG's script modified to use a Persistent int. Set/Get Persistent using aps_include (the default set of functions packaged with NWNX) uses exactly the same function parameters as bioware's Set/Get Local functions (with a few optional paramaters you don't need to worry about). It's designed to be intuitive. Just save this script as an include (it named it item_replace_inc in the example below):
#include "aps_include"
void ResRefMatchReplace(object oItem, object oTarget) {
string sResRef = GetResRef(oItem);
DestroyObject(oItem);
object oReplacement = CreateItemOnObject(sResRef, oTarget);
if (!GetIsObjectValid(oReplacement))
WriteTimestampedLogEntry("Character: " + GetName(oTarget) + " (playername: " +
GetPCPlayerName(oTarget) + "): No replacement item for " +GetName(oItem) +
" (resref: " + sResRef + ").");
}
void CheckReplaceItems(object oTarget){
if (!GetIsPC(oTarget) ||
GetPersistentInt(oTarget, "ItemsReplaced"))
return;
SetPersistentInt(oTarget, "ItemsReplaced", 1);
object oItem = GetFirstItemInInventory(oTarget);
int iSlot;
//Get items in inventory and replace if needed
while (GetIsObjectValid(oItem)) {
//if item is a container, loop through items inside
if (GetHasInventory(oItem)) {
object oConItem = GetFirstItemInInventory(oItem);
while (GetIsObjectValid(oConItem)) {
ResRefMatchReplace(oConItem, oTarget);
oConItem = GetNextItemInInventory(oItem);
}
} else
ResRefMatchReplace(oItem, oTarget);
oItem = GetNextItemInInventory(oTarget);
}
//Get equipped items and replace if necessary
for (iSlot=0; iSlot<NUM_INVENTORY_SLOTS; iSlot++) {
oItem = GetItemInSlot(iSlot, oTarget);
if (GetIsObjectValid(oItem))
ResRefMatchReplace(oItem, oTarget);
}
}
Then include it in the area onenter script for the first area pcs spend any substantial time. In that script, just Get the entering object, and call CheckReplaceItems on them, like so:
#include "item_replace_inc"
void main() {
object oEnter = GetEnteringObject();
CheckReplaceItems(oEnter);
}
If it generates lag hiccups from the mass replacements, let me know, and I'll write you one with recursive delays like the one I pasted on the first page of this thread.
LMK if you have any questions.
Funky
Modifié par FunkySwerve, 19 juin 2011 - 03:44 .