Author Topic: Take stacked items give gold/xp for each item one click?  (Read 708 times)

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« on: March 22, 2011, 02:58:46 pm »


               Problem:This script so far only takes one item out of the stack and doesnt give the gold/xp reward.

What I need it to do:  I need the NPC to take all of an item stacked (ears ..etc.) and give 20gp and 20xp per item in the stack in one click.

Here what  I have that doesnt work.

void main(){    // Configuration:    int nToTake    = 1;                            // Number of items to take.    string sTag    = "misc001";         // Tag of items to take.    string sResRef = "Place_ResRef_of_Reward_Here"; // ResRef of item to give.
    // Other variables:    object oPC = GetPCSpeaker();    int nStackSize = 0;
    // First, abort if oPC does not have enough items.    if ( GetNumItems(oPC, sTag) < nToTake )    {        SpeakString("You do not have any proof.");        return;    }
    // Loop through oPC's inventory until enough items are taken    // (i.e. while something still needs to be taken).    // Checking for OBJECT_INVALID should not be needed, but it's a good safety measure.    object oItem = GetFirstItemInInventory(oPC);    while ( oItem != OBJECT_INVALID  &&  nToTake > 0 )    {        // Only deal with items with the desired tag.        if ( GetTag(oItem) == sTag )        {            // Determine what to do based on stack size.            nStackSize = GetItemStackSize(oItem);            if ( nStackSize > nToTake )            {                // Take the rest of what is needed from this stack.                SetItemStackSize(oItem, nStackSize - nToTake);                nToTake = 0;            }            else            {                // We'll be taking all of this, thank you very much.                DestroyObject(oItem);                nToTake -= nStackSize;            }        }
        // Update the loop.        oItem = GetNextItemInInventory(oPC);
    }
    // Reward the PC.      CreateItemOnObject(sResRef, oPC);       GiveGoldToCreature(oPC, 20);         GiveXPToCreature(oPC, 20);}
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #1 on: March 22, 2011, 03:01:10 pm »


               double post oops
               
               

               


                     Modifié par Knight_Shield, 22 mars 2011 - 03:02 .
                     
                  


            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #2 on: March 22, 2011, 05:17:47 pm »


               K, let me open the toolset.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #3 on: March 22, 2011, 05:22:56 pm »


               It doesn't give any gold or xp?
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #4 on: March 22, 2011, 05:25:28 pm »


               When I went to compile the script you posted, it would not compile because you did not have "nw_i0_plot" included. Could that mayhap be the problem?
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #5 on: March 22, 2011, 05:31:14 pm »


               Do you want only 1 reward item on the pc or 1 each time the ears, etc are taken?
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #6 on: March 22, 2011, 05:37:23 pm »


               Tweaked what you posted a lil bit, set it to give the reward item once per.


#include "nw_i0_plot"

void main()
{
 int nToTake    = 1;                             // Number of items to take.
 string sTag    = "misc001";                     // Tag of items to take.
 string sResRef = "Place_ResRef_of_Reward_Here"; // ResRef of item to give.
 object oPC = GetPCSpeaker();
 object oItem = GetFirstItemInInventory(oPC);
 int nAmount;


    // First, abort if oPC does not have enough items.
    if ( GetNumItems(oPC, sTag) < nToTake )
    {
    SpeakString("You do not have any proof.");
    return;
    }

    // Loop through oPC's inventory until enough items are taken
    // (i.e. while something still needs to be taken).
    // Checking for OBJECT_INVALID should not be needed, but it's a good safety measure.
    while ( oItem != OBJECT_INVALID )
    {// Only deal with items with the desired tag.
        if ( GetTag(oItem) == sTag )
        {// Determine what to do based on stack size.
            nAmount = GetItemStackSize(oItem);
            GiveGoldToCreature(oPC, 20*nAmount);
            GiveXPToCreature(oPC, 20*nAmount);
            DestroyObject(oItem, 0.1);
            SetLocalInt(oPC, "REWARD_EARS", 1);
        }
        // Update the loop.
        oItem = GetNextItemInInventory(oPC);
    }

    if(GetLocalInt(oPC, "REWARD_EARS") == 1)
    {
     CreateItemOnObject(sResRef, oPC);
     DeleteLocalInt(oPC, "REWARD_EARS");
    }

}

               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #7 on: March 22, 2011, 07:16:59 pm »


               Yes basically give the 20gp/20xp per ear .Could be a stack 10 etc but by clicking yes to sell you would only click once and the NPC buys all /takes all and gives reward per ear.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #8 on: March 22, 2011, 08:36:40 pm »


               K, to give the reward item per amount of ears collected I will need to change what I posted above let me tweak it.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #9 on: March 22, 2011, 08:40:17 pm »


               Here this should give one reward item per ear collected.


