184 lines
4.8 KiB
Plaintext
184 lines
4.8 KiB
Plaintext
// divide_loot_oc
|
|
////////////////////////////////////////////////
|
|
//Created by: Genisys (Guile)
|
|
//Created on: 5/18/08
|
|
//Udated On: 8/27/10 - Better Coding & Switches
|
|
////////////////////////////////////////////////
|
|
/*
|
|
This script goes in the OnClose Event of a Chest
|
|
NOTE: This script automatically ID's Items when sold
|
|
Please set the Important Settings Below..
|
|
*/
|
|
////////////////////////////////////////////////
|
|
//Set this to the % you want the PC to sell items for
|
|
const int PURCHASE_PERCENT = 40; //Default = 40%
|
|
|
|
//Set this to the MAXIMUM Amount of GP / Item Sold
|
|
const int MAXIMUM_PURCHASE_PRICE = 300000; //Capped at 300,000 By Default
|
|
|
|
//Set this to the MINIMUM Purchase Price (for any item)
|
|
const int MINIMUM_PURCHASE_PRICE = 100; //Default = 100 GP
|
|
|
|
//Set this to TRUE if you WANT to sell / destroy Plot Items
|
|
const int KILL_PLOT_ITEMS = FALSE; //Default = FALSE ~ Don't Sell / Destroy Plot Items
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
//////WARNING: DON'T TOUCH ANYTHING BELOW THIS LINE - TESTED GOOD!!////////////
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Required Includes
|
|
#include "X0_I0_PARTYWIDE"
|
|
#include "nw_i0_plot"
|
|
|
|
//MAJOR VARIABLES
|
|
object oTarget;
|
|
object oItem;
|
|
|
|
//DECLARE ALL PROTOTYPES
|
|
int GetMemberCount(object oPC);
|
|
int GetIdentifiedGoldPieceValue(object oItem);
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
//MAIN SCRIPT
|
|
void main()
|
|
{
|
|
|
|
//declare major variables
|
|
object oPC = GetLastClosedBy();
|
|
oTarget = OBJECT_SELF;
|
|
object oItem;
|
|
int a, b, c;
|
|
int nMembers = GetMemberCount(oPC);
|
|
int nInt = GetLocalInt(oPC, "SECURED");
|
|
int nGP;
|
|
|
|
if(nInt!=1)
|
|
{ return; }
|
|
|
|
//if not a pc stop
|
|
if (!GetIsPC(oPC))
|
|
{ return; }
|
|
|
|
//Stop the security on the object!
|
|
SetLocalInt(OBJECT_SELF, "SECURED", 0);
|
|
SetLocalInt(oPC, "SECURED", 0);
|
|
|
|
|
|
//Loop through the items in the inventory of the chest..
|
|
oItem = GetFirstItemInInventory(oTarget);
|
|
while(oItem != OBJECT_INVALID)
|
|
{
|
|
//Lets loop through to get the total cost of all items in the container
|
|
if(KILL_PLOT_ITEMS==TRUE)
|
|
{
|
|
SetPlotFlag(oItem, FALSE); //Get the items true value (without being plot)
|
|
}
|
|
// Get the Identified GP value
|
|
nGP = GetIdentifiedGoldPieceValue(oItem);
|
|
if(nMembers>1)
|
|
{ b = nGP/nMembers; } //divide the gold!
|
|
else if(nMembers ==1)
|
|
{ b = nGP/2; } //give them only 15% for being stingy!
|
|
else
|
|
{ b = nGP; } //for debugging purposes
|
|
|
|
c = b;
|
|
//If it's not a Plot Item
|
|
if(GetPlotFlag(oItem)==FALSE)
|
|
{
|
|
//GiveGoldToAll(oPC, nValue);
|
|
GiveGoldToAll(oPC, c);
|
|
}
|
|
else //It's a plot item..
|
|
{
|
|
//Should we sell it or not?
|
|
if(KILL_PLOT_ITEMS==TRUE)
|
|
{
|
|
//GiveGoldToAll(oPC, nValue);
|
|
GiveGoldToAll(oPC, c);
|
|
}
|
|
}
|
|
|
|
oItem = GetNextItemInInventory(oTarget);
|
|
}
|
|
|
|
//Lets destroy all the stuff now.
|
|
|
|
oItem = GetFirstItemInInventory(oTarget);
|
|
while(oItem != OBJECT_INVALID)
|
|
{
|
|
if(GetIsObjectValid(oItem))
|
|
{
|
|
if(GetPlotFlag(oItem)!=TRUE)
|
|
{
|
|
DestroyObject(oItem, 0.0f);
|
|
}
|
|
else //It's a Plot Item..
|
|
{
|
|
if(KILL_PLOT_ITEMS==TRUE)
|
|
{
|
|
DestroyObject(oItem, 0.0f);
|
|
}
|
|
}
|
|
}
|
|
//Loop to make sure we got all items.
|
|
oItem = GetNextItemInInventory(oTarget);
|
|
|
|
}
|
|
|
|
//Let's prevent reopening for 2 seconds, to ensure all contents are gone!
|
|
DelayCommand(0.1, SetLocked(OBJECT_SELF, TRUE));
|
|
DelayCommand(2.0, SetLocked(OBJECT_SELF, FALSE));
|
|
|
|
//Main Script End
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//DEFINE ALL PROTOTYPES
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Tell us how many party members there are
|
|
int GetMemberCount(object oPC)
|
|
{
|
|
int i = 0;
|
|
object oMember = GetFirstFactionMember(oPC);
|
|
while(GetIsObjectValid(oMember))
|
|
{
|
|
i+=1;
|
|
|
|
oMember = GetNextFactionMember(oPC);
|
|
}
|
|
|
|
return i;
|
|
|
|
//Prototype End
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Return the Identified Value of the Item
|
|
//(Plot Status may possibly removed in main script - depending upon a switch)
|
|
int GetIdentifiedGoldPieceValue(object oItem)
|
|
{
|
|
// Initial flag
|
|
int bIdentified = GetIdentified(oItem);
|
|
|
|
// If not already, set to identfied
|
|
if (!bIdentified) SetIdentified(oItem, TRUE);
|
|
|
|
// Get the GP value
|
|
int nGP=GetGoldPieceValue(oItem);
|
|
int m, n;
|
|
|
|
//Cap the gold..
|
|
if(nGP >=MAXIMUM_PURCHASE_PRICE) { nGP = MAXIMUM_PURCHASE_PRICE; return nGP; }
|
|
else if(nGP <MAXIMUM_PURCHASE_PRICE && nGP>=100)
|
|
{m = nGP/100;
|
|
n = m * PURCHASE_PERCENT; //Determine how much to buy it for..
|
|
nGP = n; return nGP; }
|
|
else if(nGP<100) { nGP = MINIMUM_PURCHASE_PRICE; return nGP; }
|
|
else { return nGP; }
|
|
}
|
|
|
|
|