Jump to content

Multiple Commands for handler


Recommended Posts

Is something like this possible?

  
function getModInfo(thePlayer) 
    local veh = getPedOccupiedVehicle (thePlayer) 
    if veh then 
        executeCommandHandler({"getspeed", "getpower"}, thePlayer) 
    else 
        outputChatBox("You're not in a vehicle.", thePlayer, 255, 0, 0) 
    end 
end 
addCommandHandler({"getmods", "getmod"}, getModInfo) 
  

I get the error, Expected String at Argument 1 for CommandHandler, got table.

Is there another way then? Instead of having a annoying list on each line?

Link to comment
onPlayerCommand 

Which this you can check which command has been used.

That doesn't really answer the question. I'm asking about addCommandHandler and executeCommandhandler.

If they can have multiple commands like that, or if I have to do them on a individual line.

  
addCommandHandler("getmods", getModInfo) 
addCommandHandler("getmod", getModInfo) 
  

Link to comment

Found a small script that allows this, Solved otherwise but I'll post it for anyone else to use.

  
local addCommandHandler_ = addCommandHandler 
    addCommandHandler  = function(commandName, fn, restricted, caseSensitive) 
    if (type(commandName) ~= "table") then 
        commandName = {commandName} 
    end 
    for key, value in ipairs(commandName) do 
        if (key == 1) then 
            addCommandHandler_(value, fn, restricted, false) 
        else 
            addCommandHandler_(value, 
                function(player, ...) 
                    fn(player, ...) 
                end, false, false 
            ) 
        end 
    end 
end 
  

Link to comment

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