logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Can some l33t scripter fix my mess please!

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Geno of the Azure Sun



Joined: 29 Dec 2006
Posts: 1

PostPosted: Mon Jan 01, 2007 17:41    Post subject: Can some l33t scripter fix my mess please! Reply with quote

Link to Code:
http://nwn2forums.bioware.com/forums/viewcodepost.html?post=4708434

All it does is take one rat whisker from the inventory and nothing else.

This one has me stumped.
Back to top
View user's profile Send private message
Rowell



Joined: 11 Nov 2006
Posts: 3

PostPosted: Thu Mar 01, 2007 18:34    Post subject: Reply with quote

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
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Tue Mar 06, 2007 1:35    Post subject: Reply with quote

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. Wink
Back to top
View user's profile Send private message Visit poster's website
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Mar 06, 2007 4:59    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group