Fester Pot wrote...
The TAG of the items start with GP_blahblah and I'm trying to take those away from the player when entering a trigger - single player - but I can't figure out what I've done wrong. The script compiles fine, the items are available on the player with the GP_ TAG of items and a holding container that the items are copied over to.
Yet, the items remain in the inventory of the character. The container also remains empty after the script fires.
void main()
{
string sTag;
object oTo = GetObjectByTag(sTag);
object oPC = GetEnteringObject();
object oItem = GetFirstItemInInventory(oPC);
if (!GetIsPC(oPC)) return;
while(GetIsObjectValid(oItem))
{
if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "GP_")
{
sTag = "STOLENPC_ITEMS";
oTo = GetObjectByTag(sTag);
CopyItem(oItem, oTo, TRUE);
DestroyObject(oItem);
}
oItem = GetNextItemInInventory(oPC);
}
}
Thanks,
FP!
For efficiencies sake, though it won't make any noticeable difference, likely these four lines should simply be combined:
string sTag;
object oTo = GetObjectByTag(sTag);
sTag = "STOLENPC_ITEMS";
oTo = GetObjectByTag(sTag);
into:
object oTo = GetObjectByTag("STOLENPC_ITEMS");
Leaving you with:
void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
object oTo = GetObjectByTag("STOLENPC_ITEMS");
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{
if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "GP_")
{
CopyItem(oItem, oTo, TRUE);
DestroyObject(oItem);
}
oItem = GetNextItemInInventory(oPC);
}
}
Edit: If you might be removing more than one item from the characters inventory, you'll want to delay destroying the items by 0.1, since without the delay it can cause items to be skipped.
Modifié par Failed.Bard, 07 septembre 2011 - 06:41 .