Get cPlayer object in OnTakeDamage hook
#1
How can I do that?
I want to make an enchanting plugin. A player, when attacking, should take more damage with an enchanted sword, but I need to get the cPLayer object, how can I get it from Attacker?
Reply
Thanks given by:
#2
The second parameter of OnTakeDamage is a TakeDamageInfo struct. This struct contains an Attacker value. The value is of a cEntity object, but you can cast it to a cPlayer if you are sure it is a player.
If you're just wondering about the casting, use this:
local AttackerPlayer = tolua.cast(TDI.Attacker,"cPlayer")

Be sure you are actually dealing with a cPlayer object by checking it with TDI.Attacker:IsPlayer() or TDI.Attacker:IsA("cPlayer"). The former is faster than the latter but both work.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)