I’ve tried this a ton of ways but no matter what I try, GetPlayerWantedLevel returns 0. I first tried wrapping source in NetworkGetEntityFromNetworkId == argument at index 0 was nil and have tried NetToPed = nil. This is the only attempt that doesn’t end in an error but it’s clearly still written wrong.
AddEventHandler('playerDropped', function (reason)
_source = source
local wantedlevel = GetPlayerWantedLevel(_source)
print('Wantedlevel: ' .. wantedlevel)
local license = false
for k,v in pairs(GetPlayerIdentifiers(_source))do
if string.sub(v, 1, string.len("license:")) == "license:" then
license = v
end
end
Citizen.Wait(1000)
MySQL.Async.execute('UPDATE users SET wantedlevel = @wantedlevel WHERE identifier = @identifier', {
['@wantedlevel'] = wantedlevel,
['@identifier'] = license
}, function(result)
end)
end)
No matter what, that print for wantedlevel returns 0 on playerdropped while having 5 stars. I’ve also tried
What am I doing wrong that it doesn’t return actual wanted level on playerdropped?
As far as I am aware, you cannot fetch a player’s wanted level once they drop - because the client doesn’t exist any longer (they’ve disconnected from the server) and as a result - you don’t have that information at your disposal no more.
I would recommend storing the player’s wanted level server-side and updating it when needed (for example when the player’s wanted level increases/decreases). Once the player leaves, just reference the player’s ID and fetch it from the server
i did it in the script and it should refresh and update the wanted level from the server side …
i am still working on it and i waste big time hehehehe but still not working
That’s not the resource I gave you. You’re still trying to use the broken resource you had to start with. Mine is not called esx_wantedlevel_db. My resource is named esx_wantedlevel.