Need script to repeat

Simple little ‘does PC have item in inventory, If yes, delete and reward xp and gp’ script.

I’d like it to repeat for every item in the players inventory that matches the item tag, but what I added does some strange things with rewarding xp and gp.

#include "nw_i0_tool"
void main()
{

object oPC = GetPCSpeaker();

object oItem;
oItem = GetFirstItemInInventory(oPC);

while (GetIsObjectValid(oItem))
   {
   if (GetTag(oItem)=="NW_IT_MSMLMISC13") DestroyObject(oItem);

//I added the following two lines
       RewardPartyXP(15, oPC, FALSE);
       RewardPartyGP(25, oPC, FALSE);

   
   oItem = GetNextItemInInventory(oPC);
   }

}

Currently it does take all the items with the item tag, but it’s rewarding the xp 50 times and gp a random number of times.

The way you wrote it, the rewards will be applied for every item regardless if it is the one you want to reward or not.

if (GetTag(oItem)=="NW_IT_MSMLMISC13")
{
       DestroyObject(oItem);
       RewardPartyXP(15, oPC, FALSE);
       RewardPartyGP(25, oPC, FALSE);
}

I would also recommend to calculate the total GP and XP reward, or rather calculate how many of the correct items there were and then reward the party once with the sum of the amount.

1 Like

Ah I see. I needed to specify the if tag for each reward and they were outside of the condition. I’ll look into the calculating bit next because I could use that elsewhere.

Thanks