Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

qbcore script issue #140

Open
Acecash112 opened this issue May 8, 2023 · 0 comments
Open

qbcore script issue #140

Acecash112 opened this issue May 8, 2023 · 0 comments

Comments

@Acecash112
Copy link

I keep getting these two errors in my console when running the script ;

Error loading script init.lua in resource renzu_shops: @renzu_shops/init.lua:96: bad argument #1 to 'for iterator' (table expected, got nil)
[ script:renzu_shops] stack traceback:
[ script:renzu_shops] [C]: in function 'next'
[ script:renzu_shops] @renzu_shops/init.lua:96: in function 'MultiCategory'
[ script:renzu_shops] [string "return {..."]:369: in main chunk
[ script:renzu_shops] (...tail calls...)
[ script:renzu_shops] @renzu_shops/init.lua:114: in main chunk
[ c-scripting-core] Failed to load script init.lua.

this is the second error code :

[ script:renzu_shops] SCRIPT ERROR: @renzu_shops/server/main.lua:1990: attempt to concatenate a nil value (global 'vehicletable')
[ script:renzu_shops] SCRIPT ERROR: [string "local dbdata = {['financedata'] = {['columns'..."]:201: bad argument #1 to 'for iterator' (table expected, got nil)
[ script:renzu_shops] > [global chunk] (ocal dbdata = {['financedata'] = {['columns'] = 'identifier,max,financed',['values'] = '?,?,?'},['renzu_stores'] = {['columns'] = 'shop,owner,money,items,employee,cashier,customitems,job',['values'] = '?,?,?,?,?,?,?,?'},['movableshops'] = {['columns'] = 'identifier,owner,money,items,plate,type,shopname',['values'] = '?,?,?,?,?,?,?'},}
[ script:renzu_shops]
[ script:renzu_shops] local db = setmetatable({},{
[ script:renzu_shops] call = function(self)
[ script:renzu_shops]
[ script:renzu_shops] self.insert = function(name, data)
[ script:renzu_shops] local str = 'INSERT INTO %s (%s) VALUES(%s)'
[ script:renzu_shops] return MySQL.insert.await(str:format(name,dbdata[name].columns,dbdata[name].values),data)
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] self.update = function(name, column, where, update, data)
[ script:renzu_shops] local str = 'UPDATE %s SET %s = ? WHERE %s = ?'
[ script:renzu_shops] return MySQL.query(str:format(name,column,where),{data,update})
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] self.delete = function(name, where, update)
[ script:renzu_shops] local str = 'DELETE FROM %s WHERE %s = ?'
[ script:renzu_shops] return MySQL.query(str:format(name,where),{update})
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] self.save = function(data)
[ script:renzu_shops] Citizen.CreateThreadNow(function()
[ script:renzu_shops] for shopname,v in pairs(data) do
[ script:renzu_shops] local select = MySQL.query.await('SELECT * FROM renzu_stores WHERE shop = ?', {shopname})
[ script:renzu_shops] if select then
[ script:renzu_shops] for k,v in pairs(v) do
[ script:renzu_shops] if type(v) == 'table' then
[ script:renzu_shops] self.update('renzu_stores',k,'shop',shopname,json.encode(v))
[ script:renzu_shops] else
[ script:renzu_shops] self.update('renzu_stores',k,'shop',shopname,v)
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] else
[ script:renzu_shops] self.insert('renzu_stores',{
[ script:renzu_shops] shopname,
[ script:renzu_shops] v.owner,
[ script:renzu_shops] json.encode(v['money'] or {}),
[ script:renzu_shops] json.encode(v['items'] or {}),
[ script:renzu_shops] json.encode(v['employee'] or {}),
[ script:renzu_shops] json.encode(v['cashier'] or {}),
[ script:renzu_shops] json.encode(v['customitems'] or {}),
[ script:renzu_shops] v['job'],
[ script:renzu_shops] })
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] end)
[ script:renzu_shops] end
[ script:renzu_shops] return self
[ script:renzu_shops] end
[ script:renzu_shops] })
[ script:renzu_shops] local Sql = db()
[ script:renzu_shops]
[ script:renzu_shops] local success, result = pcall(MySQL.scalar.await, 'SELECT 1 FROM renzu_stores')
[ script:renzu_shops]
[ script:renzu_shops] if not success then
[ script:renzu_shops] MySQL.query([[CREATE TABLE renzu_stores (
[ script:renzu_shops] id int NOT NULL AUTO_INCREMENT KEY,
[ script:renzu_shops] shop varchar(60) DEFAULT NULL,
[ script:renzu_shops] owner varchar(64) DEFAULT NULL,
[ script:renzu_shops] money longtext DEFAULT NULL,
[ script:renzu_shops] items longtext DEFAULT NULL,
[ script:renzu_shops] employee longtext DEFAULT NULL,
[ script:renzu_shops] cashier longtext DEFAULT NULL,
[ script:renzu_shops] customitems longtext DEFAULT NULL,
[ script:renzu_shops] job varchar(64) DEFAULT NULL
[ script:renzu_shops] )]])
[ script:renzu_shops] end
[ script:renzu_shops] local success, result = pcall(MySQL.scalar.await, 'SELECT 1 FROM movableshops')
[ script:renzu_shops]
[ script:renzu_shops] if not success then
[ script:renzu_shops] MySQL.query([[CREATE TABLE movableshops (
[ script:renzu_shops] identifier varchar(64) DEFAULT NULL,
[ script:renzu_shops] owner varchar(64) DEFAULT NULL,
[ script:renzu_shops] money longtext DEFAULT NULL,
[ script:renzu_shops] items longtext DEFAULT NULL,
[ script:renzu_shops] plate varchar(64) DEFAULT NULL,
[ script:renzu_shops] type varchar(64) DEFAULT NULL,
[ script:renzu_shops] shopname varchar(64) DEFAULT NULL,
[ script:renzu_shops] UNIQUE KEY identifier (identifier)
[ script:renzu_shops] )]])
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] local success, result = pcall(MySQL.scalar.await, 'SELECT 1 FROM financedata')
[ script:renzu_shops]
[ script:renzu_shops] if not success then
[ script:renzu_shops] MySQL.query([[CREATE TABLE financedata (
[ script:renzu_shops] identifier varchar(64) DEFAULT NULL,
[ script:renzu_shops] max INT(64) DEFAULT NULL,
[ script:renzu_shops] financed longtext DEFAULT NULL,
[ script:renzu_shops] UNIQUE KEY identifier (identifier)
[ script:renzu_shops] )]])
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] local success, result = pcall(MySQL.scalar.await, 'ALTER TABLE movableshops MODIFY COLUMN identifier VARCHAR(100)')
[ script:renzu_shops]
[ script:renzu_shops] local convert = function()
[ script:renzu_shops] if GetResourceKvpString('renzu_stores') then
[ script:renzu_shops] for k,v in pairs(json.decode(GetResourceKvpString('renzu_stores'))) do
[ script:renzu_shops] local columns = {}
[ script:renzu_shops] columns['shop'] = k
[ script:renzu_shops] local data = {}
[ script:renzu_shops] for k,v in pairs(v) do
[ script:renzu_shops] columns[k] = v
[ script:renzu_shops] end
[ script:renzu_shops] Sql.insert('renzu_stores',{
[ script:renzu_shops] columns['shop'],
[ script:renzu_shops] columns['owner'],
[ script:renzu_shops] json.encode(columns['money'] or {}),
[ script:renzu_shops] json.encode(columns['items'] or {}),
[ script:renzu_shops] json.encode(columns['employee'] or {}),
[ script:renzu_shops] json.encode(columns['cashier'] or {}),
[ script:renzu_shops] json.encode(columns['customitems'] or {}),
[ script:renzu_shops] columns['job'],
[ script:renzu_shops] })
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] if GetResourceKvpString('movableshops') then
[ script:renzu_shops] for k,v in pairs(json.decode(GetResourceKvpString('movableshops'))) do
[ script:renzu_shops] local columns = {}
[ script:renzu_shops] columns['shopidentifier'] = k
[ script:renzu_shops] local data = {}
[ script:renzu_shops] for k,v in pairs(v) do
[ script:renzu_shops] columns[k] = v
[ script:renzu_shops] end
[ script:renzu_shops] Sql.insert('movableshops',{
[ script:renzu_shops] columns['shopidentifier'],
[ script:renzu_shops] columns['identifier'],
[ script:renzu_shops] json.encode(columns['money'] or {}),
[ script:renzu_shops] json.encode(columns['items'] or {}),
[ script:renzu_shops] columns['plate'],
[ script:renzu_shops] columns['type'],
[ script:renzu_shops] columns['shopname'],
[ script:renzu_shops] })
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] if GetResourceKvpString('financedata') then
[ script:renzu_shops] for k,v in pairs(json.decode(GetResourceKvpString('financedata'))) do
[ script:renzu_shops] local columns = {}
[ script:renzu_shops] columns['identifier'] = k
[ script:renzu_shops] local data = {}
[ script:renzu_shops] for k,v in pairs(v) do
[ script:renzu_shops] columns[k] = v
[ script:renzu_shops] end
[ script:renzu_shops] Sql.insert('financedata',{
[ script:renzu_shops] columns['identifier'],
[ script:renzu_shops] tonumber(columns['max']),
[ script:renzu_shops] json.encode(columns['financed'] or {}),
[ script:renzu_shops] })
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] --DeleteResourceKvp('renzu_stores_convert')
[ script:renzu_shops] if not GetResourceKvpString('renzu_stores_convert') then
[ script:renzu_shops] convert()
[ script:renzu_shops] SetResourceKvp('renzu_stores_convert', 'true')
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] local Stores = {}
[ script:renzu_shops] for k,v in pairs(MySQL.query.await('SELECT * FROM renzu_stores', { }) or {}) do
[ script:renzu_shops] Stores[v.shop] = {}
[ script:renzu_shops] for column,data in pairs(v) do
[ script:renzu_shops] if string.find(data, '{') then
[ script:renzu_shops] Stores[v.shop][column] = json.decode(data)
[ script:renzu_shops] elseif data == '[]' then
[ script:renzu_shops] Stores[v.shop][column] = {}
[ script:renzu_shops] else
[ script:renzu_shops] Stores[v.shop][column] = data
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] local Movable = {}
[ script:renzu_shops] for k,v in pairs(MySQL.query.await('SELECT * FROM movableshops', { }) or {}) do
[ script:renzu_shops] Movable[v.identifier] = {}
[ script:renzu_shops] for column,data in pairs(v) do
[ script:renzu_shops] if string.find(data, '{') then
[ script:renzu_shops] Movable[v.identifier][column] = json.decode(data)
[ script:renzu_shops] elseif data == '[]' then
[ script:renzu_shops] Movable[v.identifier][column] = {}
[ script:renzu_shops] else
[ script:renzu_shops] Movable[v.identifier][column] = data
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] local Financed = {}
[ script:renzu_shops] for k,v in pairs(MySQL.query.await('SELECT * FROM financedata', { }) or {}) do
[ script:renzu_shops] Financed[v.identifier] = {}
[ script:renzu_shops] for column,data in pairs(v) do
[ script:renzu_shops] if string.find(data, '{') then
[ script:renzu_shops] Financed[v.identifier][column] = json.decode(data)
[ script:renzu_shops] elseif data == '[]' then
[ script:renzu_shops] Financed[v.identifier][column] = {}
[ script:renzu_shops] else
[ script:renzu_shops] Financed[v.identifier][column] = data
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops]
[ script:renzu_shops] for k,v in pairs(shared.OwnedShops) do
[ script:renzu_shops] local str = 'Stores
%s'
[ script:renzu_shops] for k,v in pairs(v) do
[ script:renzu_shops] GlobalState[str:format(v.label)] = nil
[ script:renzu_shops] end
[ script:renzu_shops] end
[ script:renzu_shops] AddStateBagChangeHandler("Stores", "global", function(bagName, key, value)
[ script:renzu_shops] Wait(0)
[ script:renzu_shops] if not value then return end
[ script:renzu_shops] for shop,data in pairs(value) do -- Split datas to dedicated bags to prevent byte size limits
[ script:renzu_shops] local str = 'Stores
%s'
[ script:renzu_shops] GlobalState[str:format(shop)] = data
[ script:renzu_shops] end
[ script:renzu_shops] end)
[ script:renzu_shops]
[ script:renzu_shops] GlobalState.Shipping = json.decode(GetResourceKvpString('shippingcompany') or '[]') or {}
[ script:renzu_shops] GlobalState.Stores = Stores
[ script:renzu_shops] GlobalState.MovableShops = Movable
[ script:renzu_shops] GlobalState.FinanceData = Financed
[ script:renzu_shops] GlobalState.JobShop = {}
[ script:renzu_shops] return Sql:201)
[ script:renzu_shops] > fn (@renzu_shops/server/main.lua:16)
[ script:renzu_shops] > (@oxmysql/dist/build.js:21810)
[ script:renzu_shops] > processTicksAndRejections (node:internal/process/task_queues:96)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant