Cuberite Forum
Converting cEntity to cPlayer - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Converting cEntity to cPlayer (/thread-1493.html)



Converting cEntity to cPlayer - TuxGamer - 06-20-2014

Hey,

I am messing arount with your software as it seems pretty nice and powerful.

But I have one problem: How do I convert an entity from the hook to a player?

In Java I get an Entity object from the Event (PlayerInteractEntityEvent in this case).
And then I can convert that to a Player: (Player)event.getEntity()

How do I do that in Lua?
Code:
function PlayerInteract(Player, Entity)
  if Entity:GetEntityType() == cEntity.etPlayer and Player:GetInventory():GetEquippedItem().m_ItemType == 369 then
    Player:SendMessage("§a" .. "..Name of Entity")
  end
end

Sorry for my nooby questions, but I am new to Lua and MCServer :)


RE: Converting cEntity to cPlayer - bearbin - 06-20-2014

You should use cChatColour, it's clearer.

If you don't already have the API docs, they are here: http://mc-server.xoft.cz/LuaAPI/


RE: Converting cEntity to cPlayer - tigerw - 06-20-2014

One should do this:

tolua.cast(Entity, "cPlayer"):GetInventory()...



RE: Converting cEntity to cPlayer - TuxGamer - 06-20-2014

Thank you for the quick answers :), it is working now