View previous topic :: View next topic |
Author |
Message |
Geno of the Azure Sun
Joined: 29 Dec 2006 Posts: 1
|
|
Back to top |
|
|
Rowell
Joined: 11 Nov 2006 Posts: 3
|
Posted: Thu Mar 01, 2007 18:34 Post subject: |
|
|
I have run into this problem as well in the past. It seems that when you cycle through a character's inventory, looking for a particular object...if you try to delete that object, it doesnt get removed right away. Therefore, when you're looking for "15 Rat Whiskers", it will count that first rat whisker 15 times.
One way to handle this problem is to first mark the item that you want to destroy with a Local Variable flagging it for destruction. Then create a new function that looks through the inventory for a specific item tag, and ignores any items that have been flagged for destruction.
Code: |
object GetTrackedItemPossessedBy(object oPC, string sTag){
object oItem;
string sTemp;
int iMaxItems = 100; // THIS WILL (HOPEFULLY) STOP ANY "TOO MANY INSTRUCTIONS" ERRORS FROM POPPING UP
int iLength;
int i = 0;
oItem = GetFirstItemInInventory(oPC);
sTag = GetStringLowerCase(sTag);
iLength = GetStringLength(sTag);
while (oItem != OBJECT_INVALID && i < iMaxItems) {
i++;
sTemp = GetStringLowerCase(GetTag(oItem));
if (GetStringLeft(sTemp, iLength) == sTag && !GetLocalInt(oItem, "DESTROY_ME"))
return oItem;
oItem = GetNextItemInInventory(oPC);
}
return OBJECT_INVALID;
}
|
And here's how you would change your search code:
Code: |
oItem = GetTrackedItemPossessedBy(oPC, "RatWhisker");
while (oItem != OBJECT_INVALID)
{
SetPlotFlag(oItem, FALSE);
SetLocalInt(oItem, "DESTROY_ME", TRUE);
DestroyObject(oItem);
iNoWhiskers++;
iGoldToGive++;
oItem = GetTrackedItemPossessedBy(oPC, "RatWhisker");
}
|
|
|
Back to top |
|
|
Zebranky
Joined: 04 Jun 2006 Posts: 415
|
Posted: Tue Mar 06, 2007 1:35 Post subject: |
|
|
Or loop through, count how many Rat Whiskers they have, and if they have enough, loop again and delete them. I don't like local vars when I can avoid them. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Tue Mar 06, 2007 4:59 Post subject: |
|
|
It's a bit more complicated but I had a NWN1 system for Contract Crafting.
The 'Contract' item keeps track of the 'remaining' item count.
Then I'd fire an EVENT to remove a 'Rat Whisker', the event would decrement the item count, if the item count was > 0 the 'event' would fire itself (again) until either the PC had no more 'Rat Whisker's or the 'remaining' count = 0
This way I'd only delete the first 'Rat Whisker' found each time the event was fired. AND because it was an event it runs as a 'new' instance of the script, and the delete occurs for the found 'Rat Whisker'
Sorry - don't have example code here at the office.
And never an issue with TMI
Cheers
Gryphyn |
|
Back to top |
|
|
|