From 0394f002a6ca4a74b99b723f0dd9a908134cb161 Mon Sep 17 00:00:00 2001 From: SamuraiDevCo <160781327+SamuraiDevCo@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:36:17 -0700 Subject: [PATCH 1/3] Added Option For Closest Hospital Respawn Add the configuration option to allow for respawning at the closest hospital listed in the config. --- client/main.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/main.lua b/client/main.lua index 4f45152..64711f7 100644 --- a/client/main.lua +++ b/client/main.lua @@ -638,6 +638,23 @@ end) RegisterNetEvent('hospital:client:RespawnAtHospital', function() local hospitalIndex = 1 -- Default hospital to respawn at + if Config.RespawnAtNearestHospital and #Config.Locations["hospital"] > 0 then + local closestH = nil + local minDist = nil + for i=1, #Config.Locations["hospital"] do + if closestH then + local newDist = Vdist(Config.Locations["hospital"][i]["location"].x, Config.Locations["hospital"][i]["location"].y, Config.Locations["hospital"][i]["location"].z, GetEntityCoords(PlayerPedId())) + if newDist < minDist then + closestH = i + minDist = newDist + end + else + closestH = i + minDist = Vdist(Config.Locations["hospital"][i]["location"].x, Config.Locations["hospital"][i]["location"].y, Config.Locations["hospital"][i]["location"].z, GetEntityCoords(PlayerPedId())) + end + end + hospitalIndex = closestH + end TriggerServerEvent('hospital:server:RespawnAtHospital', hospitalIndex) if exports['qb-policejob']:IsHandcuffed() then TriggerEvent('police:client:GetCuffed', -1) From fd9616fe24fab156ec7fa6afa0a4cac8cc222a10 Mon Sep 17 00:00:00 2001 From: SamuraiDevCo <160781327+SamuraiDevCo@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:37:10 -0700 Subject: [PATCH 2/3] Added Option For Closest Hospital Respawn Added the option to respawn at the closest hospital --- config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/config.lua b/config.lua index a7a0b7d..b927bfd 100644 --- a/config.lua +++ b/config.lua @@ -3,6 +3,7 @@ Config.UseTarget = GetConvar('UseTarget', 'false') == 'true' -- Use qb-target in Config.MinimalDoctors = 2 -- How many players with the ambulance job to prevent the hospital check-in system from being used Config.DocCooldown = 1 -- Cooldown between doctor calls allowed, in minutes Config.WipeInventoryOnRespawn = true -- Enable or disable removing all the players items when they respawn at the hospital +Config.RespawnAtNearestHospital = true -- Enable or disable respawning at the closest hospital Config.Helicopter = 'polmav' -- Helicopter model that players with the ambulance job can use Config.BillCost = 2000 -- Price that players are charged for using the hospital check-in system Config.DeathTime = 300 -- How long the timer is for players to bleed out completely and respawn at the hospital From 0a0db20a2937b2fb21953af7bb64972d56b2c94f Mon Sep 17 00:00:00 2001 From: SamuraiDevCo <160781327+SamuraiDevCo@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:31:54 -0700 Subject: [PATCH 3/3] Update client/main.lua Co-authored-by: Zerio --- client/main.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/client/main.lua b/client/main.lua index 64711f7..0b22a28 100644 --- a/client/main.lua +++ b/client/main.lua @@ -639,21 +639,25 @@ end) RegisterNetEvent('hospital:client:RespawnAtHospital', function() local hospitalIndex = 1 -- Default hospital to respawn at if Config.RespawnAtNearestHospital and #Config.Locations["hospital"] > 0 then - local closestH = nil - local minDist = nil - for i=1, #Config.Locations["hospital"] do - if closestH then - local newDist = Vdist(Config.Locations["hospital"][i]["location"].x, Config.Locations["hospital"][i]["location"].y, Config.Locations["hospital"][i]["location"].z, GetEntityCoords(PlayerPedId())) - if newDist < minDist then - closestH = i - minDist = newDist + local closestHospital, lowestDist + local playerPed = PlayerPedId() + + if playerPed > 0 and DoesEntityExist(playerPed) then + local playerCoords = GetEntityCoords(playerPed) + + for i=1, #Config.Locations["hospital"] do + local dist = #(Config.Locations["hospital"][i]["location"] - playerCoords) + + if closestHospital == nil or dist < lowestDist then + closestHospital = i + lowestDist = dist end - else - closestH = i - minDist = Vdist(Config.Locations["hospital"][i]["location"].x, Config.Locations["hospital"][i]["location"].y, Config.Locations["hospital"][i]["location"].z, GetEntityCoords(PlayerPedId())) end end - hospitalIndex = closestH + + if closestHospital ~= nil then + hospitalIndex = closestHospital + end end TriggerServerEvent('hospital:server:RespawnAtHospital', hospitalIndex) if exports['qb-policejob']:IsHandcuffed() then