From 071fc5ce8511dc04804c1ed74f776cc7c887ceed Mon Sep 17 00:00:00 2001 From: stickz Date: Mon, 4 Apr 2016 18:55:17 -0400 Subject: [PATCH] Cleanup 'ent_sglowstick_fly' Code - Remove think code and use a timer to destroy the entity. (significantly faster) - Comment off un-needed testing function --- .../entities/ent_sglowstick_fly/init.lua | 81 +++++++++---------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick_fly/init.lua b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick_fly/init.lua index f25043a..4df71e0 100644 --- a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick_fly/init.lua +++ b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick_fly/init.lua @@ -10,60 +10,53 @@ function ENT:Initialize() self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end - self.Death = CurTime() + 90 + + timer.Simple(90, function() if self.Entity then self.Entity:Remove() end end) end function ENT:SpawnFunction( ply, tr ) - if ( !tr.Hit ) then return end - local ent = ents.Create("ent_sglowstick_fly") - ent:SetPos( tr.HitPos + tr.HitNormal * 16 ) - ent:Spawn() - ent:Activate() - - return ent + if ( !tr.Hit ) then return end + + local ent = ents.Create("ent_sglowstick_fly") + ent:SetPos( tr.HitPos + tr.HitNormal * 16 ) + ent:Spawn() + ent:Activate() + + return ent end -function testProp(ply) - ent = ents.Create("prop_physics") - ent:SetPos(ply:GetPos() + Vector(5,0,0)) - ent:SetModel("models/hunter/blocks/cube1x2x1.mdl") - ent:Spawn() +/*function testProp(ply) + ent = ents.Create("prop_physics") + ent:SetPos(ply:GetPos() + Vector(5,0,0)) + ent:SetModel("models/hunter/blocks/cube1x2x1.mdl") + ent:Spawn() end -concommand.Add("testprop",testProp) +concommand.Add("testprop",testProp)*/ function ENT:PhysicsCollide( data, physobj ) - if IsValid(self:GetParent()) then return end - if data.HitEntity then - ent = data.HitEntity - if ent:IsWorld() then - self:SetMoveType(MOVETYPE_NONE) - self:SetPos(data.HitPos - data.HitNormal * 1.2) - flip = 1 - if data.HitNormal.y > 0 then - flip = -1 - end - self:SetAngles(Angle(0,data.HitNormal.y + data.HitNormal.x,-data.HitNormal.z * flip) * 90) - elseif !ent:IsPlayer() and !ent:IsWeapon() then - self:SetPos(data.HitPos - data.HitNormal * 1.2) - flip = 1 - if data.HitNormal.y > 0 then - flip = -1 - end - self:SetAngles(Angle(0,data.HitNormal.y + data.HitNormal.x,-data.HitNormal.z * flip) * 90) - self:SetParent(ent) - end - end -end - -function ENT:OnRemove() -end - -function ENT:Think() - if self.Death && self.Death < CurTime() then - self:Remove() + if IsValid(self:GetParent()) then return end + if data.HitEntity then + ent = data.HitEntity + if ent:IsWorld() then + self:SetMoveType(MOVETYPE_NONE) + self:SetPos(data.HitPos - data.HitNormal * 1.2) + + flip = 1 + if data.HitNormal.y > 0 then flip = -1 end + + self:SetAngles(Angle(0,data.HitNormal.y + data.HitNormal.x,-data.HitNormal.z * flip) * 90) + elseif !ent:IsPlayer() and !ent:IsWeapon() then + self:SetPos(data.HitPos - data.HitNormal * 1.2) + + flip = 1 + if data.HitNormal.y > 0 then flip = -1 end + + self:SetAngles(Angle(0,data.HitNormal.y + data.HitNormal.x,-data.HitNormal.z * flip) * 90) + self:SetParent(ent) + end end end function ENT:Use( activator, caller ) self.Entity:Remove() -end \ No newline at end of file +end