Skip to content

Commit

Permalink
add annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenshiin13 committed Nov 14, 2024
1 parent b477665 commit 53e8df2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
---@param src number
---@param xPlayer table
AddEventHandler('esx:playerLoaded', function(src, xPlayer)
local status = MySQL.scalar.await('SELECT `status` FROM `users` WHERE `identifier` = ? LIMIT 1', { xPlayer.getIdentifier() })

status = status and json.decode(status) or {}
xPlayer.set('status', status)

TriggerClientEvent('esx_status:load', xPlayer.source, status)
end)

---@param src number
---@param reason string
AddEventHandler('esx:playerDropped', function(src, reason)
local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then
return
end
local status = xPlayer.get('status') or {}

local status = xPlayer.get('status') or {}
MySQL.update('UPDATE users SET status = ? WHERE identifier = ?', { json.encode(status), xPlayer.getIdentifier() })
end)

---@param src number
---@param statusName string
---@param cb function|table
AddEventHandler('esx_status:getStatus', function(src, statusName, cb)
local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then
return
end

local status = xPlayer.get('status') or {}
for i = 1, #status do
if status[i].name == statusName then
Expand All @@ -29,6 +38,7 @@ AddEventHandler('esx_status:getStatus', function(src, statusName, cb)
end
end)

---@param status table
RegisterNetEvent('esx_status:update', function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then
Expand Down

0 comments on commit 53e8df2

Please sign in to comment.