Cuberite Forum
Get cPlayer object in OnTakeDamage hook - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Get cPlayer object in OnTakeDamage hook (/thread-1248.html)



Get cPlayer object in OnTakeDamage hook - tonibm19 - 09-22-2013

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?


RE: Get cPlayer object in OnTakeDamage hook - FakeTruth - 09-22-2013

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.