I can't create any commands. - 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: I can't create any commands. (/thread-1567.html) |
I can't create any commands. - Guandor - 09-06-2014 I tried to create a command but it gave an error. Then, I tried to use the example code in the documentation but it did the same. Here is the code and the error. function Initialize(Plugin) Plugin:SetName("DerpyPluginThatBlowsPeopleUp") Plugin:SetVersion(9001) cPluginManager.BindCommand("/explode", "derpyplugin.explode", Explode, " ~ Explode a player"); cPluginManager:AddHook(cPluginManager.HOOK_COLLECTING_PICKUP, OnCollectingPickup) LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true end function Explode(Split, Player) if (#Split ~= 2) then -- There was more or less than one argument (excluding the "/explode" bit) -- Send the proper usage to the player and exit SendMessage(Player, "Usage: /explode [playername]") return true end -- Create a callback ExplodePlayer with parameter Explodee, which MCS calls for every player on the server local HasExploded = false local ExplodePlayer = function(Explodee) -- If the player we are currently at is the one we specified as the parameter if (Explodee:GetName() == Split[2]) then -- Create an explosion at the same position as they are; see API docs for further details of this function Player:GetWorld():DoExplosionAt(Explodee:GetPosX(), Explodee:GetPosY(), Explodee:GetPosZ(), false, esPlugin) SendMessageSuccess(Player, Split[2] .. " was successfully exploded") HasExploded = true; return true -- Signalize to MCS that we do not need to call this callback for any more players end end -- Tell MCS to loop through all players and call the callback above with the Player object it has found cRoot:Get():FindAndDoWithPlayer(Split[2], ExplodePlayer) if not(HasExploded) then -- We have not broken out so far, therefore, the player must not exist, send failure SendMessageFailure(Player, Split[2] .. " was not found") end return true end function OnCollectingPickup(Player, Pickup) -- Again, see the API docs for parameters of all hooks. In this case, it is a Player and Pickup object if (Player:GetClientHandle():GetPing() > 100) then -- Get ping of player, in milliseconds return true -- Discriminate against high latency - you don't get drops else return false -- You do get the drops! Yay~ end end RE: I can't create any commands. - Seadragon91 - 09-06-2014 Hey! That's not all the code, or? Looks like you try to access the method SendMessage() in function Explode not over the Player object I think you have there around line 17 in file asd.lua: SendMessage() instead of Player:SendMessage(). regards, Seadragon91 RE: I can't create any commands. - xoft - 09-06-2014 Thank you for the report, it seems the example in the LuaAPI docs is outdated. There used to be an additional file that you would download and it would provide the SendMessage function for you; since then the function has moved directly to the API. To fix this, you need to change your line 17 to: Player:SendMessage("Usage: /explode [playername]") your line 28 to: Player:SendMessageSuccess(Split[2] .. " was successfully exploded") and your line 39 to: Player:SendMessageFailure(Split[2] .. " was not found") RE: I can't create any commands. - Guandor - 09-07-2014 I haven't tried yet, but I'm sure this is the problem. Thank you! RE: I can't create any commands. - Lo_Pan - 09-12-2014 Hey guys, First of all, C++ server, Awesome! Now for my problem, I seem to have the same errors, but fixing it as detailed above didn't help. Trying to get a simple command going, but my Lua knowledge is limited. Here is the code: "As I originaly figured it should work" function Initialize(Plugin) Plugin:SetName("STONED") Plugin:SetVersion(1) -- Hooks cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, RollJoint); PLUGIN = Plugin -- Command Bindings cPluginManager.BindCommand("/j", "STONED.j", RollJoint, " - is rolling a joint."); -- RollJoint binding LOG("Initialised " ..Plugin:GetName() .. " v." .. Plugin:GetVersion()) return true end function OnDisable() LOG(PLUGIN:GetName() .. " is shutting down.") end -- Default callback name is: function OnExecuteCommand(Player, Command) -- RollJoint Command: function RollJoint(Player, j) SendMessage(Player, " " .. Player:GetName(Player) .. " is rolling a joint.") return true end And here is the drama the console gave me: --Warn [21:43:59] LUA: Plugins/STONED/stoned.lua:31: attempt to call global 'SendMessage' (a nil value) --Warn [21:43:59] Stack trace: --Warn [21:43:59] Plugins/STONED/stoned.lua(31): (no name) --Warn [21:43:59] Stack trace end --Warn [21:43:59] Error in plugin STONED calling function <callback>() --Warn [21:43:59] LUA: Plugins/STONED/stoned.lua:31: attempt to call method 'GetName' (a nil value) --Warn [21:43:59] Stack trace: --Warn [21:43:59] Plugins/STONED/stoned.lua(31): (no name) --Warn [21:43:59] Stack trace end --Warn [21:43:59] Error in plugin STONED calling function <callback>()[/php] Tried changing SendMessage to Player:SendMessage and the other solutions pointed out in the post above.. What am I overlooking here? RE: I can't create any commands. - NiLSPACE - 09-12-2014 What errors did you get? RE: I can't create any commands. - Lo_Pan - 09-12-2014 (09-12-2014, 03:55 AM)STR_Warrior Wrote: What errors did you get? And here is the drama the console gave me: --Warn [21:43:59] LUA: Plugins/STONED/stoned.lua:31: attempt to call global 'SendMessage' (a nil value) --Warn [21:43:59] Stack trace: --Warn [21:43:59] Plugins/STONED/stoned.lua(31): (no name) --Warn [21:43:59] Stack trace end --Warn [21:43:59] Error in plugin STONED calling function <callback>() --Warn [21:43:59] LUA: Plugins/STONED/stoned.lua:31: attempt to call method 'GetName' (a nil value) --Warn [21:43:59] Stack trace: --Warn [21:43:59] Plugins/STONED/stoned.lua(31): (no name) --Warn [21:43:59] Stack trace end --Warn [21:43:59] Error in plugin STONED calling function <callback>() RE: I can't create any commands. - Seadragon91 - 09-12-2014 Hello! Change Player:GetName(Player) to Player:GetName() SendMessage to Player:SendMessage and remove the "Player," there regards, Seadragon91 RE: I can't create any commands. - Lo_Pan - 09-12-2014 (09-12-2014, 04:47 AM)Seadragon91 Wrote: Hello! Hello! Thank you very much, this works! Greatly appreciated. I do get a console msg tho saying: Player "myplayername" tried to execute command "/j" that was stopped by the HOOK_EXECUTE_COMMAND hook No idea what that is about. EDIT: It gives the same console remark on /me command. Also, this command is visible for all players, and not just the player typing the command. For this command all players should see it, so that works as intended, but how would I go about in making it visible to only the player typing the command? RE: I can't create any commands. - LO1ZB - 09-12-2014 (09-12-2014, 05:04 AM)Lo_Pan Wrote: Player "myplayername" tried to execute command "/j" that was stopped by the HOOK_EXECUTE_COMMAND hook Why do you use the same function for a Hook and a command? It is called first from the hook, then you after sending the message to the player, you are returning "true", which means "hook successfully executed", if you want that the command get executed, you have to return "false". |