[Help] Registering more than 1 command

help

#1

Hello,

I’m kinda new to .lua, I’m using vSync and the command to change weather is "/weather " but I want to have 2 commands to execute that.
I want it to be /weather or /clima (portuguese).

I tried to do it like that, RegisterCommand('weather' or 'clima', function(source, args) but it didn’t work, can someone help me please?


#2

You cant do it that way just make 2 seperate commands triggering the same thing.


#3
RegisterCommand('clima', function(source, args)
    if source == 0 then
        local validWeatherType = false
        if args[1] == nil then
            print("Uso incorreto, a maneira correta é: /clima <clima> ")
            return
        else
            for i,wtype in ipairs(AvailableWeatherTypes) do
                if wtype == string.upper(args[1]) then
                    validWeatherType = true
                end
            end
            if validWeatherType then
                print("O clima foi alterado.")
                CurrentWeather = string.upper(args[1])
                newWeatherTimer = 10
                TriggerEvent('vSync:requestSync')
            else
                print("Clima inválido, os climas disponíveis são: \nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ")
            end
        end
    else
        if isAllowedToChange(source) then
            local validWeatherType = false
            if args[1] == nil then
                TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Uso incorreto, use ^0/clima <clima> ^1!')
            else
                for i,wtype in ipairs(AvailableWeatherTypes) do
                    if wtype == string.upper(args[1]) then
                        validWeatherType = true
                    end
                end
                if validWeatherType then
                    TriggerClientEvent('vSync:notify', source, 'O clima vai ser alterado para: ~y~' .. string.lower(args[1]) .. "~s~.")
                    CurrentWeather = string.upper(args[1])
                    newWeatherTimer = 10
                    TriggerEvent('vSync:requestSync')
                else
                    TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Clima inválido, os climas disponíveis são: ^0\nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ')
                end
            end
        else
            TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Não tem permissões para usar esse comando.')
            print('Não tem permissões para usar esse comando.')
        end
    end
end, false)

This is the whole command, I need to copy paste all of this and change the command?


#4

Could make an event, so:

RegisterCommand('command1', functon()
    TiggerEvent('event1')
end)

RegisterCommand('command2', functon()
    TiggerEvent('event1')
end)

RegisterNetEvent('event1')
AddEventHandler('event1', function()
    -- Your code here
end)

#5

Thanks for you answer.

I tried to make it like this:

RegisterCommand('clima', function(source, args)
    TriggerEvent('clima')
end)

RegisterCommand('weather', function(source, args)
    TriggerEvent('clima')
end)

RegisterNetEvent('clima')
AddEventHandler('clima', function()
    if source == 0 then
        local validWeatherType = false
        if args[1] == nil then
            print("Uso incorreto, a maneira correta é: /clima <clima> ")
            return
        else
            for i,wtype in ipairs(AvailableWeatherTypes) do
                if wtype == string.upper(args[1]) then
                    validWeatherType = true
                end
            end
            if validWeatherType then
                print("O clima foi alterado.")
                CurrentWeather = string.upper(args[1])
                newWeatherTimer = 10
                TriggerEvent('vSync:requestSync')
            else
                print("Clima inválido, os climas disponíveis são: \nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ")
            end
        end
    else
        if isAllowedToChange(source) then
            local validWeatherType = false
            if args[1] == nil then
                TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Uso incorreto, use ^0/clima <clima> ^1!')
            else
                for i,wtype in ipairs(AvailableWeatherTypes) do
                    if wtype == string.upper(args[1]) then
                        validWeatherType = true
                    end
                end
                if validWeatherType then
                    TriggerClientEvent('vSync:notify', source, 'O clima vai ser alterado para: ~y~' .. string.lower(args[1]) .. "~s~.")
                    CurrentWeather = string.upper(args[1])
                    newWeatherTimer = 10
                    TriggerEvent('vSync:requestSync')
                else
                    TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Clima inválido, os climas disponíveis são: ^0\nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ')
                end
            end
        else
            TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Erro: ^1Não tem permissões para usar esse comando.')
            print('Não tem permissões para usar esse comando.')
        end
    end
end, false)

But everytime I try to execute the weather or clima command I get the print message saying “Não tem permissões para usar esse comando.” that means “Invalid permissions”.


#6

This means that your isAllowedToChange() function is returning false.


#7

You’re not passing the arguments or the source to the event so, it has no idea what “args” is. This makes your args[1] == nil return true (because it doesn’t exist) resulting in your error. Since “source” is also nil, your function is returning false (because “nil” doesn’t have permission to change the weather)