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

refactor: bpt_ambulancejob reconstruction to fix bugs found #947

Merged
merged 13 commits into from
Jan 11, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function GetShapeTestResultSync(shape)
local handle, hit, coords, normal, entity
repeat
handle, hit, coords, normal, entity = GetShapeTestResult(shape)
until handle ~= 1 or Wait(Sleep)
until handle ~= 1 or Wait(0)
return hit, coords, normal, entity
end

Expand All @@ -22,7 +22,7 @@ end

function EndDeathCam()
RenderScriptCams(false, false, 0, false, false)
camera = DestroyCam(camera)
DestroyCam(camera, false)
end

function ProcessCamControls()
Expand All @@ -34,7 +34,7 @@ function ProcessCamControls()
end

local coords = ProcessNewPosition(playerCoords)
SetCamCoord(camera, coords)
SetCamCoord(camera, coords.x, coords.y, coords.z)
PointCamAtCoord(camera, playerCoords.x, playerCoords.y, playerCoords.z)
end

Expand All @@ -48,6 +48,6 @@ function ProcessNewPosition(playerCoords)
end
local normal = vector3(math.sin(y) * math.cos(x), math.sin(y) * math.sin(x), math.cos(y))
local pos = playerCoords + normal * camera_radius
local hit, coords = GetShapeTestResultSync(StartShapeTestLosProbe(playerCoords, pos, -1, playerPed))
local hit, coords = GetShapeTestResultSync(StartShapeTestLosProbe(playerCoords, 0, -1, playerPed, 7, playerPed, 0, 7, 0))
return (hit == 1 and playerCoords + normal * (#(playerCoords - coords) - 1)) or pos
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local CurrentAction, CurrentActionMsg, CurrentActionData, billing = nil, "", {}, {}
---@diagnostic disable: undefined-global

local CurrentAction, CurrentActionMsg, CurrentActionData = nil, "", {}
local HasAlreadyEnteredMarker, LastHospital, LastPart, LastPartNum
local IsBusy, deadPlayers, deadPlayerBlips, isOnDuty = false, {}, {}, false
IsInShopMenu = false
Expand Down Expand Up @@ -27,7 +29,7 @@ function OpenAmbulanceActionsMenu()
if element.value == "cloakroom" then
OpenCloakroomMenu()
elseif element.value == "boss_actions" then
TriggerEvent("bpt_society:openBossMenu", "ambulance", function(data, menu)
TriggerEvent("bpt_society:openBossMenu", "ambulance", function()
menu.close()
end, { wash = false })
end
Expand All @@ -48,8 +50,8 @@ function OpenMobileAmbulanceActionsMenu()
{ icon = "fas fa-bandage", title = TranslateCap("ems_menu_small"), value = "small" },
{ icon = "fas fa-bandage", title = TranslateCap("ems_menu_big"), value = "big" },
{ icon = "fas fa-car", title = TranslateCap("ems_menu_putincar"), value = "put_in_vehicle" },
{ icon = "fas fa-syringe", title = TranslateCap("ems_menu_search"), value = "search" },
{ icon = "fas fa-syringe", title = TranslateCap("billing"), value = "billing" },
{ icon = "fas fa-search", title = TranslateCap("ems_menu_search"), value = "search" },
{ icon = "fas fa-money-bill", title = TranslateCap("billing"), value = "billing" },
}

ESX.OpenContext("right", elements2, function(menu2, element2)
Expand Down Expand Up @@ -126,29 +128,32 @@ function OpenMobileAmbulanceActionsMenu()
end)
end

-- billing
if billing == "billing" then
ESX.UI.Menu.Open("dialog", GetCurrentResourceName(), "billing", {
title = TranslateCap("invoice_amount"),
}, function(data, menu)
local amount = tonumber(data.value)
if amount == nil then
ESX.ShowNotification(TranslateCap("amount_invalid"))
if value == "billing" then
local elements2 = {
{ unselectable = true, icon = "fas fa-money-bill", title = TranslateCap("billing")},
{
title = TranslateCap("amount"),
input = true,
inputType = "number",
inputMin = 1,
inputMax = 10000000,
inputPlaceholder = TranslateCap("bill_amount"),
},
{ icon = "fas fa-check-double", title = TranslateCap("confirm"), value = "confirm" },
}
local amount = tonumber(menu2.eles[2].inputValue)
if amount == nil then
ESX.ShowNotification(TranslateCap("amount_invalid"))
else
ESX.CloseContext()
if closestPlayer == -1 or closestDistance > 3.0 then
ESX.ShowNotification(TranslateCap("no_players_near"))
else
menu.close()
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
if closestPlayer == -1 or closestDistance > 3.0 then
ESX.ShowNotification(TranslateCap("no_players_near"))
else
TriggerServerEvent("bpt_billing:sendBill", GetPlayerServerId(closestPlayer), "society_ambulance", "Ambulance", amount)
ESX.ShowNotification(TranslateCap("billing_sent"))
end
TriggerServerEvent("bpt_billing:sendBill", GetPlayerServerId(closestPlayer), "society_ballas", "Ballas", amount)
ESX.ShowNotification(TranslateCap("billing_sent"))
end
end, function(_, menu)
menu.close()
end)
end
end
-- end billing

function RevivePlayer(closestPlayer)
IsBusy = true
Expand All @@ -162,7 +167,7 @@ function RevivePlayer(closestPlayer)
local lib, anim = "mini@cpr@char_a@cpr_str", "cpr_pumpchest"
ESX.ShowNotification(TranslateCap("revive_inprogress"))

for i = 1, 15 do
for _ = 1, 15 do
Wait(900)

ESX.Streaming.RequestAnimDict(lib, function()
Expand All @@ -183,24 +188,6 @@ function RevivePlayer(closestPlayer)
end, "medikit")
end

function FastTravel(coords, heading)
local playerPed = PlayerPedId()

DoScreenFadeOut(800)

while not IsScreenFadedOut() do
Wait(500)
end

ESX.Game.Teleport(playerPed, coords, function()
DoScreenFadeIn(800)

if heading then
SetEntityHeading(playerPed, heading)
end
end)
end

-- Draw markers & Marker logic
CreateThread(function()
while true do
Expand Down Expand Up @@ -322,17 +309,16 @@ CreateThread(function()
CurrentAction = nil
end
end

local playerCoords, letSleep = GetEntityCoords(PlayerPedId()), true
GetEntityCoords(PlayerPedId())
Wait(sleep)
end
end)

RegisterCommand("ambulance", function(src)
RegisterCommand("ambulance", function()
if ESX.PlayerData.job and ESX.PlayerData.job.name == "ambulance" and not ESX.PlayerData.dead then
OpenMobileAmbulanceActionsMenu()
end
end)
end, false)

RegisterKeyMapping("ambulance", "Open Ambulance Actions Menu", "keyboard", "F6")

Expand Down Expand Up @@ -388,7 +374,8 @@ function OpenCloakroomMenu()
end

isOnDuty = true
ESX.TriggerServerCallback("bpt_ambulancejob:getDeadPlayers", function(_deadPlayers)
local _deadPlayers = deadPlayers
ESX.TriggerServerCallback("bpt_ambulancejob:getDeadPlayers", function()
TriggerEvent("bpt_ambulancejob:setDeadPlayers", _deadPlayers)
end)
if Config.Debug then
Expand Down Expand Up @@ -457,9 +444,7 @@ AddEventHandler("bpt_ambulancejob:PlayerNotDead", function(Player)
end)

RegisterNetEvent("bpt_ambulancejob:setDeadPlayers")
AddEventHandler("bpt_ambulancejob:setDeadPlayers", function(_deadPlayers)
deadPlayers = _deadPlayers

AddEventHandler("bpt_ambulancejob:setDeadPlayers", function()
if isOnDuty then
for playerId, v in pairs(deadPlayerBlips) do
RemoveBlip(v)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---@diagnostic disable: undefined-global
local firstSpawn = true
IsDead, IsSearched, Medic = false, false, 0
IsDead, IsSearched = false, false

RegisterNetEvent("esx:playerLoaded")
AddEventHandler("esx:playerLoaded", function(xPlayer)
Expand Down Expand Up @@ -38,8 +39,8 @@ end)

-- Create blips
CreateThread(function()
for k, v in pairs(Config.Hospitals) do
local blip = AddBlipForCoord(v.Blip.coords)
for _, v in pairs(Config.Hospitals) do
local blip = AddBlipForCoord(v.Blip.coords.x, v.Blip.coords.y, v.Blip.coords.z)

SetBlipSprite(blip, v.Blip.sprite)
SetBlipScale(blip, v.Blip.scale)
Expand Down Expand Up @@ -139,6 +140,7 @@ function StartDeathLoop()
ProcessCamControls()
if IsSearched then
local playerPed = PlayerPedId()
local medic = Medic or 0
local ped = GetPlayerPed(GetPlayerFromServerId(medic))
IsSearched = false

Expand Down Expand Up @@ -177,7 +179,7 @@ end

function SendDistressSignal()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
GetEntityCoords(playerPed)

ESX.ShowNotification(TranslateCap("distress_sent"))
TriggerServerEvent("bpt_ambulancejob:onPlayerDistress")
Expand All @@ -194,7 +196,7 @@ function DrawGenericTextThisFrame()
end

function SecondsToClock(seconds)
local seconds, hours, mins, secs = tonumber(seconds), 0, 0, 0
local seconds, hours, mins, secs = tonumber(seconds), 0, 0, 0

if seconds <= 0 then
return 0, 0
Expand Down Expand Up @@ -330,11 +332,11 @@ end

function RespawnPed(ped, coords, heading)
SetEntityCoordsNoOffset(ped, coords.x, coords.y, coords.z, false, false, false)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, heading, true, false)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, heading, 1, false)
SetPlayerInvincible(ped, false)
ClearPedBloodDamage(ped)

TriggerEvent("esx_basicneeds:resetStatus")
TriggerEvent("bpt_basicneeds:resetStatus")
TriggerServerEvent("esx:onPlayerSpawn")
TriggerEvent("esx:onPlayerSpawn")
TriggerEvent("playerSpawned") -- compatibility with old scripts, will be removed soon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: undefined-global
local spawnedVehicles = {}

function OpenVehicleSpawnerMenu(type, hospital, part, partNum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Config.DrawDistance = 10.0 -- How close do you need to be in order for the marke

Config.Marker = { type = 1, x = 1.5, y = 1.5, z = 0.5, r = 102, g = 0, b = 102, a = 100, rotate = false }

Config.ReviveReward = 700 -- Revive reward, set to 0 if you don't want it enabled
Config.ReviveReward = 8000 -- Revive reward, set to 0 if you don't want it enabled
Config.AntiCombatLog = true -- Enable anti-combat logging? (Removes Items when a player logs back after intentionally logging out while dead.)
Config.LoadIpl = false -- Disable if you're using fivem-ipl or other IPL loaders

Config.Locale = "it"

Config.EarlyRespawnTimer = 60000 * 1 -- time til respawn is available
Config.EarlyRespawnTimer = 60000 * 10 -- time til respawn is available
Config.BleedoutTimer = 60000 * 10 -- time til the player bleeds out

Config.EnablePlayerManagement = true -- Enable society managing (If you are using bpt_society).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
fx_version 'adamant'
game 'gta5'
description 'Provides a way for players to RP as paramedics (heal/revive players)'
version '1.0.1'
legacyversion '1.9.1'
lua54 'yes'
fx_version("adamant")
game("gta5")
description("Provides a way for players to RP as paramedics (heal/revive players)")
version("1.0.7")
legacyversion("1.9.1")
lua54("yes")

shared_scripts {
'@es_extended/imports.lua',
'@es_extended/locale.lua',
'locales/*.lua',
'config.lua'
}
shared_scripts({
"@es_extended/imports.lua",
"@es_extended/locale.lua",
"locales/*.lua",
"config.lua",
})

server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/*.lua'
}
server_scripts({
"@oxmysql/lib/MySQL.lua",
"server/*.lua",
})

client_scripts {
'client/*.lua'
}
client_scripts({
"client/*.lua",
})

dependencies {
'es_extended',
'esx_skin',
'esx_vehicleshop'
}
dependencies({
"es_extended",
"esx_skin",
"esx_vehicleshop",
})
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Locales["it"] = {
["ems_menu_putincar"] = "Metti in Veicolo",
["ems_menu_small"] = "Cura ferite leggere",
["ems_menu_big"] = "Tratta ferite gravi",
["ems_menu_search"] = "Paziente non trovato",
["ems_menu_search"] = "Cerca i documenti",
-- Telefono
["alert_ambulance"] = "Chiedi l'ambulanza",
["alert_ambulance"] = "Chiama l'ambulanza",
-- Morte
["respawn_available_in"] = "Puoi rinascere tra %s minuti %s secondi",
["respawn_bleedout_in"] = "Sanguinerai a morte tra %s minuti %s secondi\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---@diagnostic disable: undefined-global

local playersHealing, deadPlayers = {}, {}

if GetResourceState("npwd") ~= "missing" then
Expand Down Expand Up @@ -42,7 +44,7 @@ AddEventHandler("bpt_ambulancejob:revive", function(playerId)
xPlayer.triggerEvent("bpt_ambulancejob:PlayerNotDead", playerId)
end
end
deadPlayers[playerId] = nil
deadPlayers[playerId] = "distress"
else
xPlayer.showNotification(TranslateCap("player_not_unconscious"))
end
Expand Down
Loading