#include "nw_i0_plot"

void main()
{
 int nToTake    = 1;                             // Number of items to take.
 string sTag    = "misc001";                     // Tag of items to take.
 string sResRef = "Place_ResRef_of_Reward_Here"; // ResRef of item to give.
 object oPC = GetPCSpeaker();
 object oItem = GetFirstItemInInventory(oPC);
 int nAmount;


    // First, abort if oPC does not have enough items.
    if ( GetNumItems(oPC, sTag) < nToTake )
    {
    SpeakString("You do not have any proof.");
    return;
    }

    // Loop through oPC's inventory until enough items are taken
    // (i.e. while something still needs to be taken).
    // Checking for OBJECT_INVALID should not be needed, but it's a good safety measure.
    while ( oItem != OBJECT_INVALID )
    {// Only deal with items with the desired tag.
        if ( GetTag(oItem) == sTag )
        {// Determine what to do based on stack size.
            nAmount = GetItemStackSize(oItem);
            GiveGoldToCreature(oPC, 20*nAmount);
            GiveXPToCreature(oPC, 20*nAmount);
            DestroyObject(oItem, 0.1);
            while(nAmount > 0)
            {
                CreateItemOnObject(sResRef, oPC);
                nAmount = nAmount-1;
            }
        }
        // Update the loop.
        oItem = GetNextItemInInventory(oPC);
    }

}

               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #10 on: March 23, 2011, 01:59:37 am »


               Put your script in.It takes one stack at a time.Is there any way for it to grab all stacks? If not dont worry about it.       Thanks Baragg
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #11 on: March 23, 2011, 02:42:30 am »


               Try it like this and see if that works for ya:
EDIT: I did change it slightly. No offense to Baragg intended.


#include "nw_i0_plot"

void main()
{
    int nToTake = 1; // Number of items to take.
    string sTag = "misc001"; // Tag of items to take.
    int iReward = FALSE;//Set to TRUE to give reward items to players
    string sResRef = "Place_ResRef_of_Reward_Here"; // ResRef of item to give.
    object oPC = GetPCSpeaker();
    object oItem = GetFirstItemInInventory(oPC);
    int nAmount;

    // First, abort if oPC does not have enough items.
    if ( GetNumItems(oPC, sTag) < nToTake )
    {
        SpeakString("You do not have any proof.");
        return;
    }

    // Loop through oPC's inventory until enough items are taken
    // (i.e. while something still needs to be taken).
    // Checking for OBJECT_INVALID should not be needed, but it's a good safety measure.
    while ( oItem != OBJECT_INVALID )
    {// Only deal with items with the desired tag.
        if ( GetTag(oItem) == sTag )
        {// Determine what to do based on stack size.
            nAmount = nAmount + GetItemStackSize(oItem);
            DestroyObject(oItem, 0.1);
        }
        // Update the loop.
        oItem = GetNextItemInInventory(oPC);
    }

    GiveGoldToCreature(oPC, 20*nAmount);
    GiveXPToCreature(oPC, 20*nAmount);

    if (iReward == TRUE)
    {
        while(nAmount > 0)
        {
            CreateItemOnObject(sResRef, oPC);
            nAmount--;
        }
    }
}
               
               

               


                     Modifié par GhostOfGod, 23 mars 2011 - 02:53 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #12 on: March 23, 2011, 03:12:53 am »


               #include "nw_i0_plot"
void main()
{
    string sTag = "misc001"; // Tag of items to take.
    object oPC = GetPCSpeaker();
    int nToTake = GetNumItems(oPC,sTag); // Number of items to take.
    if ( nToTake)
    {
      TakeNumItems(oPC,sTag,nToTake);
      int nReward =nToTake * 20;
      GiveGoldToCreature(oPC,nReward);
      GiveXPToCreature(oPC,nReward);
    }
    else SpeakString("You do not have any proof.");
}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #13 on: March 23, 2011, 03:23:03 am »


               Or you can do that ^    ':whistle:'   '<img'>
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Take stacked items give gold/xp for each item one click?
« Reply #14 on: March 23, 2011, 04:02:53 am »


               haha thanks guys I give it ago tommorrow .