Jump to content

Why is this not working?


Recommended Posts

So I made a script where if you type /cv [400-611] it will spawn a vehicle, and if you type no number, then it will open a GUI that allows you to type a number. After typing the number in the GUI and clicking "Choose" it should read the function again and create a vehicle with the number that is written in the editbox. It was based on another script I made that workes perfectly fine, so there shouldn't be no reason for this one no to work...

 

CLIENT (Everything works until the last function):

function criarVeiculo()
    janelaVeiculos = DGS:dgsCreateWindow (0.015, 0.18, 0.10, 0.20, "Criar Veículo", true)
    DGS:dgsWindowSetCloseButtonEnabled(janelaVeiculos, false)
    showCursor(true)
    DGS:dgsSetInputMode("no_binds_when_editing")
    DGS:dgsWindowSetSizable(janelaVeiculos, false)

    modeloVeiculo = DGS:dgsCreateEdit(0.1, 0.07, 0.8, 0.17, "Modelo do Veículo [400-611]", true, janelaVeiculos)
    guiEditSetMaxLength (modeloVeiculo, 20)
    addEventHandler("onDgsMouseClick", modeloVeiculo, mudarTextoModeloVeiculo)

    buttonCV = DGS:dgsCreateButton(0.53, 0.73, 0.37, 0.20, "Cancelar", true, janelaVeiculos)
    addEventHandler ("onDgsMouseClick", buttonCV, cancelamentojanelaVeiculos)
    buttonEV = DGS:dgsCreateButton(0.1, 0.73, 0.37, 0.20, "Escolher", true, janelaVeiculos)
    addEventHandler ("onDgsMouseClick", buttonEV, escolhajanelaVeiculos)
end
addEvent("veiculoJanela", true)
addEventHandler("veiculoJanela", getLocalPlayer(), criarVeiculo)

function mudarTextoModeloVeiculo()
    DGS:dgsEditClearText(modeloVeiculo)
end

function cancelamentojanelaVeiculos()
    DGS:dgsCloseWindow(janelaVeiculos)
    showCursor(false)
end

function escolhajanelaVeiculos()
    local textoModeloVeiculo = DGS:dgsGetText(modeloVeiculo)
    triggerServerEvent("criarVeiculo", resourceRoot, textoModeloVeiculo)
    DGS:dgsCloseWindow(janelaVeiculos)
    showCursor(false)
end

After I type a correct model on the box it returns this erros on the server:

Line 19: Bad argument @ 'outputChatBox' [Excpected string at argument 1, got nil]

Line 18: Bad argument @ 'getElementPosition0 [Expected element at argument 1, got string 457' (this means it sends the correct number to the server, but not in the right place)

Line 19: Bad argument @ 'outputChatBox' [Excpected string at argument 1, got nil]

Line 20: attempt to perform arithmetic on local 'y' (a nil value)

 

 

If I change resourceRoot to anything else, it returns this errors on the server:

Line 19: Bad argument @ 'outputChatBox' Expected string at argument 1, got nil

 

 

SERVER:

function createVehicleForPlayer(player, command, model)
    local x, y, z = getElementPosition(player)
    outputChatBox(model)
    y = y + 5
    if model then
        outputChatBox("Ola2")
        local veiculoCriado = createVehicle(model, x, y, z)
        local nomeVeiculo = getVehicleName(veiculoCriado)
        if veiculoCriado then
        outputChatBox(horaJ.. "Criaste um " ..corVeiculo.. nomeVeiculo.. corMJ.. " (modelo: "..corVeiculo.. model.. corMJ.. ") com sucesso.", player, isR, isG, isB, true)
        addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)
        else
            outputChatBox(horaE.. corErro.. "Uso: /cv [" ..corVeiculo.. "400" ..corErro.. "-" ..corVeiculo.. "611" ..corErro.. "].", player, isR, isG, isB, true)
        end
    else
        triggerClientEvent("veiculoJanela", player)
        outputChatBox("Feito")
    end
end

 addCommandHandler('cv', createVehicleForPlayer)
 addCommandHandler('criarveiculo', createVehicleForPlayer)
 addEvent("criarVeiculo", true)
 addEventHandler("criarVeiculo", resourceRoot, createVehicleForPlayer)

If at the addEventHandler("criarVeiculo") I change resourceRoot to localPlayer, it returns this error:

Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

 

Thanks for the help!

 

Link to comment
1 hour ago, Hugo_Almeidowski said:

SERVER:


