Cuberite Forum
Getting command sender - 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: Getting command sender (/thread-1459.html)



Getting command sender - gv1222 - 04-24-2014

Hi, i'm trying to get the player who sent the actual command, I searched around the api docs but couldn't find anything. Is there a way to do it? Thanks.


RE: Getting command sender - xoft - 04-24-2014

Hi,
How are you intercepting commands? When you register the command (using cPluginManager:BindCommand, http://mc-server.xoft.cz/LuaAPI/cPluginManager.html#functions or using Info.lua file) you give it a handler function, that handler function receives two parameters, the text that the user has sent (split into individual words into a table of strings) and the cPlayer object for the player who sent the command. So a typical command handler does something like this:
function HandleCmdSomething(a_Split, a_Player)
  -- a_Split is the command, split into words; access like a_Split[1], a_Split[2] etc.
  -- a_Player is the cPlayer object of the player who sent the command

  -- Do something command-related

  -- Notify the player that the command has been done successfully:
  a_Player:SendMessage(cCompositeChat("Success!", mtInfo))  -- Here's your cPlayer object being used
  return true
end



RE: Getting command sender - gv1222 - 04-24-2014

(04-24-2014, 07:26 AM)xoft Wrote: ...

Ah right in front of me, thank you!