Author Topic: Destroying An Exact Amount.  (Read 317 times)

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Destroying An Exact Amount.
« on: August 16, 2011, 06:37:40 am »


                I'm using  DestroyObject(GetItemPossessedBy(oPC, "ZombieEar")); on a script for a conversation, but the problem is that i want to destroy an EXACT amount of said items on the PC's inventory, not a single item or all, but an EXACT amount.

I'm pretty sure i can just run that command as many times as i like, but i was wondering if there's another way to do it?

Thanks '<img'>
               
               

               


                     Modifié par Shiek2005, 16 août 2011 - 05:46 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #1 on: August 16, 2011, 07:35:29 am »


                 This is a script I'd made that's similar to what you want, where only a set number of non-stackable items are destroyed.  The "FOOD" tag would need to be changed to what you want removed, and the name likely to something more appropriate, but it should work for you despite being simplistic.

  Called from the main routine, oPC is the character, nCount is how many to destroy.

void RemoveFood (object oPC, int nCount)
{
 int nCounter = 1;
 object oItem = GetFirstItemInInventory (oPC);
      while (GetIsObjectValid (oItem) && nCounter <= nCount)
        {
         if (GetTag (oItem) == "FOOD")
             {
              DestroyObject  (oItem, 0.5);
              nCounter ++;
             }
         oItem = GetNextItemInInventory(oPC);
        }
}

Edit:  Note that, this script, being simple, doesn't check inside containers.  That can be done with a little tweaking if you'd need that aspect of it.
               
               

               


                     Modifié par Failed.Bard, 16 août 2011 - 06:37 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #2 on: August 16, 2011, 12:00:57 pm »


               Function - TakeNumItems
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #3 on: August 16, 2011, 07:24:49 pm »


                @Failed.Bard: Thanks for the script, but unfortunately i could not get it to compile. Maybe i didn't look hard enough.
@Lightfoot8: Thanks for the suggestion, but TakeNumItems wasn't very ideal because the items in questions are in stacks and there's something about that function not handling items in stacks correctly.
Took me a little bit, but after raiding the old NWN Forum archives i found this script which i pieced together with the appropriate reward commands and journal updates, i'll post it for future referrence as well as anyone who might have need of it


#include "x0_i0_partywide"
void main()
{
object oPC = GetPCSpeaker();
object oItem = GetFirstItemInInventory( oPC );
//25 = Number of items to take away from the PC.
int nCount = 0; while( oItem != OBJECT_INVALID && nCount < 25 )
{
//Zombie Ear = Tag of item(s) to take.
if ( GetTag( oItem ) == "ZombieEar" )
{
DestroyObject( oItem );
++nCount;
}
oItem = GetNextItemInInventory( oPC );
}
// Give 500 gold (to party) to the PC.
GiveGoldToAll(oPC, 500);
GiveXPToAll(oPC, 250);

// Update the party's journals.
AddJournalQuestEntry("AchieveQuest01", 2, oPC);
}
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #4 on: August 16, 2011, 11:27:09 pm »


               @ Shiek - The code that FB posted is a function, not a full script.

As to the code you posted above, there are some loopholes in there. You have no check to make sure that the party has 25 Zombie Ears. If they only have 20, then all 20 of those would be taken away. Related to that, you have no check for Ears before awarding the Gold, XP and the Journal Entry. As written, the PC could have zero Ears and still get the gold, XP journal update.

if(nCount == 24) // Since we started counting at 0, we look to see in nCount equals 24
{
// Give 500 gold (to party) to the PC.
GiveGoldToAll(oPC, 500);
GiveXPToAll(oPC, 250);

// Update the party's journals.
AddJournalQuestEntry("AchieveQuest01", 2, oPC);
}
               
               

               


                     Modifié par _Knightmare_, 16 août 2011 - 10:30 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #5 on: August 17, 2011, 03:50:37 am »


               

Failed.Bard wrote...


Edit:  Note that, this script, being simple, doesn't check inside containers.  That can be done with a little tweaking if you'd need that aspect of it.


Your script will already check all the items in the containers  in the inventory.  No tweeking needed.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #6 on: August 17, 2011, 06:48:09 am »


               

Lightfoot8 wrote...

Failed.Bard wrote...


Edit:  Note that, this script, being simple, doesn't check inside containers.  That can be done with a little tweaking if you'd need that aspect of it.


Your script will already check all the items in the containers  in the inventory.  No tweeking needed.





You know..all this time I thought you needed a second loop for container items. ':whistle:'

I just read the lexicon for GetFirst/NextItemInInventory and it does indeed cycle through items in containers as well.
Did this change at some point or has it always been like that?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #7 on: August 17, 2011, 07:06:00 am »


               @Ghost: I think it was the 1.68 update.  not sure though It happened before I was started messing with nwn
               
               

               
            

Legacy_Shiek2005

  • Full Member
  • ***
  • Posts: 179
  • Karma: +0/-0
Destroying An Exact Amount.
« Reply #8 on: August 17, 2011, 05:52:37 pm »


               

_Knightmare_ wrote...

@ Shiek - The code that FB posted is a function, not a full script.

As to the code you posted above, there are some loopholes in there. You have no check to make sure that the party has 25 Zombie Ears. If they only have 20, then all 20 of those would be taken away. Related to that, you have no check for Ears before awarding the Gold, XP and the Journal Entry. As written, the PC could have zero Ears and still get the gold, XP journal update.

if(nCount == 24) // Since we started counting at 0, we look to see in nCount equals 24
{
// Give 500 gold (to party) to the PC.
GiveGoldToAll(oPC, 500);
GiveXPToAll(oPC, 250);

// Update the party's journals.
AddJournalQuestEntry("AchieveQuest01", 2, oPC);
}


Ummm.....oops?':whistle:'
lol

As for my script, i know it most likely has it's flaws, i'm actually surprised i was able to put that together into something that did what i needed it to.
But for what i need it, i don't need it to check if the PC actually has the number of items, i just need it to take ALL of them and give the xp, gp and journal update to the PC. The script goes on a conversation and i already have a text appears when script that'll only make the option to trade-in the quest available if the PC has the quest (journal entry) AND 25 of the quest items.

Thanks!