r173: Register/bind commands
#1
A new feature in the upcoming release r173 is that you can register commands, so you don't have to parse the chat messages yourself anymore.

This feature was requested twice:
http://www.mc-server.org/support/index.p...task_id=71
http://www.mc-server.org/support/index.p...task_id=24

So you created a function that needs to be called when you type /god, this is the function:
Code:
function HandleGodCommand( Split, Player )
    if( not Player:HasPermission( "myplugin.god" ) ) then -- Check permissions first
        return false
    end
    MakePlayerGod( Player ) -- Do something to make the player invincible
    return true
end

It's really easy to bind this function to a command, you bind a command on a plugin. Like so:
Code:
function MyPlugin:Initialize()
    self:AddCommand("/god", " - Makes you invincible", "myplugin.god") -- This only adds the command to the commandlist for /help
    self:BindCommand("/god", HandleGodCommand) -- This actually binds the /god command to the HandleGodCommand function
    return true -- Make sure you return true, otherwise the plugin is not added
end

The function HandleGodCommand is called each time a player types /god

UPDATE:
In r174 you can also specify the permissions of a command, so you don't have to manually check it.
Code:
self:BindCommand("/god", HandleGodCommand) -- This still works, but you have to manually check permissions
self:BindCommand( "/home", "myplugin.god", HandleGodCommand) -- New version where permissions are checked for you
Both methods work.
Reply
Thanks given by:


Messages In This Thread
r173: Register/bind commands - by FakeTruth - 02-24-2011, 04:06 AM
RE: r173: Register/bind commands - by Tybor - 02-24-2011, 04:43 AM
RE: r173: Register/bind commands - by FakeTruth - 02-24-2011, 05:39 AM
RE: r173: Register/bind commands - by Tybor - 02-24-2011, 07:19 AM
RE: r173: Register/bind commands - by FakeTruth - 02-24-2011, 09:10 AM
RE: r173: Register/bind commands - by FakeTruth - 02-24-2011, 10:54 PM
RE: r173: Register/bind commands - by Tim - 02-25-2011, 10:15 PM
RE: r173: Register/bind commands - by Tybor - 02-25-2011, 02:36 AM



Users browsing this thread: 1 Guest(s)