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

tweak(respawnAtHospital): Adding closest bed check #60

Merged
merged 1 commit into from
Jul 23, 2023
Merged
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
11 changes: 6 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
---@param player Player
---@param bedsKey "beds"|"jailbeds"
---@param i integer
---@param bed Bed
---@param bed table Bed
local function respawnAtBed(player, bedsKey, i, bed)
TriggerClientEvent('hospital:client:SendToBed', player.PlayerData.source, i, bed, true)
TriggerClientEvent('hospital:client:SetBed', -1, bedsKey, i, true)
Expand All @@ -36,13 +36,14 @@ end
---@param bedsKey "beds"|"jailbeds"
local function respawnAtHospital(player, bedsKey)
local beds = Config.Locations[bedsKey]
local closest, bedIndex = nil, 0
for i, bed in pairs(beds) do
if not bed.taken then
respawnAtBed(player, bedsKey, i, bed)
return
if (not closest or closest > #(GetEntityCoords(cache.ped) - bed.coords)) and not bed.taken then
closest = #(GetEntityCoords(cache.ped) - bed.coords)
bedIndex = i
end
end
respawnAtBed(player, bedsKey)
respawnAtBed(player, bedsKey, bedIndex, beds[bedIndex])
end

RegisterNetEvent('hospital:server:RespawnAtHospital', function()
Expand Down
Loading