From fe2df959221cbcc45fc5f30fc76edcce42b36735 Mon Sep 17 00:00:00 2001 From: stickz Date: Mon, 4 Apr 2016 18:47:33 -0400 Subject: [PATCH] Cleanup 'ent_sglowstick' 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_sglowstick/shared.lua | 121 +++++++++--------- 1 file changed, 62 insertions(+), 59 deletions(-) diff --git a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick/shared.lua b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick/shared.lua index 8d7bc3f..26ae82c 100644 --- a/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick/shared.lua +++ b/MorbusGamemode/gamemodes/morbusgame/entities/entities/ent_sglowstick/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_rng.mdl") - -end - function ENT:Think() - local player = self:GetOwner() - self:SetColor(player:GetColor()) - self:SetMaterial(player:GetMaterial()) -end + 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_rng.mdl") + + local player = self:GetOwner() + self:SetColor(player:GetColor()) + self:SetMaterial(player:GetMaterial()) + 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 - 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 = 255 - dlight.g = 127 - 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 + 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 + 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 = 255 + dlight.g = 127 + dlight.b = 0 + dlight.Brightness = 1 + dlight.Size = 750 + dlight.Decay = 750 + dlight.DieTime = CurTime() + 1 + end + end +end