Author Topic: Respawning loot  (Read 348 times)

Legacy_Jackrabbit_Slim

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +0/-0
Respawning loot
« on: March 03, 2015, 06:27:05 pm »


               

#include "NW_O2_CONINCLUDE"
void main()
{
    float fDelay = 30.0;  //30 second delay

    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       return;
    }
    object oLastOpener = GetLastOpener();
    GenerateLowTreasure(oLastOpener, OBJECT_SELF);
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    DelayCommand(fDelay,SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
    ShoutDisturbed();
}






Sorry but I cant seem to get the code above to show below my message. :-( The script above works great for respawning the loot. The problem however is if the loot is not removed from the chest when opened again it just stacks on top of whats there. I know I have to use DestroyObject somehow but Im not sure how.


 


Thanks in advance!



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Respawning loot
« Reply #1 on: March 03, 2015, 07:53:11 pm »


               

Well, there's a few different ways you can do it, but I'd probably just go for the path of least reisistance and say 'if there is already something in the container, don't generate treasure'. To do that, I just added GetFirstItemInInventory() != OBJECT_INVALID to your script below.



#include "NW_O2_CONINCLUDE"
void main()
{
  float fDelay = 30.0; //30 second delay
 
  if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0 || GetFirstItemInInventory() != OBJECT_INVALID)
  {
    return;
  }

  object oLastOpener = GetLastOpener();
  GenerateLowTreasure(oLastOpener, OBJECT_SELF);
  SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
  DelayCommand(fDelay,SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
  ShoutDisturbed();
}

But if you really want to destroy everything in the container though and then generate treasure, put this code in right after the brackets that have the 'return;' in them:



object oInvItem = GetFirstItemInInventory();
while (oInvItem != OBJECT_INVALID) {
  DestroyObject(oInvItem);
  oInvItem = GetNextItemInInventory();
}


               
               

               
            

Legacy_Jackrabbit_Slim

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +0/-0
Respawning loot
« Reply #2 on: March 03, 2015, 09:02:17 pm »


               

Thank you so much for the fast response. Works great!



               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Respawning loot
« Reply #3 on: March 08, 2015, 03:16:22 pm »


               The problem is, someone could troll the server with leaving 1 GP or a worthless item in the chest, or not taking any of the cheap loot in the chest leaving the chest to only have worthless loot....

I'd say use the variable & clean the chest (e.g. remove inventory on open) every time....  (But that's just me)