Hello
I have a problem with creating a login and registration when a player enters the server I do not know how to create a check and under which event to connect to check if the player is in the database and if it is not to show him registration, or someone is able to me in somehow present or lead a good direction?
hard to help without reviewing any code
function WczytajGracza(source, callback)
local identifier = GetPlayerIdentifiers(source)[1]
MySQL.Async.fetchAll("SELECT * FROM `needrp_postacie` WHERE `p_hex` = @identifier",
{
['@identifier'] = identifier
},
function(result)
if result[1]['p_hex'] ~= nil then
local data = {
id = result[1]['p_id'],
identifier = result[1]['p_hex'],
firstname = result[1]['p_firstname'],
lastname = result[1]['p_lastname'],
dateofbirth = result[1]['p_dateofbirth'],
sex = result[1]['p_sex'],
height = result[1]['p_height'],
money = result[1]['p_money'],
bankmoney = result[1]['p_bankmoney'],
spawn = result[1]['p_spawn']
}
callback(data)
else
local data = {
identifier = '',
firstname = '',
lastname = '',
dateofbirth = '',
sex = '',
height = '',
money = '',
bankmoney = '',
spawn = ''
}
callback(data)
end
end)
end
AddEventHandler('playerConnecting', function(playerName, setKickReason)
WczytajGracza(source, function(data)
if data.p_hex ~= nil then
print('Nie znaleziono ')
else
print('znaleziono gracza ' .. data.firstname .. ' ' .. data.lastname)
end
end)
print('ss')
end)
Error running call reference function for resource mymode: citizen:/scripting/lua/scheduler.lua:403: mymode_server.lua:10: attempt to index a nil value (field ‘?’)
stack traceback:
mymode_server.lua:10: in upvalue ‘ref’
citizen:/scripting/lua/scheduler.lua:389: in function citizen:/scripting/lua/scheduler.lua:388
[C]: in function ‘xpcall’
citizen:/scripting/lua/scheduler.lua:388: in function citizen:/scripting/lua/scheduler.lua:387
stack traceback:
[C]: in function ‘error’
citizen:/scripting/lua/scheduler.lua:403: in function citizen:/scripting/lua/scheduler.lua:372
Error: Unhandled error: Error: BUFFER_SHORTAGE
Error: BUFFER_SHORTAGE
at n.e [as reserve] (citizen:/scripting/v8/msgpack.js:29:12766)
at h (citizen:/scripting/v8/msgpack.js:29:15761)
at n.r [as decode] (citizen:/scripting/v8/msgpack.js:29:13908)
at n.fetch (citizen:/scripting/v8/msgpack.js:29:6972)
at n.u [as read] (citizen:/scripting/v8/msgpack.js:29:12076)
at Object.n [as decode] (citizen:/scripting/v8/msgpack.js:29:7097)
at unpack (citizen:/scripting/v8/main.js:20:33)
at citizen:/scripting/v8/main.js:51:11
at setImmediate (mysql-async.js:4962:9)
at Object.callback (citizen:/scripting/v8/timer.js:56:6)
you are trying to index a empty table, that is what the error says
How can I do it differently or make it work?
function WczytajGracza(source, callback)
local pName = GetPlayerName(source)
MySQL.Async.fetchAll("SELECT p_id FROM `needrp_postacie` WHERE `p_name` = @pName",
{
['@pName'] = pName
},
function(result)
if result[1]['p_name'] ~= nil then
local jest = true
callback(jest)
else
local jest = false
callback(jest)
end
end)
end
AddEventHandler('playerConnecting', function(playerName, setKickReason)
WczytajGracza(source, function(jest)
if jest then
print(' znaleziono ')
else
print('Nie znaleziono gracza ')
end
end)
print('ss')
end)
and the same error…
AddEventHandler('playerConnecting', function(playerName, setKickReason)
local pName = GetPlayerName(source)
print(pName)
MySQL.Async.fetchAll("SELECT * FROM `needrp_postacie` WHERE `p_name` = @pName",
{
['@pName'] = pName
},
function(result)
print(#result)
if result then
print('Nie Znaleziono gracza')
else
print('Znaleziono gracza')
end
end)
end)
Ok no errors is good!
result return to me 1 if player exist or 0 if player no exist in base, but this code not working