Garry's Mod Wiki

NEXTBOT:RunBehaviour

  NEXTBOT:RunBehaviour()

Description

A hook called to process nextbot logic.

This hook runs in a coroutine by default. It will only be called if NEXTBOT:BehaveStart is not overriden.

Example

Example usage of the hook to make NextBot logic from the Example NextBot NPC shipped with the game.

function ENT:RunBehaviour() while ( true ) do -- walk somewhere random self:StartActivity( ACT_WALK ) -- walk anims self.loco:SetDesiredSpeed( 100 ) -- walk speeds self:MoveToPos( self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 200 ) -- walk to a random place within about 200 units (yielding) self:StartActivity( ACT_IDLE ) -- revert to idle activity self:PlaySequenceAndWait( "idle_to_sit_ground" ) -- Sit on the floor self:SetSequence( "sit_ground" ) -- Stay sitting coroutine.wait( self:PlayScene( "scenes/eli_lab/mo_gowithalyx01.vcd" ) ) -- play a scene and wait for it to finish before progressing self:PlaySequenceAndWait( "sit_ground_to_idle" ) -- Get up -- find the furthest away hiding spot local pos = self:FindSpot( "random", { type = 'hiding', radius = 5000 } ) -- if the position is valid if ( pos ) then self:StartActivity( ACT_RUN ) -- run anim self.loco:SetDesiredSpeed( 200 ) -- run speed self:PlayScene( "scenes/npc/female01/watchout.vcd" ) -- shout something while we run just for a laugh self:MoveToPos( pos ) -- move to position (yielding) self:PlaySequenceAndWait( "fear_reaction" ) -- play a fear animation self:StartActivity( ACT_IDLE ) -- when we finished, go into the idle anim else -- some activity to signify that we didn't find anything end coroutine.yield() end end