Loot script respawn delay

For toolset tutorials as well as question and answers.
Locked
User avatar
indio
Ancient Red Dragon
Posts: 2810
Joined: Sat Jan 03, 2004 10:40 am

Loot script respawn delay

Post by indio »

Code: Select all

//OnOpened event of placeable
void main()
{
   float fDelay = 60.0; // << Set respawn delay in seconds
   if(GetLocalInt(OBJECT_SELF, "LOOTED")) return;
   string sResRef;
   switch (Random(4) + 1)// << 1 to 12, also change the number 12 to match the number of cases below
   {
      case 1: sResRef = "nw_it_mpotion001x10"; break;//<< Resref of Item 1
      case 2: sResRef = "nw_it_mpotion020"; break;//<< Resref of Item 2

      case 3: sResRef = "cs_it_mpotioncom"; break;//<< Resref of Item 3
      case 4: sResRef = "cs_it_mpotionremcrs"; break;//<< Resref of Item 4


   }
   CreateItemOnObject(sResRef, OBJECT_SELF);
   SetLocalInt(OBJECT_SELF, "LOOTED", TRUE);
   DelayCommand(fDelay, DeleteLocalInt(OBJECT_SELF, "LOOTED"));
}
One of the potions spawns inside the chest's inventory the first time, which is great. But 60 seconds later, another potion should spawn. It doesn't. Any ideas?
Image
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Loot script respawn delay

Post by Teric neDhalir »

Hi Indio.
From the Lexicon...
Note that when initializing or setting a literal value to a float, you must include a decimal point and at least one number after the decimal, plus a lower case "f".
So
float fDelay = 60.0f;
Hope that helps,
Teric
User avatar
Creslyn
Orc Champion
Posts: 423
Joined: Sat Jan 10, 2004 2:30 am

Re: Loot script respawn delay

Post by Creslyn »

DelayCommand doesn't play well with various functions. Try

Code: Select all

DelayCommand(fDelay, SetLocalInt(OBJECT_SELF, "LOOTED", FALSE));
If that doesn't work, try using a wrapper function and delaying that.

If that doesn't work, perhaps its losing track of OBJECT_SELF after the delay. Try defining it as an object and passing that into the delayed command.

Been a while ;)
User avatar
indio
Ancient Red Dragon
Posts: 2810
Joined: Sat Jan 03, 2004 10:40 am

Re: Loot script respawn delay

Post by indio »

Thanks guys. Will let you know.
Image
User avatar
AcadiusLost
Chosen of Forumamus, God of Forums
Posts: 5061
Joined: Tue Oct 19, 2004 8:38 am
Location: Montara, CA [GMT -8]
Contact:

Re: Loot script respawn delay

Post by AcadiusLost »

Teric neDhalir wrote:float fDelay = 60.0f;
I wonder if that's the oddity with my rangefinding scripts, hmm...
User avatar
indio
Ancient Red Dragon
Posts: 2810
Joined: Sat Jan 03, 2004 10:40 am

Re: Loot script respawn delay

Post by indio »

Unfortunately neither approach succeeded.

Hmm.
Image
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Loot script respawn delay

Post by Teric neDhalir »

Well what do we think about
if(GetLocalInt(OBJECT_SELF, "LOOTED")) return;
as a valid line? Does it actually mean anything?

Would you be better off assigning a value to "LOOTED" and then turning it on and off? So when value is 0 the contents spawn and when it's 1 they don't. Then change that line above to
if ((GetLocalInt(OBJECT_SELF, "LOOTED")) == 1) return;
Oh, and I've just noticed while typing that there's no space between your "if" and (GetLocal etc etc). Would that make a difference?
Locked