Jump to content

Problem with executeCommandHandler


Recommended Posts

Simple problem, I am not familiar with using executeCommandHandler nor working with using "..." but it just fails to execute everytime.

local execcmd = nil 
function executeCommand(thePlayer, commandName, exeCmd, targetPlayer, ...) 
    if(exports.global:isPlayerOwner(thePlayer))then 
        if not (exeCmd) or not (targetPlayer) then 
            outputChatBox("Syntax: /"..commandName.." [player id] [cmd name] [arguments]", thePlayer, 255, 0, 0) 
            return 
        end 
        if(...)then 
            execcmd = executeCommandHandler(exeCmd,targetPlayer,...) 
            if(execcmd)then 
                outputChatBox("Command Execution successful!", thePlayer, 0, 255, 0) 
            else 
                outputChatBox("Command Execution failed!", thePlayer, 255, 0, 0) 
            end 
        else 
            execcmd = executeCommandHandler(exeCmd,targetPlayer) 
            if(execcmd)then 
                outputChatBox("Command Execution successful!", thePlayer, 0, 255, 0) 
            else 
                outputChatBox("Command Execution failed!", thePlayer, 255, 0, 0) 
            end 
        end 
    else 
        outputChatBox("This.",thePlayer,255,0,0) 
    end 
end 
addCommandHandler("exec", executeCommand) 

Link to comment

I believe the problem is that you cannot execute a command which isn't in the .lua file which contains the executeCommandHandler function of yours itself, i.e, the command you're trying to execute is in a separate .lua file.

Link to comment
  
addCommandHandler("exec",function(Me,Cmd,pName,Cmd,...) 
    -- pName : The other player name | Cmd : the command to execute | ... : arguments 
    if ( exports.global:isPlayerOwner(thePlayer) ) then 
        if ( not pName or not Cmd ) then 
            outputChatBox("Syntax: /"..Cmd.." [player name] [cmd name] [arguments]", Me, 255, 0, 0) 
            return 
        end 
        local args = table.concat({...}," ") 
        local target = getPlayerFromName(pName) 
        if not target then 
            outputChatBox("Player does not exist!",Me,255,0,0,true) 
            return 
        end 
        if executeCommandHandler(Cmd,target,tostring(args)) then 
            outputChatBox("Command Execution successful!", Me, 0, 255, 0) 
        else 
            outputChatBox("Command Execution failed!", Me, 255, 0, 0) 
        end 
    else 
        outputChatBox("This.",Me,255,0,0) 
    end 
end ) 
  

Using this function : https://wiki.multitheftauto.com/wiki/Get ... omNamePart will be good.

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