diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/client/damage/damage.lua b/client/damage/damage.lua index dc8d402..9b41d8c 100644 --- a/client/damage/damage.lua +++ b/client/damage/damage.lua @@ -165,7 +165,7 @@ local function applyDamage(ped, damageDone, isArmorDamaged) if damageDone >= config.healthDamage then local isBodyHitOrWeakWeapon = checkBodyHitOrWeakWeapon(isArmorDamaged, bodypart, weaponClass) if isBodyHitOrWeakWeapon and isArmorDamaged then - lib.callback('qbx_medical:server:setArmor', false, false, GetPedArmour(ped)) + lib.callback.await('qbx_medical:server:setArmor', false, GetPedArmour(ped)) elseif not isBodyHitOrWeakWeapon and isDamagingEvent(damageDone, weaponClass) then checkDamage(ped, bone, weaponHash, weaponClass, damageDone) end diff --git a/client/dead.lua b/client/dead.lua index 85e7c15..d974559 100644 --- a/client/dead.lua +++ b/client/dead.lua @@ -1,6 +1,7 @@ +local config = require 'config.client' local sharedConfig = require 'config.shared' local WEAPONS = exports.qbx_core:GetWeapons() -local allowRespawn = false +local allowRespawn = true local function playDeadAnimation() local deadAnimDict = 'dead' @@ -23,7 +24,6 @@ exports('PlayDeadAnimation', playDeadAnimation) ---put player in death animation and make invincible function OnDeath() - if DeathState == sharedConfig.deathState.DEAD then return end SetDeathState(sharedConfig.deathState.DEAD) TriggerEvent('qbx_medical:client:onPlayerDied') TriggerServerEvent('qbx_medical:server:onPlayerDied') @@ -38,11 +38,13 @@ function OnDeath() Wait(0) end end) + LocalPlayer.state.invBusy = true ResurrectPlayer() playDeadAnimation() SetEntityInvincible(cache.ped, true) SetEntityHealth(cache.ped, GetEntityMaxHealth(cache.ped)) + CheckForRespawn() end exports('KillPlayer', OnDeath) @@ -50,36 +52,43 @@ exports('KillPlayer', OnDeath) local function respawn() local success = lib.callback.await('qbx_medical:server:respawn') if not success then return end - if exports.qbx_policejob:IsHandcuffed() then + if QBX.PlayerData.metadata.ishandcuffed then TriggerEvent('police:client:GetCuffed', -1) end TriggerEvent('police:client:DeEscort') + LocalPlayer.state.invBusy = false end ---Allow player to respawn -function AllowRespawn() - allowRespawn = true +function CheckForRespawn() RespawnHoldTime = 5 while DeathState == sharedConfig.deathState.DEAD do - Wait(1000) + if IsControlPressed(0, 38) and RespawnHoldTime <= 1 and allowRespawn then + respawn() + return + end + if IsControlPressed(0, 38) then + RespawnHoldTime -= 1 + end + if IsControlReleased(0, 38) then + RespawnHoldTime = 5 + end + if RespawnHoldTime <= 0 then + RespawnHoldTime = 0 + end DeathTime -= 1 - if DeathTime <= 0 then - if IsControlPressed(0, 38) and RespawnHoldTime <= 1 and allowRespawn then - respawn() - end - if IsControlPressed(0, 38) then - RespawnHoldTime -= 1 - end - if IsControlReleased(0, 38) then - RespawnHoldTime = 5 - end - if RespawnHoldTime <= 1 then - RespawnHoldTime = 0 - end + if DeathTime <= 0 and allowRespawn then + respawn() + return end + Wait(1000) end end +function AllowRespawn() + allowRespawn = true +end + exports('AllowRespawn', AllowRespawn) exports('DisableRespawn', function() @@ -95,8 +104,8 @@ local function logDeath(victim, attacker, weapon) local playerName = (' %s (%d)'):format(GetPlayerName(playerId), GetPlayerServerId(playerId)) or Lang:t('info.self_death') local killerId = NetworkGetPlayerIndexFromPed(attacker) 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 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:log', false, 'logDeath', message) @@ -110,13 +119,13 @@ AddEventHandler('gameEventTriggered', function(event, data) local victim, attacker, victimDied, weapon = data[1], data[2], data[4], data[7] if not IsEntityAPed(victim) or not victimDied or NetworkGetPlayerIndexFromPed(victim) ~= cache.playerId or not IsEntityDead(cache.ped) then return end if DeathState == sharedConfig.deathState.ALIVE then + Wait(1000) StartLastStand() elseif DeathState == sharedConfig.deathState.LAST_STAND then EndLastStand() logDeath(victim, attacker, weapon) - DeathTime = 0 + DeathTime = config.deathTime OnDeath() - AllowRespawn() end end) diff --git a/client/laststand.lua b/client/laststand.lua index c8aafef..f00b7bd 100644 --- a/client/laststand.lua +++ b/client/laststand.lua @@ -5,7 +5,9 @@ local WEAPONS = exports.qbx_core:GetWeapons() ---blocks until ped is no longer moving function WaitForPlayerToStopMoving() local timeOut = 10000 - while GetEntitySpeed(cache.ped) > 1.0 or IsPedRagdoll(cache.ped) and timeOut > 1 do timeOut -= 10 Wait(10) end + while GetEntitySpeed(cache.ped) > 0.1 and IsPedRagdoll(cache.ped) and timeOut > 1 do + timeOut -= 10 Wait(10) + end end --- low level GTA resurrection @@ -52,22 +54,19 @@ local function countdownLastStand() exports.qbx_core:Notify(Lang:t('error.bled_out'), 'error') EndLastStand() logPlayerKiller() - DeathTime = 0 + DeathTime = config.deathTime OnDeath() - AllowRespawn() end end ---put player in last stand mode and notify EMS. function StartLastStand() - Wait(1000) TriggerEvent('ox_inventory:disarm', cache.playerId, true) WaitForPlayerToStopMoving() TriggerServerEvent('InteractSound_SV:PlayOnSource', 'demo', 0.1) LaststandTime = config.laststandReviveInterval ResurrectPlayer() SetEntityHealth(cache.ped, 150) - PlayUnescortedLastStandAnimation() SetDeathState(sharedConfig.deathState.LAST_STAND) TriggerEvent('qbx_medical:client:onPlayerLaststand') TriggerServerEvent('qbx_medical:server:onPlayerLaststand') @@ -81,7 +80,10 @@ function StartLastStand() CreateThread(function() while DeathState == sharedConfig.deathState.LAST_STAND do DisableControls() + PlayLastStandAnimation() Wait(0) end end) end + +exports('StartLastStand', StartLastStand) \ No newline at end of file diff --git a/client/load-unload.lua b/client/load-unload.lua index 945c62f..7e25253 100644 --- a/client/load-unload.lua +++ b/client/load-unload.lua @@ -16,9 +16,8 @@ end ---@param metadata any local function initDeathAndLastStand(metadata) if metadata.isdead then - DeathTime = config.laststandReviveInterval + DeathTime = config.deathTime OnDeath() - AllowRespawn() elseif metadata.inlaststand then StartLastStand() end diff --git a/client/main.lua b/client/main.lua index d893323..b94e744 100644 --- a/client/main.lua +++ b/client/main.lua @@ -41,6 +41,7 @@ end) function SetDeathState(deathState) playerState:set(DEATH_STATE_STATE_BAG, deathState, true) + DeathState = deathState end BleedTickTimer, AdvanceBleedTimer = 0, 0 @@ -59,7 +60,7 @@ exports('IsDead', function() return DeathState == sharedConfig.deathState.DEAD end) -exports('GetLaststand', function() +exports('IsLaststand', function() return DeathState == sharedConfig.deathState.LAST_STAND end) @@ -71,6 +72,14 @@ exports('GetLaststandTime', function() return LaststandTime end) +exports('IncrementDeathTime', function(seconds) + DeathTime += seconds +end) + +exports('IncrementLaststandTime', function(seconds) + LaststandTime += seconds +end) + exports('GetRespawnHoldTimeDeprecated', function() return RespawnHoldTime end) @@ -158,7 +167,7 @@ local function resetAllInjuries() SendBleedAlert() MakePedLimp() doLimbAlert() - lib.callback('qbx_medical:server:resetHungerAndThirst') + lib.callback.await('qbx_medical:server:resetHungerAndThirst') end ---notify the player of bleeding to their body. @@ -218,4 +227,5 @@ RegisterNetEvent('qbx_medical:client:playerRevived', function() ResetPedMovementClipset(cache.ped, 0.0) TriggerServerEvent('hud:server:RelieveStress', 100) exports.qbx_core:Notify(Lang:t('info.healthy'), 'inform') + LocalPlayer.state.invBusy = false end) diff --git a/client/setdownedstate.lua b/client/setdownedstate.lua index ba02b3d..6f936fc 100644 --- a/client/setdownedstate.lua +++ b/client/setdownedstate.lua @@ -4,7 +4,7 @@ local vehicleAnim = 'sit' local LastStandCuffedDict = 'dead' local LastStandCuffedAnim = 'dead_f' -function PlayUnescortedLastStandAnimation() +local function playUnescortedLastStandAnimation() if cache.vehicle then lib.requestAnimDict(vehicleDict, 5000) if not IsEntityPlayingAnim(cache.ped, vehicleDict, vehicleAnim, 3) then @@ -37,16 +37,14 @@ local function playEscortedLastStandAnimation(ped) end end -local function playLastStandAnimation() +function PlayLastStandAnimation() if isEscorted then playEscortedLastStandAnimation(cache.ped) else - PlayUnescortedLastStandAnimation() + playUnescortedLastStandAnimation() end end -exports('PlayLastStandAnimationDeprecated', playLastStandAnimation) - ---@param bool boolean ---TODO: this event name should be changed within qb-policejob to be generic AddEventHandler('hospital:client:isEscorted', function(bool) diff --git a/config/client.lua b/config/client.lua index 6f90175..556ee8c 100644 --- a/config/client.lua +++ b/config/client.lua @@ -36,6 +36,7 @@ return { walking = 15, }, laststandReviveInterval = 360, + deathTime = 300, forceInjury = 35, -- Maximum amount of damage a player can take before limb damage & effects are forced to occur healthDamage = 5, -- Minimum damage done to health before checking for injuries diff --git a/server/main.lua b/server/main.lua index 885318b..c220c70 100644 --- a/server/main.lua +++ b/server/main.lua @@ -50,7 +50,7 @@ exports('Revive', revivePlayer) ---removes all ailments, sets to full health, and fills up hunger and thirst. ---@param src Source local function heal(src) - lib.callback('qbx_medical:client:heal', src, false, 'full') + lib.callback.await('qbx_medical:client:heal', src, 'full') end exports('Heal', heal) @@ -58,7 +58,7 @@ exports('Heal', heal) ---Removes any injuries with severity 2 or lower. Stops bleeding if bleed level is less than 3. ---@param src Source local function healPartially(src) - lib.callback('qbx_medical:client:heal', src, false, 'partial') + lib.callback.await('qbx_medical:client:heal', src, 'partial') end exports('HealPartially', healPartially) @@ -162,7 +162,7 @@ lib.addCommand('kill', { exports.qbx_core:Notify(source, Lang:t('error.not_online'), 'error') return end - lib.callback('qbx_medical:client:killPlayer', args.id) + lib.callback.await('qbx_medical:client:killPlayer', args.id) end) lib.addCommand('aheal', {