From 84279bbb034aef483276926255e88c531219aa31 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 30 Dec 2015 20:06:08 -0500 Subject: Fixed birds crashing if not spawned on a valid navmesh --- gamemode/npcsystem/aidirector.lua | 11 +++++----- gamemode/npcsystem/npcs/bird.lua | 45 ++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'gamemode/npcsystem') diff --git a/gamemode/npcsystem/aidirector.lua b/gamemode/npcsystem/aidirector.lua index d671b3c..b0a76a9 100644 --- a/gamemode/npcsystem/aidirector.lua +++ b/gamemode/npcsystem/aidirector.lua @@ -1,16 +1,18 @@ --Lol i dunno, spawn some npc's or something concommand.Add("ws_spawnzomb",function(ply, cmd, args) - SpawnNpcByName("Zombie",ply:GetPos()) - end -) + SpawnNpcByName("Zombie",ply:GetPos()) +end) + +concommand.Add("ws_spawnbird",function(ply,cmd,args) + SpawnNpcByName("Bird",ply:GetPos()) +end) function SpawnNpcByName(name, position) entdata = GetNpcByName(name) ent = ents.Create("ws_npc_ambient") ent:SetPos(position) - if(entdata.Speed) then ent.Speed = entdata.Speed end @@ -72,7 +74,6 @@ hook.Add("Tick","SpawnAmbient",function() if (C != CONTENTS_WATER and C != CONTENTS_WATER+CONTENTS_TRANSLUCENT) then --print("Appropriate place found, spawning bird)") - --SpawnNpcByName("Bird",Pos) break end end diff --git a/gamemode/npcsystem/npcs/bird.lua b/gamemode/npcsystem/npcs/bird.lua index fa98335..0393532 100644 --- a/gamemode/npcsystem/npcs/bird.lua +++ b/gamemode/npcsystem/npcs/bird.lua @@ -31,6 +31,11 @@ NPC.AwareEnemies = nil function NPC:Act() end +--What to replace ENT:OnStuck with +function NPC:Stuck() + +end + --What to replace ENT:RunBehaviour with function NPC:Behave() --print("Going into bird's custom behaviour") @@ -62,7 +67,21 @@ function NPC:Behave() direction:Normalize() local addition = direction * 1000 local topos = self:GetPos() + addition - self:MoveToPos(topos) + + --Check to make sure we can make it somewhere, so we don't crash + --[[ + if not self.loco:IsAreaTraversable(navmesh.GetNavArea(self:GetPos(),100)) then + print("No way to go forward!") + break + end + --]] + local navarea = navmesh.GetNavArea(self:GetPos(), 100) + if navarea:IsValid() then + self:MoveToPos(topos) + else + self:BecomeRagdoll(DamageInfo()) + end + -- --Check to see if we're being chased iscrouched = v:Crouching() @@ -70,29 +89,7 @@ function NPC:Behave() 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 - - - -- 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 - --print("Bird could not find anywhere to fly to") - -- some activity to signify that we didn't find shit + self:BecomeRagdoll(DamageInfo()) end end coroutine.yield() -- cgit v1.2.3-70-g09d2