diff --git a/client/damage/damage.lua b/client/damage/damage.lua index 5704a4d..7d2b710 100644 --- a/client/damage/damage.lua +++ b/client/damage/damage.lua @@ -56,7 +56,7 @@ local function findDamageCause() end end if detected then - TriggerServerEvent("hospital:server:SetWeaponDamage", CurrentDamageList) + lib.callback('qbx_medical:server:SetWeaponWounds', false, false, CurrentDamageList) end end @@ -173,7 +173,7 @@ local function checkDamage(ped, boneId, weapon, damageDone) applyImmediateEffects(ped, bone, weapon, damageDone) injureBodyPart(bone) - TriggerServerEvent('hospital:server:SyncInjuries', { + lib.callback('qbx_medical:server:syncInjuries', false, false,{ limbs = BodyParts, isBleeding = BleedLevel }) @@ -195,7 +195,7 @@ local function applyDamage(ped, damageDone, isArmorDamaged) if damageDone >= Config.HealthDamage then local isBodyHitOrWeakWeapon = checkBodyHitOrWeakWeapon(isArmorDamaged, bodypart, weapon) if isBodyHitOrWeakWeapon and isArmorDamaged then - TriggerServerEvent("hospital:server:SetArmor", GetPedArmour(ped)) + lib.callback('qbx_medical:server:setArmor', false, false, GetPedArmour(ped)) elseif not isBodyHitOrWeakWeapon and isDamagingEvent(damageDone, weapon) then checkDamage(ped, bone, weapon, damageDone) end diff --git a/client/laststand.lua b/client/laststand.lua index 0b3987c..a5e0a3e 100644 --- a/client/laststand.lua +++ b/client/laststand.lua @@ -25,7 +25,7 @@ function EndLastStand() TaskPlayAnim(ped, LastStandDict, "exit", 1.0, 8.0, -1, 1, -1, false, false, false) InLaststand = false LaststandTime = 0 - TriggerServerEvent("hospital:server:SetLaststandStatus", false) + TriggerServerEvent('qbx_medical:server:onPlayerLaststandEnd') end exports('endLastStandDeprecated', EndLastStand) @@ -82,5 +82,4 @@ function StartLastStand() countdownLastStand() end end) - TriggerServerEvent("hospital:server:SetLaststandStatus", true) end \ No newline at end of file diff --git a/client/load-unload.lua b/client/load-unload.lua index 261d054..f83616e 100644 --- a/client/load-unload.lua +++ b/client/load-unload.lua @@ -19,9 +19,6 @@ local function initDeathAndLastStand(metadata) AllowRespawn() elseif metadata.inlaststand then StartLastStand() - else - TriggerServerEvent("hospital:server:SetDeathStatus", false) - TriggerServerEvent("hospital:server:SetLaststandStatus", false) end end diff --git a/client/main.lua b/client/main.lua index 55b273f..db2047e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -179,7 +179,7 @@ function ResetMinorInjuries() BlackoutTimer = 0 end - TriggerServerEvent('hospital:server:SyncInjuries', { + lib.callback('qbx_medical:server:syncInjuries', false, false,{ limbs = BodyParts, isBleeding = BleedLevel }) @@ -205,13 +205,13 @@ function ResetAllInjuries() FadeOutTimer = 0 BlackoutTimer = 0 - TriggerServerEvent('hospital:server:SyncInjuries', { + lib.callback('qbx_medical:server:syncInjuries', false, false,{ limbs = BodyParts, isBleeding = BleedLevel }) CurrentDamageList = {} - TriggerServerEvent('hospital:server:SetWeaponDamage', CurrentDamageList) + lib.callback('qbx_medical:server:SetWeaponWounds', false, false, CurrentDamageList) SendBleedAlert() MakePedLimp() @@ -274,7 +274,7 @@ RegisterNetEvent('hospital:client:SetPain', function() bone = Config.Bones[40269] CreateInjury(BodyParts[bone], bone, 4) - TriggerServerEvent('hospital:server:SyncInjuries', { + lib.callback('qbx_medical:server:syncInjuries', false, false,{ limbs = BodyParts, isBleeding = BleedLevel }) @@ -293,8 +293,7 @@ RegisterNetEvent('hospital:client:HealInjuries', function(type) else ResetMinorInjuries() end - TriggerServerEvent("hospital:server:RestoreWeaponDamage") - + lib.callback('qbx_medical:server:clearWeaponWounds') exports.qbx_core:Notify(Lang:t('success.wounds_healed'), 'success') end) @@ -320,7 +319,7 @@ exports('getPatientStatus', getPatientStatus) ---Revives player, healing all injuries ---Intended to be called from client or server. -RegisterNetEvent('hospital:client:Revive', function() +RegisterNetEvent('qbx_medical:client:playerRevived', function() local ped = cache.ped if IsDead or InLaststand then @@ -331,7 +330,6 @@ RegisterNetEvent('hospital:client:Revive', function() EndLastStand() end - TriggerServerEvent("hospital:server:RestoreWeaponDamage") SetEntityMaxHealth(ped, 200) SetEntityHealth(ped, 200) ClearPedBloodDamage(ped) @@ -339,7 +337,5 @@ RegisterNetEvent('hospital:client:Revive', function() ResetAllInjuries() ResetPedMovementClipset(ped, 0.0) TriggerServerEvent('hud:server:RelieveStress', 100) - TriggerServerEvent("hospital:server:SetDeathStatus", false) - TriggerServerEvent("hospital:server:SetLaststandStatus", false) exports.qbx_core:Notify(Lang:t('info.healthy'), 'inform') end) diff --git a/server/main.lua b/server/main.lua index 65b527e..b797cce 100644 --- a/server/main.lua +++ b/server/main.lua @@ -11,21 +11,25 @@ local playerWeaponWounds = {} local triggerEventHooks = require 'modules.hooks.server' ---@param data number[] weapon hashes -RegisterNetEvent('hospital:server:SetWeaponDamage', function(data) - if GetInvokingResource() then return end - local src = source - local player = exports.qbx_core:GetPlayer(src) - if not player then return end - playerWeaponWounds[player.PlayerData.source] = data +lib.callback.register('qbx_medical:server:setWeaponWounds', function(source, data) + playerWeaponWounds[source] = data end) -RegisterNetEvent('hospital:server:RestoreWeaponDamage', function() - if GetInvokingResource() then return end - local src = source - local player = exports.qbx_core:GetPlayer(src) - playerWeaponWounds[player.PlayerData.source] = nil +lib.callback.register('qbx_medical:server:clearWeaponWounds', function(source) + playerWeaponWounds[source] = nil end) +---@param player table|number +local function revivePlayer(player) + if type(player) == "number" then + player = exports.qbx_core:GetPlayer(player) + end + player.Functions.SetMetaData("isdead", false) + player.Functions.SetMetaData("inlaststand", false) + playerWeaponWounds[source] = nil + TriggerClientEvent('qbx_medical:client:playerRevived', player.PlayerData.source) +end + ---Compatibility with txAdmin Menu's heal options. ---This is an admin only server side event that will pass the target player id or -1. ---@class EventData @@ -36,15 +40,13 @@ AddEventHandler('txAdmin:events:healedPlayer', function(eventData) return end - TriggerClientEvent('hospital:client:Revive', eventData.id) + revivePlayer(eventData.id) TriggerClientEvent("hospital:client:HealInjuries", eventData.id, "full") end) ---@param data PlayerStatus -RegisterNetEvent('hospital:server:SyncInjuries', function(data) - if GetInvokingResource() then return end - local src = source - playerStatus[src] = data +lib.callback.register('qbx_medical:server:syncInjuries', function(source, data) + playerStatus[source] = data end) ---@param limbs BodyParts @@ -88,38 +90,29 @@ lib.callback.register('hospital:GetPlayerStatus', function(_, playerId) return damage end) ----@param isDead boolean -RegisterNetEvent('hospital:server:SetDeathStatus', function(isDead) +RegisterNetEvent('qbx_medical:server:playerDied', function() if GetInvokingResource() then return end local src = source local player = exports.qbx_core:GetPlayer(src) if not player then return end - player.Functions.SetMetaData("isdead", isDead) + player.Functions.SetMetaData("isdead", true) end) -RegisterNetEvent('qbx_medical:server:playerDied', function() +RegisterNetEvent('qbx_medical:server:onPlayerLaststand', function() if GetInvokingResource() then return end - local src = source - local player = exports.qbx_core:GetPlayer(src) - if not player then return end - player.Functions.SetMetaData("isdead", true) + local player = exports.qbx_core:GetPlayer(source) + player.Functions.SetMetaData("inlaststand", true) end) ----@param bool boolean -RegisterNetEvent('hospital:server:SetLaststandStatus', function(bool) +RegisterNetEvent('qbx_medical:server:onPlayerLaststandEnd', function() if GetInvokingResource() then return end - local src = source - local player = exports.qbx_core:GetPlayer(src) - if not player then return end - player.Functions.SetMetaData("inlaststand", bool) + local player = exports.qbx_core:GetPlayer(source) + player.Functions.SetMetaData("inlaststand", false) end) ---@param amount number -RegisterNetEvent('hospital:server:SetArmor', function(amount) - if GetInvokingResource() then return end - local src = source - local player = exports.qbx_core:GetPlayer(src) - if not player then return end +lib.callback('qbx_medical:server:setArmor', function(source, amount) + local player = exports.qbx_core:GetPlayer(source) player.Functions.SetMetaData("armor", amount) end) @@ -162,7 +155,13 @@ lib.addCommand('revive', { { name = 'id', help = Lang:t('info.player_id'), type = 'playerId', optional = true }, } }, function(source, args) - triggerEventOnPlayer(source, 'hospital:client:Revive', args.id) + if not args.id then args.id = source end + local player = exports.qbx_core:GetPlayer(tonumber(args.id)) + if not player then + TriggerClientEvent('ox_lib:notify', source, { description = Lang:t('error.not_online'), type = 'error' }) + return + end + revivePlayer(args.id) end) lib.addCommand('setpain', {