From 37c4c8993f104ae7bd8c11b75ea7cf70e891b26a Mon Sep 17 00:00:00 2001 From: stickz Date: Mon, 4 Apr 2016 18:22:17 -0400 Subject: [PATCH] Cleanup 'ent_glowstick' Code - Setting the color and material on initialize is sufficient (don't need to think it) - Only think four times per second, 'if the client is in range to render the glowstick dynamic light' (improved performance) --- .../entities/ent_glowstick/shared.lua | 107 +++++++++--------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_glowstick/shared.lua b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_glowstick/shared.lua index 0e36f04..75b42b3 100644 --- a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_glowstick/shared.lua +++ b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_glowstick/shared.lua @@ -5,66 +5,69 @@ ENT.Type = "anim" if SERVER then -AddCSLuaFile("shared.lua") - -function ENT:Initialize() - self:SetMoveType( MOVETYPE_NONE ) - self:SetSolid( SOLID_NONE ) - self:SetCollisionGroup( COLLISION_GROUP_NONE ) - self:DrawShadow(false) - self:SetModel("models/glowstick/stick.mdl") + AddCSLuaFile("shared.lua") -end - function ENT:Think() + function ENT:Initialize() + self:SetMoveType( MOVETYPE_NONE ) + self:SetSolid( SOLID_NONE ) + self:SetCollisionGroup( COLLISION_GROUP_NONE ) + self:DrawShadow(false) + self:SetModel("models/glowstick/stick.mdl") + local player = self:GetOwner() self:SetColor(player:GetColor()) self:SetMaterial(player:GetMaterial()) -end - -end + end +end if CLIENT then - function ENT:Draw() --- some lines of code were modified, cause i dont need all bones, only right hand. - local p = self:GetOwner():GetRagdollEntity() or self:GetOwner() - local hand = p:LookupBone("ValveBiped.Bip01_R_Hand") - if hand then - local position, angles = p:GetBonePosition(hand) - - local x = angles:Up() * (-0.00 ) - local y = angles:Right() * 2.50 - local z = angles:Forward() * 4.15 - - local pitch = 0.00 - local yaw = 0.00 - local roll = 0.00 - - angles:RotateAroundAxis(angles:Forward(), pitch) - angles:RotateAroundAxis(angles:Right(), yaw) - angles:RotateAroundAxis(angles:Up(), roll) - - self:SetPos(position + x + y + z) - self:SetAngles(angles) - end + function ENT:Draw() + -- some lines of code were modified, cause i dont need all bones, only right hand. + local p = self:GetOwner():GetRagdollEntity() or self:GetOwner() + local hand = p:LookupBone("ValveBiped.Bip01_R_Hand") + if hand then + local position, angles = p:GetBonePosition(hand) + + local x = angles:Up() * (-0.00 ) + local y = angles:Right() * 2.50 + local z = angles:Forward() * 4.15 + + local pitch = 0.00 + local yaw = 0.00 + local roll = 0.00 + + angles:RotateAroundAxis(angles:Forward(), pitch) + angles:RotateAroundAxis(angles:Right(), yaw) + angles:RotateAroundAxis(angles:Up(), roll) + + self:SetPos(position + x + y + z) + self:SetAngles(angles) + end + local eyepos = EyePos() local eyepos2 = LocalPlayer():EyePos() if eyepos:Distance(eyepos2) > 5 or LocalPlayer() != self:GetOwner() then self:DrawModel() end - end - function ENT:Think() - if self:GetPos():Distance(LocalPlayer():GetPos()) > 5000 then return end - local dlight = DynamicLight( self:EntIndex() ) - if ( dlight ) then - local r, g, b, a = self:GetColor() - dlight.Pos = self:GetPos() - dlight.r = 0 - dlight.g = 255 - dlight.b = 0 - dlight.Brightness = 1 - dlight.Size = 750 - dlight.Decay = 750 - dlight.DieTime = CurTime() + 1 - end -end -end \ No newline at end of file + end + + function ENT:Think() + if self:GetPos():Distance(LocalPlayer():GetPos()) > 5000 then + self:SetNextClientThink(CurTime() + 0.25) + return true + end + + local dlight = DynamicLight( self:EntIndex() ) + if ( dlight ) then + local r, g, b, a = self:GetColor() + dlight.Pos = self:GetPos() + dlight.r = 0 + dlight.g = 255 + dlight.b = 0 + dlight.Brightness = 1 + dlight.Size = 750 + dlight.Decay = 750 + dlight.DieTime = CurTime() + 1 + end + end +end