/*------------------------------------------------------------------------------ Thanks for writing this, ogniK (modified from a proxy by Kilburn) -CBB */------------------------------------------------------------------------------ matproxy.Add( { name = "CarbonHealth", init = function( self, mat, values ) -- Store the name of the variable we want to set self.ResultTo = values.resultvar end, bind = function( self, mat, ent ) if not IsValid( ent ) then return end function SinBetween( min, max, time ) local diff = max - min local remain = max - diff return ( ( ( math.sin( time ) + 1 ) / 2 ) * diff ) + remain end local col = Vector(255, 255, 255) -- If entity is a ragdoll try to convert it into the player -- ( this applies to their corpses ) if ( ent:IsRagdoll() ) then local owner = ent:GetRagdollOwner() ent = IsValid(owner) and owner or ent col = Vector(255, 255, 255) end -- If the target ent has a function called GetPlayerColor then use that -- The function SHOULD return a Vector with the chosen player's colour. if (ent:IsPlayer() and ent.GetPlayerColor) or ent:IsNPC() then local plhp = 100 if ent:IsPlayer() then col = ent:GetPlayerColor() plhp = ent:Health() / ent:GetMaxHealth() * 100 elseif ent:IsNPC() then NPCcol = ent:GetColor() col = Vector(NPCcol.r / 255, NPCcol.g / 255, NPCcol.b / 255) plhp = ent:Health() / 40 * 100 end self.ResultTo = "$color" or "$color2" if ent:IsPlayer() or ent:IsNPC() then if plhp <= 50 and plhp > 40 then mat:SetVector( self.ResultTo, Vector(math.abs(SinBetween(0.35, 1, CurTime()*1.25)), math.abs(SinBetween(0.35, 1, CurTime()*1.25)), 0) ) elseif plhp <= 40 and plhp > 30 then mat:SetVector( self.ResultTo, Vector(math.abs(SinBetween(0.35, 1, CurTime()*2.5)), math.abs(SinBetween(0.35, 0.75, CurTime()*2.5)), 0) ) elseif plhp <= 30 and plhp > 0 then mat:SetVector( self.ResultTo, Vector(math.abs(SinBetween(0.35, 1, CurTime()*4)), 0, 0) ) elseif plhp <= 0 then mat:SetVector( self.ResultTo, col*0.05) else mat:SetVector( self.ResultTo, col ) end end else if self.DefaultValue then mat:SetVector( self.ResultTo, self.DefaultValue ) else --mat:SetVector( self.ResultTo, Vector( 0.0, 1.0, 0.83 ) ) mat:SetVector( self.ResultTo, Vector( 1.0, 1.0, 1.0 ) ) end end end } )