Skip to content

Commit

Permalink
refactor(logs): finish swapping over to ox logger (#77)
Browse files Browse the repository at this point in the history
* fix(logs): finish swapping over to ox logger

* fix: typo
  • Loading branch information
mafewtm authored Apr 6, 2024
1 parent 5571c7f commit 4a7e418
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions client/dead.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ end)
---@param weapon string weapon hash
local function logDeath(victim, attacker, weapon)
local playerId = NetworkGetPlayerIndexFromPed(victim)
local playerName = GetPlayerName(playerId) .. ' ' .. '(' .. GetPlayerServerId(playerId) .. ')' or Lang:t('info.self_death')
local playerName = (' %s (%d)'):format(GetPlayerName(playerId), GetPlayerServerId(playerId)) or Lang:t('info.self_death')
local killerId = NetworkGetPlayerIndexFromPed(attacker)
local killerName = GetPlayerName(killerId) .. ' ' .. '(' .. GetPlayerServerId(killerId) .. ')' or Lang:t('info.self_death')
local killerName = ('%s (%d)'):format(GetPlayerName(killerId), GetPlayerServerId(killerId)) or Lang:t('info.self_death')
local weaponLabel = WEAPONS[weapon].label or 'Unknown'
local weaponName = WEAPONS[weapon].name or 'Unknown'
local message = Lang:t('logs.death_log_message', { killername = killerName, playername = playerName, weaponlabel = weaponLabel, weaponname = weaponName })
lib.callback.await('qbx_medical:server:logDeath', false, message)

lib.callback.await('qbx_medical:server:log', false, 'logDeath', message)
end

---when player is killed by another player, set last stand mode, or if already in last stand mode, set player to dead mode.
Expand Down
20 changes: 11 additions & 9 deletions client/laststand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ end
local function logPlayerKiller()
local killer_2, killerWeapon = NetworkGetEntityKillerOfPlayer(cache.playerId)
local killer = GetPedSourceOfDeath(cache.ped)
if killer_2 ~= 0 and killer_2 ~= -1 then killer = killer_2 end

if killer_2 ~= 0 and killer_2 ~= -1 then
killer = killer_2
end

local killerId = NetworkGetPlayerIndexFromPed(killer)
local killerName = killerId ~= -1 and GetPlayerName(killerId) .. ' ' .. '(' .. GetPlayerServerId(killerId) .. ')' or Lang:t('info.self_death')
local weaponLabel = Lang:t('info.wep_unknown')
local weaponName = Lang:t('info.wep_unknown')
local killerName = killerId ~= -1 and (' %s (%d)'):format(GetPlayerName(killerId), GetPlayerServerId(killerId)) or Lang:t('info.self_death')
local weaponItem = WEAPONS[killerWeapon]
if weaponItem then
weaponLabel = weaponItem.label
weaponName = weaponItem.name
end
TriggerServerEvent('qb-log:server:CreateLog', 'death', Lang:t('logs.death_log_title', { playername = GetPlayerName(cache.playerId), playerid = GetPlayerServerId(cache.playerId) }), 'red', Lang:t('logs.death_log_message', { killername = killerName, playername = GetPlayerName(cache.playerId), weaponlabel = weaponLabel, weaponname = weaponName }))
local weaponLabel = Lang:t('info.wep_unknown') or (weaponItem and weaponItem.label)
local weaponName = Lang:t('info.wep_unknown') or (weaponItem and weaponItem.name)
local message = Lang:t('logs.death_log_message', { killername = killerName, playername = GetPlayerName(cache.playerId), weaponlabel = weaponLabel, weaponname = weaponName })

lib.callback.await('qbx_medical:server:log', false, 'playerKiller', message)
end

---count down last stand, if last stand is over, put player in death mode and log the killer.
Expand Down
4 changes: 2 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ lib.callback.register('qbx_medical:server:respawn', function(source)
return true
end)

lib.callback.register('qbx_medical:server:logDeath', function(_, message)
logger.log({source = 'qbx_medical', event = 'logDeath', message = message})
lib.callback.register('qbx_medical:server:log', function(_, event, message)
logger.log({source = 'qbx_medical', event = event, message = message})
end)

0 comments on commit 4a7e418

Please sign in to comment.