Ai schedule.AddTask

From GMod Wiki

Jump to: navigation, search
Function
Syntax ai_schedule:AddTask( String _functionname_, Function _data_ )
Where is this used?
Description:
Adds Lua NPC task to the schedule.
Returns: nil
Part of Library: ai_schedule
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Ai schedule.AddTask]Ai schedule.AddTask [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionAdding a custom AI Task
Used onNewerServer.png
Code
local schdHello = ai_schedule.New( "SayHello" )
schdHello:AddTask("TASK_HELLO","HELLO") // (TaskName, AttachedData)
 
function ENT:Task_TASK_HELLO(data) //Called every think until the task is completed
     print(data.." Again")
end
 
function ENT:TaskStart_TASK_HELLO(data) //Called when the task is initiated (started)
     print(data)
end
 
 
OutputPrints "HELLO" in console when the task is started, and prints "HELLO Again" every think until the task is complete


DescriptionMakes the npc find the closest player
Used onNewerServer.png
Code
function ENT:SelectSchedule()
 
	local schdChase = ai_schedule.New( "AIFighter Chase" )
 
	schdChase:AddTask( "FindEnemy", 		{ Class = "player", Radius = 10000 } )
 
end
OutputMakes the NPC Find the closest class(player) in a radius of Radius(10000)!
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox