Controlling Gold In Chest, need help..
#1
Posté 27 août 2010 - 05:16
I want to only allow players to take 5% of the current gold in the chest...
(Of course there should be a variable / only reset & module restart / that prevent retaking more gold)
Also, does anyone have any fuctions to increment / decrement the amount of gold in the chest?
#2
Posté 27 août 2010 - 07:10
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(
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 .
#3
Posté 28 août 2010 - 02:47





Retour en haut






