Any way to run a player command from a plugin?
#1
Hello,
I'm planning on making something that allows the console and command blocks to run commands as if they were a player. You would put like /run [SomePlayerCommand] inside of a command block and when powering it, it would execute it as if it was a player in the overworld with rank Admin. Has anyone done something like that before or knows what functions to call to make this work?

And for all those shouting "Just use cPluginManager.ExecuteCommand":
It doesn't seem to work correctly for my usecase. At least not in the way I tried to use it before.
Here is my current code that doesn't work:
Code:
function run(Split)
    if (#Split < 2) then
    -- There was less than one argument (excluding the "/" bit)
    -- Send the proper usage to the player and exit
    cRoot.BroadcastChatInfo("/say You need to provide a command.")
    return true
    end
    cPluginManager.ExecuteCommand(cPluginManager, tostring(Split))
    return true
end

Edit:
I'm so terrible at lua that even the help message won't work:
Code:
error in function 'BroadcastChatInfo'.
     argument #1 is 'string'; 'cRoot' expected.
Reply
Thanks given by:
#2
Look at the API documentation for what ExecuteCommand function requires. It also requires a player object. Also, tostring(Split) isn't how you concatenate a table in Lua. You use table.concat for that.

EDIT:
Also, only functions marked in the documentation as STATIC require that you call the function with a period. Otherwise you can call the function with a colon without itself as the first argument.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)