Damage info (getting attackers/other things)

I’m experimenting with classes in Fretta right now and am having some trouble getting some info from the, uh, damage.

The EntityTakeDamage function only activates on taking damage, and I can’t seem to get who is attacking. Like, for example…

Player A attacks Player B. I know how to tell Player B that Player A is attacking them, but how do I tell Player A that they’re attacking Player B? (I know it’s really obvious to Player A, but still)

Also, is there any sort of function that runs when a player attacks another? Not a take damage, but some sort of a ‘deal damage’ thing… or something like that.

I’m having a hard time trying to explain what I mean.

Just notify the attacker in takedamage.
So in the same hook where you notice the victim.

**[CTakeDamageInfo.GetAttacker

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=CTakeDamageInfo.GetAttacker)**? lol

Alright, after playing with the code for a bit, I got this out…

[lua]function OnDamageTaken(ent, attacker)
ent:ChatPrint("YOU HAVE BEEN SHOT BY " … attacker)
end

function OnHit(ent, attacker)
attacker:ChatPrint("YOU HAVE SHOT " … ent)
end

function who_hit_who( ent, inflictor, attacker, amount )

ent:OnDamageTaken(ent, attacker)
attacker:OnHit(ent, attacker)

end
hook.Add(“EntityTakeDamage”,“who_hit_who”,who_hit_who)[/lua]

It’s a serverside script, but I’m getting no message on shot/being shot in chat/server console.

I’m sure the answer is staring me right in the face, but…

[lua]
ent:OnDamageTaken(ent, attacker)
attacker:OnHit(ent, attacker)
[/lua]
Should be
[lua]
OnDamageTaken(ent, attacker)
OnHit(ent, attacker)
[/lua]

Still no dice.

I’m beginning to think the entire problem is because of the function placement… maybe if I put OnHit and OnTakeDamage in a seperated shared file, they’ll work the way I want.

[lua]hook.Add(“EntityTakeDamage”,“who_hit_who”,function( victim, inflictor, attacker, amount, dmginfo )

if victim:IsPlayer() and attacker:IsPlayer() then
	victim:ChatPrint("YOU HAVE BEEN SHOT BY " .. attacker:Nick())
	attacker:ChatPrint("YOU HAVE SHOT " .. victim:Nick())
end

end)[/lua]

Use this serverside. I see no reason it wouldn’t work.

Making that code shared wouldn’t help one bit since the hook is serverside only.