Jump to content

A small question


Recommended Posts

Posted

Greetings , i was wondering how to use :

addCommandHandler 

with a 2 parts command. Normally , i'd use

addCommandHandler ("commandname" ,Handlerfucntion ) 

But i want to do a command like /goto [iD] , It consists on two parts which are the basic command and the Player's ID. So what's the appropriate use of that function in a similar case ?

Posted
addCommandHandler ( "goto", 
    function ( thePlayer, cmd, ID ) 
        local ID = tonumber ( ID ) 
    end 
) 

Is that what you meant?

Posted

[lua]

addCommandHandler ( "goto", -- the command handler

function ( thePlayer, cmd, ID ) -- The function

local ID = tonumber ( ID ) -- It will add the ID as you told /goto ID. It must be a number.

end

)

Posted

Handler function parameters

These are the parameters for the handler function that is called when the command is used.

Server

player playerSource, string commandName, [string arg1, string arg2, ...]

playerSource: The player who triggered the command. If not triggered by a player (e.g. by admin), this will be false.

commandName: The name of the command triggered. This is useful if multiple commands go through one function.

arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below.

Client

string commandName, [string arg1, string arg2, ...]

commandName: The name of the command triggered. This is useful if multiple commands go through one function.

arg1, arg2, ...: Each word after command name in the original command is passed here in a seperate variable. If there is no value for an argument, its variable will contain nil. You can deal with a variable number of arguments using the vararg expression, as shown in Server Example 2 below.

That is why Solidsnake used function(thePlayer,command,id)

For example, if you use the command /goto 11 thePlayer will be the player element that requested the command, the command will be a string : "goto" and the id will be an argument specified by you, in this case 11.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...