Skip to content

Commit

Permalink
Feat: Add support for multiple respawn points
Browse files Browse the repository at this point in the history
  • Loading branch information
Mycroft-Studios committed Mar 9, 2022
1 parent 6945bbd commit 3b9c069
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 18 additions & 6 deletions [esx_addons]/esx_ambulancejob/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ function StartDeathTimer()
end)
end

function GetClosestRespawnPoint()
local PlyCoords = GetEntityCoords(PlayerPedId())
local ClosestDist,ClosestHosptial, ClostestCoord = 10000, {}, nil

This comment has been minimized.

Copy link
@iSentrie

iSentrie Mar 10, 2022

Contributor

ClosestHosptial


for k,v in pairs(Config.RespawnPoints) do
local Distance = #(PlyCoords - vector3(v.coords.x, v.coords.y, v.coords.z))
if Distance <= ClosestDist then
ClosestDist = Distance
ClosestHosptial = v
ClostestCoord = vector3(v.coords.x, v.coords.y, v.coords.z)

This comment has been minimized.

Copy link
@iSentrie

iSentrie Mar 10, 2022

Contributor

ClostestCoord

end
end

return ClostestCoord, ClosestHosptial

This comment has been minimized.

Copy link
@iSentrie

iSentrie Mar 10, 2022

Contributor

ClostestCoord

jezz

end

function RemoveItemsAfterRPDeath()
TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)

Expand All @@ -301,14 +317,10 @@ function RemoveItemsAfterRPDeath()
end

ESX.TriggerServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function()
local formattedCoords = {
x = Config.RespawnPoint.coords.x,
y = Config.RespawnPoint.coords.y,
z = Config.RespawnPoint.coords.z
}
local RepspawnCoords, ClosestHosptial = GetClosestRespawnPoint()

ESX.SetPlayerData('loadout', {})
RespawnPed(PlayerPedId(), formattedCoords, Config.RespawnPoint.heading)
RespawnPed(PlayerPedId(), RepspawnCoords, ClosestHosptial.heading)

This comment has been minimized.

Copy link
@iSentrie

iSentrie Mar 10, 2022

Contributor

RepspawnCoords
ClosestHosptial


AnimpostfxStop('DeathFailOut')
DoScreenFadeIn(800)
Expand Down
5 changes: 3 additions & 2 deletions [esx_addons]/esx_ambulancejob/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ Config.EarlyRespawnFine = false
Config.EarlyRespawnFineAmount = 5000

Config.OxInventory = ESX.GetConfig().OxInventory

Config.RespawnPoint = {coords = vector3(341.0, -1397.3, 32.5), heading = 48.5}
Config.RespawnPoints = {
{coords = vector3(341.0, -1397.3, 32.5), heading = 48.5}
}

Config.Hospitals = {

Expand Down

0 comments on commit 3b9c069

Please sign in to comment.