Jump to content

Multiple Same Commands Question [RESOLVED]


Recommended Posts

Posted (edited)

I don't even think this is actually possible, but it's worth a shot anyway:

I have a /Test1 command and then a /Test2 command that will perform the same exact function

but instead of doing something like this:

addCommandHandler("Test1",TestFunction) 
addCommandHandler("Test2",TestFunction) 

Is there a way of merging them together? Such as...

addCommandHandler("Test1" or "Test2",TestFunction) 

Edited by Guest
Guest Guest4401
Posted

No, you can't merge like that. If you merge it with or, only /Test1 will work and not /Test2

Posted

You can use this:

local _addCommandHandler = addCommandHandler 
  
function addCommandHandler ( commandName, func, restricted, caseSensitive, ... ) 
    if ( type ( commandName ) ~= "table" ) then 
        _addCommandHandler ( commandName, func, restricted, caseSensitive, ... ) 
    else 
        for index, command in ipairs ( commandName ) do 
            _addCommandHandler ( command, func, restricted, caseSensitive, ... ) 
        end 
    end 
end 
  
addCommandHandler ( { "hello", "world" }, -- Both commands will work for the same function. 
    function ( thePlayer, commandName ) 
        outputChatBox ( commandName ) 
    end 
) 

Posted (edited)

Thank you Solid Snake 14, I appreciate the response... I'll give it a shot at my next chance :)

Update: Works like a charm, thanx again :D

Edited by Guest

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...