Page 1 of 1

Loot script respawn delay

Posted: Fri Nov 07, 2008 6:31 am
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?

Re: Loot script respawn delay

Posted: Fri Nov 07, 2008 12:46 pm
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

Re: Loot script respawn delay

Posted: Fri Nov 07, 2008 6:30 pm
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 ;)

Re: Loot script respawn delay

Posted: Fri Nov 07, 2008 8:05 pm
by indio
Thanks guys. Will let you know.

Re: Loot script respawn delay

Posted: Fri Nov 07, 2008 10:03 pm
by AcadiusLost
Teric neDhalir wrote:float fDelay = 60.0f;
I wonder if that's the oddity with my rangefinding scripts, hmm...

Re: Loot script respawn delay

Posted: Fri Nov 07, 2008 10:56 pm
by indio
Unfortunately neither approach succeeded.

Hmm.

Re: Loot script respawn delay

Posted: Sun Nov 09, 2008 11:05 am
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?