Aller au contenu

Photo

Destroying An Exact Amount.


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
Shiek2005

Shiek2005
  • Members
  • 104 messages
 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 :)

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


#2
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
  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 .


#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Function - TakeNumItems

#4
Shiek2005

Shiek2005
  • Members
  • 104 messages
 @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);
}

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
@ 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 .


#6
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#7
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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?

#8
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
@Ghost: I think it was the 1.68 update. not sure though It happened before I was started messing with nwn

#9
Shiek2005

Shiek2005
  • Members
  • 104 messages

_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!