Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: miscl fixes #90

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 1 addition & 1 deletion client/damage/damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Manason marked this conversation as resolved.
Show resolved Hide resolved
elseif not isBodyHitOrWeakWeapon and isDamagingEvent(damageDone, weaponClass) then
checkDamage(ped, bone, weaponHash, weaponClass, damageDone)
end
Expand Down
55 changes: 32 additions & 23 deletions client/dead.lua
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')
Expand All @@ -38,48 +38,57 @@ 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)

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()
Expand All @@ -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)
Expand All @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions client/laststand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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)
3 changes: 1 addition & 2 deletions client/load-unload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ end)

function SetDeathState(deathState)
playerState:set(DEATH_STATE_STATE_BAG, deathState, true)
DeathState = deathState
end

BleedTickTimer, AdvanceBleedTimer = 0, 0
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
8 changes: 3 additions & 5 deletions client/setdownedstate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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')
Manason marked this conversation as resolved.
Show resolved Hide resolved
end

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')
Manason marked this conversation as resolved.
Show resolved Hide resolved
end

exports('HealPartially', healPartially)
Expand Down Expand Up @@ -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)
Manason marked this conversation as resolved.
Show resolved Hide resolved
end)

lib.addCommand('aheal', {
Expand Down