From 383aebf4bd5cfaf31702b3b5bbf94d331d6256fd Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 29 Dec 2015 22:34:58 -0500 Subject: Added dodos --- gamemode/npcsystem/npcs/bird.lua | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'gamemode/npcsystem/npcs/bird.lua') diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua index 007c16a..d09f1ef 100644 --- a/gamemode/npcsystem/npcs/bird.lua +++ b/gamemode/npcsystem/npcs/bird.lua @@ -36,30 +36,43 @@ function NPC:Behave() print("Going into bird's custom behaviour") while ( true ) do self:StartActivity( ACT_IDLE ) -- 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) - - - -- revert to idle activity - - self:PlaySequenceAndWait( "Idle01" ) -- Sit on the floor --Check if there are any players nearby local players = ents.FindByClass("Player") + local playernearby = false for k,v in pairs(players) do local fardist = 800 local closedist = 300 + local removedist = 2000 local iscrouched = v:Crouching() local dist = v:GetPos():Distance(self:GetPos()) - if((dist < fardist and not iscrouched) or (dist < closedist)) then + --Remove ourselves if there's noone nearby + if(dist > 2000) then + playernearby = true + end + --Keep flying away as long as we're being chased + while((dist < fardist and not iscrouched) or (dist < closedist)) do self:StartActivity(ACT_FLY) - print("I should fly away") self:SetSequence( "Fly01" ) - local topos = self:GetPos() + Vector( math.Rand( -1, 1 ), math.Rand( -1, 1 ), 0 ) * 1000 + + --Find a position in roughly the oposite direction of the player + local tpos = self:GetPos() + local ppos = v:GetPos() + local direction = Vector(tpos.x - ppos.x, tpos.y - ppos.y, tpos.z - ppos.z) + direction:Normalize() + local addition = direction * 1000 + local topos = self:GetPos() + addition self:MoveToPos(topos) - print("Flying to (" .. topos.x .. "," .. topos.y .. "," .. topos.z .. ")") + + --Check to see if we're being chased + iscrouched = v:Crouching() + dist = v:GetPos():Distance(self:GetPos()) end end + if not playernearby then + local di = DamageInfo() + self:BecomeRagdoll(di) + end --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 -- Get up -- cgit v1.2.3-70-g09d2