Attacking players

I have been trying to create a way to set a players color to red when they have inflicted damage to another player. This only goes for the TEAM_PRISONER so when they attack a TEAM_GUARD with for example a weapon_m4a1 and a weapon_ak47 it would set there color to p:SetPlayerColor(246, 165, 14, 255).

Something like
if ply:Team(“TEAM_PRISONER”) and ply:CauseDamage(“TEAM_GUARD”) then
p:SetPlayerColor(246, 165, 14, 255)
end.

Its totally fake but something along them lines if you understand. Thanks in advance.

Hey if you check out the EntityTakeDamage hook, that gives you the victim and inflicter which you can do your team checks on and then set the color of your victim.

You seem kind of new to lua, so here’s how you make a hook:

There might be more ways, but I know of two…



function EnterANameHere( target, dmginfo)
 -- CODE -- 
end

hook.Add("EntityTakeDamage", "EnterANameHere", EnterANamehere)


or



hook.Add("EntityTakeDamage", "EnterANameHere", function( target, dmginfo)
 -- CODE -- 
end)


And hooks are just things which are tied to in-game events, and run all of the associated code when the “hook is tugged” (The event is called). Each hook can take different arguements (Ex. target, dmginfo)

And you can use



dmginfo:GetAttacker()


To see who was the one attacking inside of that hook.