Hi everyone,
I want to get a string from an sql table. I get it server side but i want it client side in a variable, i just dont know how to do it. Here’s my code:
server.lua
RegisterServerEvent('police:checkGrade')
AddEventHandler('police:checkGrade', function()
TriggerEvent("es:getPlayerFromId", source, function(user)
local identifier = user.getIdentifier()
MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier LIKE @identifier;", {['@identifier'] = identifier},
function(result)
if(result) then
gradepo = result[1].rank
print(gradepo) -- print "captain" and thats right
TriggerClientEvent('police:ReturnGrade', gradepo)
end
end)
end)
end)
RegisterServerEvent('print') -- just used to see what the client variable "grade" is
AddEventHandler('print', function(string)
print("-------------------------------------------------------")
print(string)
end)
client.lua
RegisterNetEvent('police:ReturnGrade')
AddEventHandler('police:ReturnGrade', function(gradepo)
grade = gradepo
TriggerServerEvent('print', gradepo)
end)
(...)
-- some code
(...)
function xxxx()
(...)
TriggerServerEvent('police:checkGrade')
Citizen.Wait(100)
TriggerServerEvent('print', grade) -- print nil :( i want it to print the real grade like "captain"
if(grade == "Captain") then
(...)
end
its like the RegisterNetEvent(‘police:ReturnGrade’) isn’t called. Maybe i use it wrong, maybe it can’t be used to return a global variable or maybe i write it at the wrong place. Can someone fix that please?