Hey there, sweetie,
I seem to be doing something wrong. Maybe you can help? Here's what I did.
I made stackable apples and set it at 1.
Then in the script, where it says return tag of item, I put in "Apple"
Where it says return number of items, I put "10" because I want the player to collect 10 apples.
Where it says return xp reward, I put "50".
And where it says return gold reward, I put "20"
Just so you know, I replaced the entire return statement with the word apple or the numbers mentioned, with quotations of around it of course.
Then down where it says int nCheck = 0, nStack; I changed the 0 to 1, since we only need one stack of 10 apples.
Then down where it says // requirement is fulfilled
nRequiredAmount = 0; I changed the 0 to 10 since I just want 10 apples.
Naturally the npc isnt responding like I want.
Please help...hehe. I'm hopeless.
Dagesh wrote...
void main()
{
// our PC speaker
object oPC = GetPCSpeaker();
// Set the tag needed on the NPC
string sTag = GetLocalString( OBJECT_SELF, "RETURN_TAG_OF_ITEM" );
// Set how much we need on the NPC in the convo
int nRequiredAmount = GetLocalInt( OBJECT_SELF, "RETURN_NUMBER_OF_ITEMS" );
// Get the XP reward stored on the NPC
int nXP = GetLocalInt( OBJECT_SELF, "RETURN_XP_REWARD" );
// Get the gold reward stored on the NPC
int nGold = GetLocalInt( OBJECT_SELF, "RETURN_GOLD_REWARD" );
// This while loop will loop around and around until either
// we have checked every single item in the PC's inventory
// or until we have found that the amount of items needed
// is found. I added a check for stack size. This lets you
// use items that stack
int nCheck = 0, nStack;
object oItem = GetFirstItemInInventory( oPC );
while( GetIsObjectValid( oItem ) )
{
if( GetTag( oItem ) == sTag )
{// if current item has the tag we're looking for
nStack = GetItemStackSize( oItem );
nCheck += nStack;// same as: nCheck = nCheck + 1;
if( nCheck >= nRequiredAmount )
{// we have found the number we need
// this will break us out of the loop
break;
}
}
oItem = GetNextItemInInventory( oPC );
}
if( nCheck >= nRequiredAmount )
{// PC has the required number of items
// Here we will loop around to remove the items with sTag.
// we simply loop through the PC's inventory until
// we have destroyed the amount to take
// Once we've done that we leave (break) the loop
// this also checks for stacked items
// and removes them as needed
oItem = GetFirstItemInInventory( oPC );
while( GetIsObjectValid( oItem ) )
{
if( GetTag( oItem ) == sTag )
{// if current item has the tag we're looking for
nStack = GetItemStackSize( oItem );
if( nStack > nRequiredAmount )
{// stack has more than we need
// lower stack size minus what NPC takes
SetItemStackSize( oItem, nStack - nRequiredAmount );
// requirement is fulfilled
nRequiredAmount = 0;
}
else
{// stack is not high enough
// destroy entire stack
DestroyObject (oItem);
// remove the stack amount from required amount
// so we know how much we still need
nRequiredAmount = nRequiredAmount - nStack;
}
if( nRequiredAmount <= 0 )
{// we have found the total number we need
// this will break us out of the loop
GiveGoldToCreature( oPC, nGold );
GiveXPToCreature( oPC, nXP ); break;
}
}
oItem = GetNextItemInInventory( oPC );
}
}
else
{// PC does not have enough of the required items
// You could add a line for the NPC to respond here if you wanted
}
}
This should work for you. It's compiled and tested just in case. Make sure to not add it to the last node of the conversation or things won't work (GetPCSpeaker will be an invalid object because the convo is over so the script won't know who to take the items from).
edit: Tried to make the code look decent instead of the stupid mishmash this forum style gives it. Bah.
edit again: added XP and gold reward