function createVehicleForPlayer(player, command, model)
    local x, y, z = getElementPosition(player)
    outputChatBox(model)
    y = y + 5
    if model then
        outputChatBox("Ola2")
        local veiculoCriado = createVehicle(model, x, y, z)
        local nomeVeiculo = getVehicleName(veiculoCriado)
        if veiculoCriado then
        outputChatBox(horaJ.. "Criaste um " ..corVeiculo.. nomeVeiculo.. corMJ.. " (modelo: "..corVeiculo.. model.. corMJ.. ") com sucesso.", player, isR, isG, isB, true)
        addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)
        else
            outputChatBox(horaE.. corErro.. "Uso: /cv [" ..corVeiculo.. "400" ..corErro.. "-" ..corVeiculo.. "611" ..corErro.. "].", player, isR, isG, isB, true)
        end
    else
        triggerClientEvent("veiculoJanela", player)
        outputChatBox("Feito")
    end
end

 addCommandHandler('cv', createVehicleForPlayer)
 addCommandHandler('criarveiculo', createVehicleForPlayer)
 addEvent("criarVeiculo", true)
 addEventHandler("criarVeiculo", resourceRoot, createVehicleForPlayer)

If at the addEventHandler("criarVeiculo") I change resourceRoot to localPlayer, it returns this error:

Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]

 

In 'addEventHandler' on line 24 [ or 25 :3 ] of that code, change argument 2 from 'resourceRoot' to 'getRootElement()'.

And try some edits like below to the function;

function createVehicleForPlayer(player, command, model)
    if model then
      local x, y, z = getElementPosition(player)
        outputChatBox(model,player)
        y = y + 5
        outputChatBox("Ola2",player)
      local veiculoCriado = createVehicle(tonumber(model), x, y, z)
      local nomeVeiculo = getVehicleName(veiculoCriado)
        if veiculoCriado then
            outputChatBox(horaJ.. "Criaste um " ..corVeiculo.. nomeVeiculo.. corMJ.. " (modelo: "..corVeiculo.. model.. corMJ.. ") com sucesso.", player, isR, isG, isB, true)
        else
            outputChatBox(horaE.. corErro.. "Uso: /cv [" ..corVeiculo.. "400" ..corErro.. "-" ..corVeiculo.. "611" ..corErro.. "].", player, isR, isG, isB, true)
        end
    else
        triggerClientEvent(player, "veiculoJanela", player)
        outputChatBox("Feito")
    end
end
addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)

 

Edited by DeadthStrock
Link to comment
2 hours ago, DeadthStrock said:

In 'addEventHandler' on line 24 [ or 25 :3 ] of that code, change argument 2 from 'resourceRoot' to 'getRootElement()'.

And try some edits like below to the function;


function createVehicleForPlayer(player, command, model)
    if model then
      local x, y, z = getElementPosition(player)
        outputChatBox(model,player)
        y = y + 5
        outputChatBox("Ola2",player)
      local veiculoCriado = createVehicle(tonumber(model), x, y, z)
      local nomeVeiculo = getVehicleName(veiculoCriado)
        if veiculoCriado then
            outputChatBox(horaJ.. "Criaste um " ..corVeiculo.. nomeVeiculo.. corMJ.. " (modelo: "..corVeiculo.. model.. corMJ.. ") com sucesso.", player, isR, isG, isB, true)
        else
            outputChatBox(horaE.. corErro.. "Uso: /cv [" ..corVeiculo.. "400" ..corErro.. "-" ..corVeiculo.. "611" ..corErro.. "].", player, isR, isG, isB, true)
        end
    else
        triggerClientEvent(player, "veiculoJanela", player)
        outputChatBox("Feito")
    end
end
addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion)

 

It returns these:

Bad argument @ outputChatBox Expected string at argument 1, got nil

Bad argument @ getElementPosition Expected element at argument 1, got string 462

Bad argument @ getElementPosition Expected element at argument 1, got string 462 (I changed the code a bit)

Bad argument @ outputChatBox Expected string at argument 1, got nil

Bad argument @ triggerClientEvent Expected element at argument 2, got string 462

Link to comment
7 hours ago, Hugo_Almeidowski said:

It returns these:

Bad argument @ outputChatBox Expected string at argument 1, got nil

Bad argument @ getElementPosition Expected element at argument 1, got string 462

Bad argument @ getElementPosition Expected element at argument 1, got string 462 (I changed the code a bit)

Bad argument @ outputChatBox Expected string at argument 1, got nil

Bad argument @ triggerClientEvent Expected element at argument 2, got string 462

According to the way I think, that errors looks not received from the function that I gave you. check that carefully

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