Author Sticky: Post Working Scripts Here
gsmithcat Posted: Tuesday, 25 June 07:03PM
Script Name: CreateObjectDel
What is does: This is more of a function than a script. It works just like CreateObject, but allows you to add in a delay before it spawns.
Notes: I recommend putting these functions in a header file for general use (i.e. some #include myfunctions)
NWScript:
//Here are the functions needed to create an object with a delay

//function: VoidObject

//author:   gsmithcat@yahoo.com

//behavior: Casts something of type object to type void, this is useful

//          for passing object returning actions to other functions.

void VoidObject(object oAction){}

//function: CreateObjectDel

//author: gsmithcat@yahoo.com

//behavior: Acts like CreateObject but with an fSeconds delay.

//          It does not return an object as I've found that trying

//          to instantly return something not yet created results

//          in invalid object IDs.

void CreateObjectDel(float fSeconds, int nObjectType, string sTemplate,

                       location lLocation, int bUseAppearAnimation=FALSE)

{

  //Ask the Module to create the object after fSeconds delay

  //This is done because sometimes OBJECT_SELF will no longer

  //exist after fSeconds

  AssignCommand(GetModule(),

                DelayCommand(fSeconds,

                VoidObject(CreateObject(nObjectType, sTemplate,

                lLocation, bUseAppearAnimation))));

}

//EXAMPLE USE

void main()

{

  location lLoc = GetLocation(OBJECT_SELF);

  //spawn a goblin in this location in 5 seconds

  CreateObjectDel(5.0, OBJECT_TYPE_CREATURE, "goblin", lLoc);

}