- Documentation
- Server functions
- setPedTask
Function
setPedTask
Stores a "task" for a ped in a chosen layer, e.g. primary = "enterVehicle", together with any data. It is a mechanism for scripts (e.g. your own NPC AI): the game does not carry out stored tasks by itself, but other scripts can read them with getPedTask, getPedTasks, isPedDoingTask and getPedSimplestTask. Passing nil as the name clears the task from the layer.
Syntax
bool setPedTask(ped ped, string priority [, string name = nil, any data = nil])Arguments
pedped- A player or an NPC.
prioritystring- Layer name, e.g.
"primary","secondary"(any string). namestring, optional = nil- Task name, e.g.
"patrol".nil= clear this layer. dataany, optional = nil- Any task data (number, string, table, element).
Returns
true on success.
Example
setPedTask(guard, "primary", "patrol", { 2490, -1670, 13.3 })
See also
getPedTaskReturns the task stored in a layer bysetPedTask: its name, data and the moment (ingetTickCountunits) it was set. Returnsfalsewhen the layer is empty.getPedTasksReturns a table of all of a ped's task layers as "layer → task name". Useful to see what scripts told an NPC to do.isPedDoingTaskChecks whether any of a ped's task layers holds a task with the given name (stored bysetPedTaskor by functions such assetPedEnterVehicle, which storeenterVehicle).