As far as taking only %5 of the gold once per reset, you could do something like so:
The chest's OnDisturbed script:
void main()
{
object oSelf = OBJECT_SELF;
object oPC = GetLastDisturbed();
int iMyGold = GetLocalInt(oSelf, "MY_GOLD");
int iPCGold = GetGold(oPC);
int iPCTook = GetLocalInt(oSelf, GetName(oPC));
float fKeep = IntToFloat(iMyGold) * 0.05;
int iKeep = FloatToInt(fKeep);
int iTake = iMyGold - iKeep;
object oItem = GetInventoryDisturbItem();
int iType = GetObjectType(oItem);
if (iType == 0)
{
if (iPCTook == TRUE)
{
TakeGoldFromCreature(iMyGold, oPC, FALSE);
SendMessageToPC(oPC, "You can not take anymore of this gold today.");
}
else
{
TakeGoldFromCreature(iTake, oPC, FALSE);
SetLocalInt(oSelf, GetName(oPC), TRUE);
SetLocalInt(oSelf, "MY_GOLD", GetGold(oSelf));
}
}
}
The chest's OnOpened script:
void main()
{
SetLocalInt(OBJECT_SELF, "MY_GOLD", GetGold(OBJECT_SELF));
}
The OnOpened records, ahead of time, the amount of gold it currently has by setting an int variable on the chest.
Then the OnDisturbed does some sloppy math(
'> )to figure out how much of the gold the chest will take back after the player has taken it. This also sets int variables on the chest that records the players who already took gold and in this case the chest will just take back the full amount of gold that was just taken.
Tested and seems to be working fine. Not sure if there are any possible exploits or not.
One thing to note: Gold returns an item type of 0. And i'm not sure if that is the same things as OBJECT_TYPE_INVALID which nwscript says is 32767. I tested this with various other items in the chest and so far gold seems to be the only thing that triggers the item type 0. Perhaps someone else will know more about it and enlighten us.
Anyway hope that helps. Good luck.
P.S. I'll mess around with increases and decreasing amount of gold functions too.
Modifié par GhostOfGod, 27 août 2010 - 09:12 .