-- variables --
ambulance=GetHashKey('ambulance')
paramedic=GetHashKey("S_M_M_Paramedic_01")
nearesthospital=nil
-- spawning events --
RegisterNetEvent('EMS:Spawn')
RegisterNetEvent('Coroner:Spawn')
-- report progress events --
RegisterNetEvent('EMS:Half')
RegisterNetEvent('Coroner:Half')
RegisterNetEvent('EMS:Arrived')
RegisterNetEvent('Coroner:Arrived')
-- spawning events handlers --
AddEventHandler('EMS:Spawn', function(target)
Citizen.CreateThread(function()
local pc = GetEntityCoords(target)
RequestModel(ambulance)
RequestModel(paramedic)
while not HasModelLoaded(ambulance) and RequestModel(paramedic) do
RequestModel(ambulance)
RequestModel(paramedic)
Citizen.Wait(0)
end
local offset=GetOffsetFromEntityInWorldCoords(PlayerPedId(), 50, 50, 0)
local heading, spawn = GetNthClosestVehicleNodeFavourDirection(offset.x, offset.y, offset.z, pc.x, pc.y, pc.z, 50, 1, 0x40400000, 0)
print('spawn point found!')
local vehicle = CreateVehicle(ambulance, spawn.x, spawn.y, spawn.z, heading, true, false)
created_ped = CreatePed(5, paramedic , spawn.x +2 , spawn.y+ 2, spawn.z+1, heading, true, true)
SetEntityAsMissionEntity(created_ped, false, false)
SetEntityAsMissionEntity(vehicle, false, false)
AddBlipForEntity(created_ped)
SetVehicleSiren(vehicle, true)
LoadAllPathNodes(true)
while not AreAllNavmeshRegionsLoaded() do
Wait(1)
end
TaskEnterVehicle(created_ped, vehicle, 1000, -1, 20, 1, 0)
while GetIsTaskActive(created_ped, 160) do
Wait(1)
end
TaskVehicleDriveToCoordLongrange(created_ped, vehicle, pc.x, pc.y, pc.z, 15.0, 1074004284, 2.0)
local arrived = false
while not arrived do
Citizen.Wait(0)
local coords = GetEntityCoords(created_ped, true)
local distance=Vdist(coords.x, coords.y, coords.z, pc.x, pc.y, pc.z)
if distance < 25.0 then
break
end
end
print('arrived')
local pheading, parking = GetNthClosestVehicleNodeFavourDirection(pc.x, pc.y, pc.z, pc.x, pc.y, pc.z, 10, 1, 0x40400000, 0)
TaskVehiclePark(created_ped, vehicle, parking.x, parking.y, parking.z, pheading, 1, 60.0, 1)
while GetEntitySpeed(vehicle)>0 do
Wait(1)
end
ClearPedTasks(created_ped)
TaskLeaveVehicle(created_ped, vehicle, 0)
while IsPedInAnyVehicle(created_ped, false) do
Wait(1)
end
print('exited veh')
ClearPedTasks(created_ped)
TaskGoToEntity(created_ped, target, -1, 4.0, 100, 1073741824, 0)
while not arrived do
Citizen.Wait(0)
local coords = GetEntityCoords(created_ped, true)
local distance=Vdist(coords.x, coords.y, coords.z, pc.x, pc.y, pc.z)
if distance < 2.0 then
print('arrived to target... kneeling...')
break
end
end
TaskStartScenarioInPlace(created_ped, 'CODE_HUMAN_MEDIC_KNEEL', 0, true)
while IsPedActiveInScenario(created_ped) do
Wait(1)
end
print("we're done here!")
end)
end)
-- command --
RegisterCommand("ems", function()
local target = GetClosestSuitablePed()
if target~=nil then
TriggerEvent('EMS:Spawn', target)
else
print('no peds found :^/')
end
end, false)
-- useful functions --
function table_to_string(tbl)
local result = "{"
for k, v in pairs(tbl) do
-- Check the key type (ignore any numerical keys - assume its an array)
if type(k) == "string" then
result = result.."[\""..k.."\"]".."="
end
-- Check the value type
if type(v) == "table" then
result = result..table_to_string(v)
elseif type(v) == "boolean" then
result = result..tostring(v)
else
result = result.."\""..v.."\""
end
result = result..","
end
-- Remove leading commas from the result
if result ~= "" then
result = result:sub(1, result:len()-1)
end
return result.."}"
end
function GetPositionInfrontOfEntity(ped, scalar)
target= nil
entity = GetEntity(ped)
right, forward, up, pos = GetEntityMatrix(entity)
return pos + forward * scalar
end
function GetClosestSuitablePed()
local handle, p = FindFirstPed()
local success
target=nil
repeat
success, p = FindNextPed(handle)
local pos = GetEntityCoords(p)
local distance = Vdist(pos.x, pos.y, pos.z, GetEntityCoords(PlayerPedId(), true).x, GetEntityCoords(PlayerPedId(), true).y, GetEntityCoords(PlayerPedId(), true).z)
if distance <= 4 and p ~= GetPlayerPed(-1) then
target=p
break
end
until not success
return target
end
it’s a client_script obviously. it’s also incomplete xD
oh yeah, i forgot to mention some people who helped me
@Syntasu for the GetPositionInfrontOfEntity function
@d0p3t for the GetClosestSuitablePed function