patrol(function_name, npc_name)

Parameters:
function_name (string) name of the function
npc_name (string) name of the NPC
 
Returns:
(integer) handle of the patrol thread, or -1 if an error occurred

Description:
Execute a function as a patrol thread for an NPC.

When this script action is calle,d the function is executed immediately in a new thread, with the character's name passed as a parameter.

The patrol thread may be temporarily paused in certain situations, such as if the character attacks someone else. If the character is killed or otherwise removed from the game, the patrol thread is killed. Also, if for any reason, the patrol thread is killed, it will not be re-started.

Note that, although this script action is primarily intended for setting up patrol routes, it can also be used to execute any character-related function. The term "patrol" is used loosely here.

Patrols cannot be registered to the player character.

Example:

   function do_patrol(name)
      local route = {"nav00", "nav01", "nav02", "nav03"}
      local i = 1
      while (1) do
         move_to(name, route[i])
         i = i + 1
         if (i > 4) then
            i = 1
         end
      end
   end

   patrol("do_patrol", "Guard#000")

Associates the function, do_patrol(), with the character named, "Guard#000". The function is executed immediately in a new thread. The string, "Guard#000", is passed to do_patrol() as a parameter.

 

back to indexSR3 Script Action Documentation
Last updated: Tue, 09 Aug 2011 11:32:15