Aller au contenu

Photo

Take stacked items give gold/xp for each item one click?


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

#1
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
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);}

#2
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
double post oops

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


#3
Baragg

Baragg
  • Members
  • 271 messages
K, let me open the toolset.

#4
Baragg

Baragg
  • Members
  • 271 messages
It doesn't give any gold or xp?

#5
Baragg

Baragg
  • Members
  • 271 messages
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?

#6
Baragg

Baragg
  • Members
  • 271 messages
Do you want only 1 reward item on the pc or 1 each time the ears, etc are taken?

#7
Baragg

Baragg
  • Members
  • 271 messages
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");
    }

}


#8
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
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.

#9
Baragg

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

#10
Baragg

Baragg
  • Members
  • 271 messages
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);
    }

}


#11
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
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

#12
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
#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.");
}

#14
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
Or you can do that ^    :whistle:   :P

#15
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
haha thanks guys I give it ago tommorrow .

#16
Baragg

Baragg
  • Members
  • 271 messages

GhostOfGod wrote...

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


None taken.....I am surprised that only took one stack tho.

#17
Baragg

Baragg
  • Members
  • 271 messages
Leave it up to Lightfoot, clean looking code Lightfoot.

#18
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
Ok guys ..you let me loose with a perfectly good script .Lightfoot8 script was so short I thought I was suppose to replace the top of the other one with it.LOL Works great Lightfoot8. Thanks guys for your help.

#19
PreyingMantis

PreyingMantis
  • Members
  • 11 messages
Great script Lightfoot! Thanks.