ESX.RegisterCommand error

Hey, my friend made me a script, and now he can’t fix it because he is not home. So I am trying to fix it by myself…

I get this error when I start my script:

I don’t know how to fix it…

ESX.RegisterCommand('vaikunamai', 'admin', function(xPlayer, args, showError)

    local targetPlayer = ESX.GetPlayerFromId(args["id"])

    if targetPlayer ~= nil then

        targetPlayer.setCoords(Config.HousePosition)

        local result = MySQL.Sync.fetchAll('SELECT * FROM peurost_vnamai WHERE identifier = @id', {

            ['@id'] = targetPlayer.getIdentifier(),

        })

        local amount = 0

        if #result > 0 then

            MySQL.Async.execute('UPDATE peurost_vnamai SET amount = @amount WHERE identifier = @id', {

                ['@id'] = targetPlayer.getIdentifier(),

                ['@amount'] = result[1].amount + args["kiekis"]

            })

            amount = result[1].amount + args["kiekis"]

        else

            MySQL.Async.execute('INSERT INTO peurost_vnamai VALUES (@id, @amount)', {

                ['@id'] = targetPlayer.getIdentifier(),

                ['@amount'] = args["kiekis"]

            })

            amount = args["kiekis"]

        end

        cache[targetPlayer.getIdentifier()] = amount

        TriggerClientEvent("peurost_vnamai:sentToHouse", args["id"], cache[targetPlayer.getIdentifier()])

    end

end, true, {help = "Pasodinti žaidėją į vaikų namus", validate = true, arguments = {

    {name = 'id', help = 'Žaidėjo ID', type = 'number'},

    {name = 'kiekis', help = 'Klausimų kiekis', type = 'number'}

}})

What is your esx version?

My es_extended version is 1.1.0

Try to replace this line: ESX.RegisterCommand(‘vaikunamai’, ‘admin’, function(xPlayer, args, showError)

with this one: TriggerEvent(‘es:addGroupCommand’, ‘vaikunamai’, ‘admin’, function(xPlayer, args, showError)

Now it gives me this error…

Can you send the server lua?

ESX = nil

TriggerEvent(Config.SharedObject, function(obj) ESX = obj end) 

local cache = {}

RegisterNetEvent("peurost_vnamai:completedTest")

AddEventHandler("peurost_vnamai:completedTest", function(rightAnswers)

    release(source)

end)

RegisterNetEvent("peurost_vnamai:ranAway")

AddEventHandler("peurost_vnamai:ranAway", function()

    local xPlayer = ESX.GetPlayerFromId(source)

    local amount = cache[xPlayer.getIdentifier()]

    MySQL.Async.execute('UPDATE peurost_vnamai SET amount = @amount WHERE identifier = @id', {

        ['@id'] = xPlayer.getIdentifier(),

        ['@amount'] = amount + Config.Penalty

    })

    cache[xPlayer.getIdentifier()] = amount + Config.Penalty

    xPlayer.setCoords(Config.HousePosition)

    xPlayer.showNotification("Ir ku gi tu begi?")

    TriggerClientEvent("peurost_vnamai:sentToHouse", source, cache[xPlayer.getIdentifier()])

end)

RegisterNetEvent('peurost_vnamai:playerLoaded')

AddEventHandler('peurost_vnamai:playerLoaded', function()  

    local xPlayer = ESX.GetPlayerFromId(source)

    MySQL.Async.execute('CREATE TABLE IF NOT EXISTS peurost_vnamai (identifier text,amount int NOT NULL);', {})

    local result = MySQL.Sync.fetchAll('SELECT * FROM peurost_vnamai WHERE identifier = @id', {

        ['@id'] = xPlayer.getIdentifier(),

    })

    if #result > 0 and result[1].amount ~= nil and result[1].amount > 0 then

        cache[xPlayer.getIdentifier()] = result[1].amount

    end

    if cache[xPlayer.getIdentifier()] ~= nil and cache[xPlayer.getIdentifier()] > 0 then

        xPlayer.setCoords(Config.HousePosition)

        TriggerClientEvent("peurost_vnamai:sentToHouse", xPlayer.source, cache[xPlayer.getIdentifier()])

    end

end)

function release(source)

    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer ~= nil then

        xPlayer.setCoords(Config.ReleasePosition)

        MySQL.Async.execute('DELETE FROM peurost_vnamai WHERE identifier = @id', {

            ['@id'] = xPlayer.getIdentifier()

        })

        cache[xPlayer.getIdentifier()] = 0

        TriggerClientEvent("peurost_vnamai:removedFromHouse", xPlayer.source)

    end

end

TriggerEvent(‘es:addGroupCommand’, ‘vaikunamai’, ‘admin’, function(xPlayer, args, showError)

    local targetPlayer = ESX.GetPlayerFromId(args["id"])

    if targetPlayer ~= nil then

        targetPlayer.setCoords(Config.HousePosition)

        local result = MySQL.Sync.fetchAll('SELECT * FROM peurost_vnamai WHERE identifier = @id', {

            ['@id'] = targetPlayer.getIdentifier(),

        })

        local amount = 0

        if #result > 0 then

            MySQL.Async.execute('UPDATE peurost_vnamai SET amount = @amount WHERE identifier = @id', {

                ['@id'] = targetPlayer.getIdentifier(),

                ['@amount'] = result[1].amount + args["kiekis"]

            })

            amount = result[1].amount + args["kiekis"]

        else

            MySQL.Async.execute('INSERT INTO peurost_vnamai VALUES (@id, @amount)', {

                ['@id'] = targetPlayer.getIdentifier(),

                ['@amount'] = args["kiekis"]

            })

            amount = args["kiekis"]

        end

        cache[targetPlayer.getIdentifier()] = amount

        TriggerClientEvent("peurost_vnamai:sentToHouse", args["id"], cache[targetPlayer.getIdentifier()])

    end

end, true, {help = "Pasodinti žaidėją į vaikų namus", validate = true, arguments = {

    {name = 'id', help = 'Žaidėjo ID', type = 'number'},

    {name = 'kiekis', help = 'Klausimų kiekis', type = 'number'}

}})

TriggerEvent(‘es:addGroupCommand’, ‘paleistinamai’, ‘admin’, function(xPlayer, args, showError)

    release(args["id"])

end, true, {help = "Paleisti žaidėją iš vaikų namų", validate = true, arguments = {

    {name = 'id', help = 'Žaidėjo ID', type = 'number'}

}})

Here you go :slight_smile:

If you don’t mind if it’s a free resource can you send the resource here?

Sorry, the resource is paid… Maybe you know how to fix the error, only with server main.lua

Okay. No problem. Let me recheck

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.