Schedule/AddTask

From Garry's Mod
Jump to: navigation, search
 Schedule:AddTask( )

Contents

Description

Adds a task to the schedule. See also Schedule:AddTaskEx if you wish to customize task start and run function names.

See also ENTITY:StartSchedule, NPC:StartEngineTask, and NPC:RunEngineTask.

Arguments

string taskname

Custom task name

Arguments

any taskdata

Task data to be passed into the NPC's functions

Examples

Example

This creates a new schedule with a task named "HelloWorld" that is defined to print the taskdata passed in.

local schdHello = ai_schedule.New( "SayHello" )
schdHello:AddTask( "HelloWorld", "HELLO" )

-- Called when the task is initiated (started)
function ENT:TaskStart_HelloWorld( data )
    print(data)

    -- Set a variable that is 5 seconds in the future so the task can complete when we tick past it
    self.TaskEndTime = CurTime() + 5
end

-- Called every think until the task is completed
function ENT:Task_HelloWorld(data)
    print( data, "again" )

    -- Check if the 5 seconds have passed
    if CurTime() < self.TaskEndTime then
        self:TaskComplete()
    end
end

Output:

Prints "HELLO" in the console, then prints "HELLO again" on every NPC think until 5 seconds have passed.
Personal tools
Navigation