Destroy object in pc inventory with highest value
From NWNWiki
[edit] What it does
This script searches the whole inventory of a PC for the item with the highest value.
- The script is made for use in a conversation (object oPC=GetPCSpeaker()). This can be changed for other purpose.
- You need to create an object, where locals can be stored (tried without an object, but it does not seem to work this way). Replace <TagOfObject> with Tag of ur object (mine was an invisible object)
[edit] The Script
//Another crappy script from Incanus
//Use it while PC is in conversation. Otherwise u will have to change the object oPC
//
//Enjoy or destroy! :)
//Based upon script from Bioware by Tolan Fellowes
/*
Check all items in PC inventory and search for the highest value. Destroy thingy with highest value
oPC: The PC Speaker who is in conversation
*/
void main()
{
object oPC; //PC
//used for multiple items which are stackable
int nStackSize;
int nCount; //used in for loops
object oPCItem; //PC inventory items
//Object used to get/set item properties
object oMostValue;
string sMostValue;
string sMostValue1;
int nGoldValue;
oPC = GetPCSpeaker();
oMostValue = GetObjectByTag("<TagOfObject>");
//Get the first item in PC inventory
oPCItem = GetFirstItemInInventory(oPC);
//Set starting value = 0 and store it
nGoldValue = 0;
SetLocalInt(oMostValue,sMostValue,nGoldValue);
//loop thru until PC inventory is empty
while(oPCItem != OBJECT_INVALID)
{
//Get the number of stacked items
nStackSize = GetNumStackedItems(oPCItem);
//Search items in PC's inventory (stacked) and compare
for(nCount = 0; nCount < nStackSize; nCount++)
{
//Get Value of item
nGoldValue = GetGoldPieceValue(oPCItem);
if (nGoldValue>(GetLocalInt(oMostValue,sMostValue)))
{
SetLocalInt(oMostValue,sMostValue,nGoldValue);
SetLocalString(oMostValue,sMostValue1,GetTag(oPCItem));
SendMessageToPC(oPC,"Item: "+GetLocalString(oMostValue,sMostValue1)+" ;Value: "+IntToString(GetLocalInt(oMostValue,sMostValue))); //just 4 checking the script
}
}
//Get the next item
oPCItem = GetNextItemInInventory(oPC);
}
//loop thru PC slot items and compare
for(nCount = 0; nCount < NUM_INVENTORY_SLOTS; nCount++)
{
oPCItem = GetItemInSlot(nCount, oPC);
if(oPCItem != OBJECT_INVALID)
{
nGoldValue = GetGoldPieceValue(oPCItem);
if (nGoldValue>(GetLocalInt(oMostValue,sMostValue)))
{
SetLocalInt(oMostValue,sMostValue,nGoldValue);
SetLocalString(oMostValue,sMostValue1,GetTag(oPCItem));
SendMessageToPC(oPC,"Item: "+GetLocalString(oMostValue,sMostValue1)+" ;Value: "+IntToString(GetLocalInt(oMostValue,sMostValue))); //just 4 checking the script
}
}
}
//remove item from PC inventory
string sDestroy = GetLocalString(oMostValue,sMostValue1);
DestroyObject(GetObjectByTag(sDestroy));
//PCMessage to confirm destruction of highest value thingy
SendMessageToPC(oPC,"Destroyed: "+GetLocalString(oMostValue,sMostValue1)+" ;Value: "+IntToString(GetLocalInt(oMostValue,sMostValue)));
//Set all locals to 0
SetLocalInt(oMostValue,sMostValue,0);
SetLocalString(oMostValue,sMostValue1,"");
}
[edit] Notes
It's not the finest script, but it works (I tried several times and every time the script runs, item with highest value gets destroyed).
