Create Job

Hello everyone, I’m trying to create a new work based on gopostal. Almost everything works correctly, the only error is that I can not connect to the database to get the job information.

What am I trying to do?

I created a new job in the database
22 uber 2750 would be (id) (name job) (salary) I created all my work But what I had not realized was that the gopostal worked with old mysql and not mysql async. Then I started converting to mysql async to FX server

Steps that I did to convert from MYSQL to MYSQL Async

added server_script “@mysql-async/lib/MySQL.lua” in __resource
Remove all

  1. require “resources/mysql-async/lib/MySQL”

  2. require “resources/essential/lib/MySQL”

Chance All MySQL acess
and I changed the format of requesting access to mysql from

MySQL.executeQuery(
for
MySQL.Sync.fetchAll(

And the result in the end? did not work i’m breaking my head, but I can not find the error because all the other scripts I converted so only this one is giving problem. I’ll leave the original code and the new one here for you to take a look and who knows, someone can help me,

SCRIPT ORIGINAL

function nameJob(player)
  local executed_query = MySQL:executeQuery("SELECT identifier, job_id, job_name FROM users LEFT JOIN jobs ON jobs.job_id = users.job WHERE users.identifier = '@identifier'", {['@identifier'] = player})
  local result = MySQL:getResults(executed_query, {'job_name'}, "identifier")
  return tostring(result[1].job_name)
end



RegisterServerEvent('delivery:checkjob')
AddEventHandler('delivery:checkjob', function()
  TriggerEvent('es:getPlayerFromId', source, function(user)
    local player = user.identifier
    local namejob = nameJob(player)

    if namejob == "Delivery guy" then --here you change the jobname (from your database)
      TriggerClientEvent('yesdelivery', source)
    else
      TriggerClientEvent('nodelivery', source)
    end
  end)
end)

SCRIPT MODIFIED

function nameJob(player)
  local executed_query = MySQL.Sync.fetchAll("SELECT identifier, job_id, job_name FROM users LEFT JOIN jobs ON jobs.job_id = users.job WHERE users.identifier = '@identifier'", {['@identifier'] = player})
  local result = MySQL:getResults(executed_query, {'job_name'}, "identifier")
  return tostring(result[1].job_name)
end



RegisterServerEvent('delivery:checkjob')
AddEventHandler('delivery:checkjob', function()
  TriggerEvent('es:getPlayerFromId', source, function(user)
    local player = user.identifier
    local namejob = nameJob(player)

    if namejob == "Delivery guy" then --here you change the jobname (from your database)
      TriggerClientEvent('yesdelivery', source)
    else
      TriggerClientEvent('nodelivery', source)
    end
  end)
end)

MY DATABASE

THIS IS ERROR

2 Likes

You get this error because

MineGetPlayerJobID(...);

is not defined anywhere.

Wow, I’m sorry it was the old print. I updated the new one with the modifications I made. Could you refresh the page and review the print and code

this is my code now

function nameJob(player)
  local executed_query = MySQL.Sync.fetchAll("SELECT identifier, job_id, job_name FROM users LEFT JOIN jobs ON jobs.job_id = users.job WHERE users.identifier = '@identifier'", {['@identifier'] = player})
  local result = MySQL:getResults(executed_query, {'job_name'}, "identifier")
  return tostring(result[1].job_name)
end



RegisterServerEvent('delivery:checkjob')
AddEventHandler('delivery:checkjob', function()
  TriggerEvent('es:getPlayerFromId', source, function(user)
    local player = user.identifier
    local namejob = nameJob(player)

    if namejob == "Delivery guy" then --here you change the jobname (from your database)
      TriggerClientEvent('yesdelivery', source)
    else
      TriggerClientEvent('nodelivery', source)
    end
  end)
end)

Make sure you have the latest artifacts and mysql-async version. There has been some significant changes regarding mysql-async

I’m going to download just to be sure but I’m sure I’m using the latest version. A question encountered some error in my code in the conversion issue?

I try reinstall mysql but dont work same error

Redo the last screenshot, can’t see the first error message.

ohh sorry

Error

[    787672] Error running call reference function for resource delivery: sv_delivery.lua:3: attempt to call a nil value (method 'getResults')
[    787688] stack traceback:
[    787703] 	sv_delivery.lua:3: in function 'nameJob'
[    787703] 	sv_delivery.lua:13: in local 'ref'
[    787719] 	citizen:/scripting/lua/scheduler.lua:278: in function <citizen:/scripting/lua/scheduler.lua:269>
[    787734] 	[C]: in function 'coroutine.resume'
[    787750] 	citizen:/scripting/lua/scheduler.lua:33: in field 'CreateThreadNow'
[    787766] 	citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
[    787844] Error running system event handling function for resource essentialmode: citizen:/scripting/lua/scheduler.lua:39: Failed to execute thread: citizen:/scripting/lua/MessagePack.lua:830: missing bytes
[    787844] stack traceback:
[    787859] 	[C]: in function 'error'
[    787875] 	citizen:/scripting/lua/MessagePack.lua:830: in method 'underflow'
[    787891] 	citizen:/scripting/lua/MessagePack.lua:465: in field 'any'
[    787906] 	citizen:/scripting/lua/MessagePack.lua:860: in field 'unpack'
[    787922] 	citizen:/scripting/lua/scheduler.lua:339: in local 'cb'
[    787938] 	server/player/login.lua:106: in upvalue 'handler'
[    787953] 	citizen:/scripting/lua/scheduler.lua:124: in function <citizen:/scripting/lua/scheduler.lua:123>
[    787969] stack traceback:
[    787969] 	[C]: in function 'error'
[    787984] 	citizen:/scripting/lua/scheduler.lua:39: in field 'CreateThreadNow'
[    788000] 	citizen:/scripting/lua/scheduler.lua:123: in function <citizen:/scripting/lua/scheduler.lua:92>
[    788016] hitch warning: frame time of 434 milliseconds

By the I understood the error is in line 3 in the way that the job is taking the reference in the database

local result = MySQL:getResults(executed_query, {'job_name'}, "identifier")

You are using the mysql-async wrong. There is no need for the following code:

local result = MySQL:getResults(executed_query, {'job_name'}, "identifier")

The query variable already has the result of the query

local executed_query = MySQL.Sync.fetchAll("SELECT identifier, job_id, job_name FROM users LEFT JOIN jobs ON jobs.job_id = users.job WHERE users.identifier = '@identifier'", {['@identifier'] = player})

executed_query returns a table with all the values fetched.

1 Like

Thank you for that. It works now. I’ll work on a few more scripts, and release to the fiveM community

I have no error but not working…