How To Make Your Mobprog Wait

Example of how to add delays:

  • NOTE: Do not add delays to mprogs that are triggered by death because the mob will be dead/nil after the initial trigger. Even with the check for self == nil shown below, it seems to cause problems.
-- Line below is essential to avoid infinite loops
if progactive(self.gid, ch.gid) then return end

makewait(
   function()
      say("This is the first action!")

      -- Then wait 10 seconds... (attenuated by the player's output speed)
      mpause(10)

      -- After each mpause() call, make sure the player and actor are still alive and in the same room.
      if self == nil or ch == nil or self.room.key ~= ch.room.key then return end

      say("This is the second action, a bit later!")

      -- Wait again, and remember to check again that player/actor are still alive and present
      mpause(10)
      if self == nil or ch == nil or self.room.key ~= ch.room.key then return end

      say("This is the third and last action, nice job!")

      -- The 2 lines below look strange but are essential!
   end   -- this ends the function() scope
)        -- this ends the makewait() call