From 0dbb82037c02c10b12532f92f170904613c06c10 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 9 Jun 2016 00:17:33 -0400 Subject: Give zombies the ability to climb over obsticals --- entities/entities/npc_nb_base/shared.lua | 71 +++++++++++++++++--------------- gamemode/init.lua | 7 ++++ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/entities/entities/npc_nb_base/shared.lua b/entities/entities/npc_nb_base/shared.lua index c2557bb..5be63a5 100644 --- a/entities/entities/npc_nb_base/shared.lua +++ b/entities/entities/npc_nb_base/shared.lua @@ -68,12 +68,13 @@ function ENT:Initialize() self.DmgTable = {} self.LastPos = self.Entity:GetPos() - self.Stuck = CurTime() + 10 + self.Stuck = CurTime() + 1 end function ENT:Think() - + v1 = self:GetNWVector("tracestart") + v2 = self:GetNWVector("traceend") self.Entity:OnThink() if ( self.IdleTalk or 0 ) < CurTime() then @@ -82,14 +83,14 @@ function ENT:Think() self.IdleTalk = CurTime() + math.Rand(10,20) end - if ( self.Stuck or 0 ) < CurTime() then + if self.LastPos:Distance( self.Entity:GetPos() ) < 50 then + self.Entity:StuckThink() + end - self.Entity:StuckThink() - self.Stuck = CurTime() + 10 + self.Stuck = CurTime() + 1 self.LastPos = self.Entity:GetPos() - end if self.Entity:OnFire() and self.FireDamageTime < CurTime() then @@ -173,12 +174,7 @@ function ENT:OnThink() end function ENT:StuckThink() - self.LastPos = self.LastPos or Vector(0,0,0) - if self.LastPos:Distance( self.Entity:GetPos() ) < 50 then - - self.Entity:StartRespawn() - end end @@ -643,6 +639,9 @@ function ENT:OnHitBreakable( ent ) if not IsValid( ent ) then return end + local min,max = ent:WorldSpaceAABB() + local height = max.z - min.z + if string.find( ent:GetClass(), "func_breakable" ) then ent:TakeDamage( 25, self.Entity, self.Entity ) @@ -657,6 +656,14 @@ function ENT:OnHitBreakable( ent ) ent:Remove() + elseif string.find( ent:GetClass(), "prop_physics" ) and height > 10 and ent:GetCollisionGroup() != COLLISION_GROUP_DEBRIS then + + ent:GetPhysicsObject():AddVelocity((self:GetForward()*200)+Vector(0,0,100)) + + if(height < 30) then + table.RemoveByValue(GAMEMODE.Breakables, ent) + end + else if not ent.Hits then @@ -713,10 +720,6 @@ function ENT:OnHitBreakable( ent ) end -function ENT:BehaveAct() // what does this do? - -end - function ENT:IsZombie() return true @@ -853,28 +856,11 @@ end function ENT:OnStuck() - local ent = self.Entity:GetBreakable() - - if IsValid( ent ) then - self.Obstructed = true - else - - self.Obstructed = false - - //self.loco:SetDesiredSpeed( self.BumpSpeed ) - //self.loco:Jump() - //self.loco:SetDesiredSpeed( self.BumpSpeed ) - - end - - self.loco:ClearStuck() - end function ENT:OnUnStuck() - self.Obstructed = false end @@ -929,10 +915,27 @@ function ENT:RunBehaviour() self.Entity:StartActivity( ACT_IDLE ) else - if self.Obstructed then - self.Entity:BreakableRoutine() + local tp = self:GetPos() + local fp = self:GetForward()*20 + local trdata = { + start = tp+fp+Vector(0,0,50), + endpos = fp+tp + } + local tr = util.TraceLine(trdata) + --If we can climb over this obstical, do that + if(tr.Fraction < 0.9) then + self:SetPos(tp+Vector(0,0,50)+(fp/19)) + self:PlaySequenceAndWait("pickup") + self:SetPos(tp+fp+Vector(0,0,50)) + else + self.Entity:BreakableRoutine() + end + self:SetNWVector("startrace",tr.start) + self:SetNWVector("endtrace",tr.endpos) + + self.loco:ClearStuck() coroutine.yield() diff --git a/gamemode/init.lua b/gamemode/init.lua index 400e4a1..024358b 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -214,6 +214,13 @@ function GM:InitPostEntity() local tbl = ents.FindByClass( "prop_door_rotating" ) tbl = table.Add( tbl, ents.FindByClass( "func_breakable*" ) ) tbl = table.Add( tbl, ents.FindByClass( "func_door*" ) ) + for k,v in pairs(ents.FindByClass("prop_physics")) do + local min,max = v:WorldSpaceAABB() + local height = max.z - min.z + if height > 10 then + table.insert(tbl,v) + end + end GAMEMODE.Breakables = tbl GAMEMODE.NPCSpawns = ents.FindByClass( "info_npcspawn" ) -- cgit v1.2.3-70-g09d2