Author Topic: Controlling Gold In Chest, need help..  (Read 371 times)

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Controlling Gold In Chest, need help..
« on: August 27, 2010, 06:16:05 am »


               I want to control the gold placed in a chest, this way not everyone can take all of it at once..

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?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Controlling Gold In Chest, need help..
« Reply #1 on: August 27, 2010, 08:10:29 pm »


               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( '<img'> )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 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Controlling Gold In Chest, need help..
« Reply #2 on: August 28, 2010, 03:47:49 am »


               Yes it does, much thanks for the help, and nice coding too...  '<img'>