From 6e8f8314db119eeac8d5f349255ab0ee20238e52 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 1 Jan 2016 20:29:20 -0500 Subject: Objects change color as they get dammaged --- entities/entities/ws_prop/init.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'entities') diff --git a/entities/entities/ws_prop/init.lua b/entities/entities/ws_prop/init.lua index 519f1e7..51e979f 100644 --- a/entities/entities/ws_prop/init.lua +++ b/entities/entities/ws_prop/init.lua @@ -8,21 +8,23 @@ function ENT:Initialize() self:SetMoveType(MOVETYPE_NONE) self:SetSolid(SOLID_VPHYSICS) self:DrawShadow(false) - + local phys = self:GetPhysicsObject() phys:EnableMotion(false) phys:Sleep() - + self:SetHealth(30) - + self.HP = 500 + self.MaxHP = self.HP end function ENT:OnTakeDamage(dmginfo) self.HP = self.HP-dmginfo:GetDamage() - - if (self.HP <= 0) then + local newcolor = (self.HP/self.MaxHP)*255 + self:SetColor(Color(newcolor,newcolor,newcolor)) + if (self.HP <= 0) then self:EmitSound(Sound("physics/wood/wood_plank_break"..math.random(1,4)..".wav")) - self:Remove() + self:Remove() end end -- cgit v1.2.3-70-g09d2