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);}
Take stacked items give gold/xp for each item one click?
Débuté par
Knight_Shield
, mars 22 2011 02:58
#1
Posté 22 mars 2011 - 02:58
#2
Posté 22 mars 2011 - 03:01
double post oops
Modifié par Knight_Shield, 22 mars 2011 - 03:02 .
#3
Posté 22 mars 2011 - 05:17
K, let me open the toolset.
#4
Posté 22 mars 2011 - 05:22
It doesn't give any gold or xp?
#5
Posté 22 mars 2011 - 05:25
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
Posté 22 mars 2011 - 05:31
Do you want only 1 reward item on the pc or 1 each time the ears, etc are taken?
#7
Posté 22 mars 2011 - 05:37
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
Posté 22 mars 2011 - 07:16
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
Posté 22 mars 2011 - 08:36
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
Posté 22 mars 2011 - 08:40
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
Posté 23 mars 2011 - 01:59
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
Posté 23 mars 2011 - 02:42
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--;
}
}
}
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
Posté 23 mars 2011 - 03:12
#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.");
}
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
Posté 23 mars 2011 - 03:23
Or you can do that ^
#15
Posté 23 mars 2011 - 04:02
haha thanks guys I give it ago tommorrow .
#16
Posté 23 mars 2011 - 11:46
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
Posté 23 mars 2011 - 11:47
Leave it up to Lightfoot, clean looking code Lightfoot.
#18
Posté 23 mars 2011 - 11:10
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
Posté 23 mars 2011 - 11:19
Great script Lightfoot! Thanks.





Retour en haut







