Spoiler
local firstSpawn, PlayerLoaded = true, false
isDead = false
ESX = nil
AddEventHandler("onClientMapStart", function()
exports.spawnmanager:spawnPlayer()
Citizen.Wait(5000)
exports.spawnmanager:setAutoSpawn(false)
end)
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX.GetPlayerData().job == nil do
Citizen.Wait(100)
end
PlayerLoaded = true
ESX.PlayerData = ESX.GetPlayerData()
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
ESX.PlayerData = xPlayer
PlayerLoaded = true
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
end)
AddEventHandler('esx:onPlayerSpawn', function()
isDead = false
if firstSpawn then
firstSpawn = false
if Config.AntiCombatLog then
while not PlayerLoaded do
Citizen.Wait(1000)
end
ESX.TriggerServerCallback('esx_ambulancejob:getDeathStatus', function(shouldDie)
if shouldDie then
ESX.ShowNotification(_U('combatlog_message'))
RemoveItemsAfterRPDeath()
end
end)
end
end
end)
-- Create blips
Citizen.CreateThread(function()
for k,v in pairs(Config.Hospitals) do
local blip = AddBlipForCoord(v.Blip.coords)
SetBlipSprite(blip, v.Blip.sprite)
SetBlipScale(blip, v.Blip.scale)
SetBlipColour(blip, v.Blip.color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(_U('blip_hospital'))
EndTextCommandSetBlipName(blip)
end
end)
-- Disable most inputs when dead
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if isDead then
DisableAllControlActions(0)
EnableControlAction(0, 47, true)
EnableControlAction(0, 245, true)
EnableControlAction(0, 38, true)
else
Citizen.Wait(500)
end
end
end)
function OnPlayerDeath()
isDead = true
ESX.UI.Menu.CloseAll()
TriggerServerEvent('esx_ambulancejob:setDeathStatus', true)
StartDeathTimer()
StartDistressSignal()
StartScreenEffect('DeathFailOut', 0, false)
end
RegisterNetEvent('esx_ambulancejob:useItem')
AddEventHandler('esx_ambulancejob:useItem', function(itemName)
ESX.UI.Menu.CloseAll()
if itemName == 'medikit' then
local lib, anim = 'anim@heists@narcotics@funding@gang_idle', 'gang_chatting_idle01' -- TODO better animations
local playerPed = PlayerPedId()
ESX.Streaming.RequestAnimDict(lib, function()
TaskPlayAnim(playerPed, lib, anim, 8.0, -8.0, -1, 0, 0, false, false, false)
Citizen.Wait(500)
while IsEntityPlayingAnim(playerPed, lib, anim, 3) do
Citizen.Wait(0)
DisableAllControlActions(0)
end
TriggerEvent('esx_ambulancejob:heal', 'big', true)
ESX.ShowNotification(_U('used_medikit'))
end)
elseif itemName == 'bandage' then
local lib, anim = 'anim@heists@narcotics@funding@gang_idle', 'gang_chatting_idle01' -- TODO better animations
local playerPed = PlayerPedId()
ESX.Streaming.RequestAnimDict(lib, function()
TaskPlayAnim(playerPed, lib, anim, 8.0, -8.0, -1, 0, 0, false, false, false)
Citizen.Wait(500)
while IsEntityPlayingAnim(playerPed, lib, anim, 3) do
Citizen.Wait(0)
DisableAllControlActions(0)
end
TriggerEvent('esx_ambulancejob:heal', 'small', true)
ESX.ShowNotification(_U('used_bandage'))
end)
end
end)
function StartDistressSignal()
Citizen.CreateThread(function()
local timer = Config.BleedoutTimer
while timer > 0 and isDead do
Citizen.Wait(0)
timer = timer - 30
SetTextFont(4)
SetTextScale(0.45, 0.45)
SetTextColour(185, 185, 185, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
BeginTextCommandDisplayText('STRING')
AddTextComponentSubstringPlayerName(_U('distress_send'))
EndTextCommandDisplayText(0.175, 0.805)
if IsControlJustReleased(0, 47) then
SendDistressSignal()
break
end
end
end)
end
function SendDistressSignal()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
ESX.ShowNotification(_U('distress_sent'))
TriggerServerEvent('esx_ambulancejob:onPlayerDistress')
end
function DrawGenericTextThisFrame()
SetTextFont(4)
SetTextScale(0.0, 0.5)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextCentre(true)
end
function secondsToClock(seconds)
local seconds, hours, mins, secs = tonumber(seconds), 0, 0, 0
if seconds <= 0 then
return 0, 0
else
local hours = string.format('%02.f', math.floor(seconds / 3600))
local mins = string.format('%02.f', math.floor(seconds / 60 - (hours * 60)))
local secs = string.format('%02.f', math.floor(seconds - hours * 3600 - mins * 60))
return mins, secs
end
end
function StartDeathTimer()
local canPayFine = false
if Config.EarlyRespawnFine then
ESX.TriggerServerCallback('esx_ambulancejob:checkBalance', function(canPay)
canPayFine = canPay
end)
end
local earlySpawnTimer = ESX.Math.Round(Config.EarlyRespawnTimer / 1000)
local bleedoutTimer = ESX.Math.Round(Config.BleedoutTimer / 1000)
Citizen.CreateThread(function()
-- early respawn timer
while earlySpawnTimer > 0 and isDead do
Citizen.Wait(1000)
if earlySpawnTimer > 0 then
earlySpawnTimer = earlySpawnTimer - 1
end
end
-- bleedout timer
while bleedoutTimer > 0 and isDead do
Citizen.Wait(1000)
if bleedoutTimer > 0 then
bleedoutTimer = bleedoutTimer - 1
end
end
end)
Citizen.CreateThread(function()
local text, timeHeld
-- early respawn timer
while earlySpawnTimer > 0 and isDead do
Citizen.Wait(0)
text = _U('respawn_available_in', secondsToClock(earlySpawnTimer))
DrawGenericTextThisFrame()
SetTextEntry('STRING')
AddTextComponentString(text)
DrawText(0.5, 0.8)
end
-- bleedout timer
while bleedoutTimer > 0 and isDead do
Citizen.Wait(0)
text = _U('respawn_bleedout_in', secondsToClock(bleedoutTimer))
if not Config.EarlyRespawnFine then
text = text .. _U('respawn_bleedout_prompt')
if IsControlPressed(0, 38) and timeHeld > 60 then
RemoveItemsAfterRPDeath()
break
end
elseif Config.EarlyRespawnFine and canPayFine then
text = text .. _U('respawn_bleedout_fine', ESX.Math.GroupDigits(Config.EarlyRespawnFineAmount))
if IsControlPressed(0, 38) and timeHeld > 60 then
TriggerServerEvent('esx_ambulancejob:payFine')
RemoveItemsAfterRPDeath()
break
end
end
if IsControlPressed(0, 38) then
timeHeld = timeHeld + 1
else
timeHeld = 0
end
DrawGenericTextThisFrame()
SetTextEntry('STRING')
AddTextComponentString(text)
DrawText(0.5, 0.8)
end
if bleedoutTimer < 1 and isDead then
RemoveItemsAfterRPDeath()
end
end)
end
function RemoveItemsAfterRPDeath()
TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)
Citizen.CreateThread(function()
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
Citizen.Wait(10)
end
ESX.TriggerServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function()
local formattedCoords = {
x = Config.RespawnPoint.coords.x,
y = Config.RespawnPoint.coords.y,
z = Config.RespawnPoint.coords.z
}
ESX.SetPlayerData('loadout', {})
RespawnPed(PlayerPedId(), formattedCoords, Config.RespawnPoint.heading)
StopScreenEffect('DeathFailOut')
DoScreenFadeIn(800)
end)
end)
end
function RespawnPed(ped, coords, heading)
SetEntityCoordsNoOffset(ped, coords.x, coords.y, coords.z, false, false, false, true)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, heading, true, false)
SetPlayerInvincible(ped, false)
ClearPedBloodDamage(ped)
TriggerServerEvent('esx:onPlayerSpawn')
TriggerEvent('esx:onPlayerSpawn')
TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon
end
RegisterNetEvent('esx_phone:loaded')
AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
local specialContact = {
name = 'Ambulance',
number = 'ambulance',
base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAABp5JREFUWIW1l21sFNcVhp/58npn195de23Ha4Mh2EASSvk0CPVHmmCEI0RCTQMBKVVooxYoalBVCVokICWFVFVEFeKoUdNECkZQIlAoFGMhIkrB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('esx_phone:addSpecialContact', specialContact.name, specialContact.number, specialContact.base64Icon)
end)
AddEventHandler('esx:onPlayerDeath', function(data)
OnPlayerDeath()
end)
RegisterNetEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
Citizen.Wait(50)
end
local formattedCoords = {
x = ESX.Math.Round(coords.x, 1),
y = ESX.Math.Round(coords.y, 1),
z = ESX.Math.Round(coords.z, 1)
}
RespawnPed(playerPed, formattedCoords, 0.0)
StopScreenEffect('DeathFailOut')
DoScreenFadeIn(800)
end)
-- Load unloaded IPLs
if Config.LoadIpl then
RequestIpl('Coroner_Int_on') -- Morgue
end
Spoiler
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
ESX = nil
local CurrentAction = nil
local CurrentActionMsg = nil
local CurrentActionData = nil
local Licenses = {}
local CurrentTest = nil
local CurrentTestType = nil
local CurrentVehicle = nil
local CurrentCheckPoint = 0
local LastCheckPoint = -1
local CurrentBlip = nil
local CurrentZoneType = nil
local DriveErrors = 0
local IsAboveSpeedLimit = false
local LastVehicleHealth = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function DrawMissionText(msg, time)
ClearPrints()
BeginTextCommandPrint('STRING')
AddTextComponentSubstringPlayerName(msg)
EndTextCommandPrint(time, true)
end
function StartTheoryTest()
CurrentTest = 'theory'
SendNUIMessage({
openQuestion = true
})
ESX.SetTimeout(200, function()
SetNuiFocus(true, true)
end)
TriggerServerEvent('esx_dmvschool:pay', Config.Prices['dmv'])
end
function StopTheoryTest(success)
CurrentTest = nil
SendNUIMessage({
openQuestion = false
})
SetNuiFocus(false)
if success then
TriggerServerEvent('esx_dmvschool:addLicense', 'dmv')
ESX.ShowNotification(_U('passed_test'))
else
ESX.ShowNotification(_U('failed_test'))
end
end
function StartDriveTest(type)
ESX.Game.SpawnVehicle(Config.VehicleModels[type], Config.Zones.VehicleSpawnPoint.Pos, Config.Zones.VehicleSpawnPoint.Pos.h, function(vehicle)
CurrentTest = 'drive'
CurrentTestType = type
CurrentCheckPoint = 0
LastCheckPoint = -1
CurrentZoneType = 'residence'
DriveErrors = 0
IsAboveSpeedLimit = false
CurrentVehicle = vehicle
LastVehicleHealth = GetEntityHealth(vehicle)
local playerPed = PlayerPedId()
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end)
TriggerServerEvent('esx_dmvschool:pay', Config.Prices[type])
end
function StopDriveTest(success)
if success then
TriggerServerEvent('esx_dmvschool:addLicense', CurrentTestType)
ESX.ShowNotification(_U('passed_test'))
else
ESX.ShowNotification(_U('failed_test'))
end
CurrentTest = nil
CurrentTestType = nil
end
function SetCurrentZoneType(type)
CurrentZoneType = type
end
function OpenDMVSchoolMenu()
local ownedLicenses = {}
for i=1, #Licenses, 1 do
ownedLicenses[Licenses[i].type] = true
end
local elements = {}
if not ownedLicenses['dmv'] then
table.insert(elements, {
label = (('%s: <span style="color:green;">%s</span>'):format(_U('theory_test'), _U('school_item', ESX.Math.GroupDigits(Config.Prices['dmv'])))),
value = 'theory_test'
})
end
if ownedLicenses['dmv'] then
if not ownedLicenses['drive'] then
table.insert(elements, {
label = (('%s: <span style="color:green;">%s</span>'):format(_U('road_test_car'), _U('school_item', ESX.Math.GroupDigits(Config.Prices['drive'])))),
value = 'drive_test',
type = 'drive'
})
end
if not ownedLicenses['drive_bike'] then
table.insert(elements, {
label = (('%s: <span style="color:green;">%s</span>'):format(_U('road_test_bike'), _U('school_item', ESX.Math.GroupDigits(Config.Prices['drive_bike'])))),
value = 'drive_test',
type = 'drive_bike'
})
end
if not ownedLicenses['drive_truck'] then
table.insert(elements, {
label = (('%s: <span style="color:green;">%s</span>'):format(_U('drive_truck'), _U('school_item', ESX.Math.GroupDigits(Config.Prices['drive_truck'])))),
value = 'drive_test',
type = 'drive_truck'
})
end
end
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'dmvschool_actions', {
title = _U('driving_school'),
elements = elements,
align = 'top-left'
}, function(data, menu)
if data.current.value == 'theory_test' then
menu.close()
StartTheoryTest()
elseif data.current.value == 'drive_test' then
StartDriveTest(data.current.type)
end
end, function(data, menu)
menu.close()
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = _U('press_open_menu')
CurrentActionData = {}
end)
end
RegisterNUICallback('question', function(data, cb)
SendNUIMessage({
openSection = 'question'
})
cb()
end)
RegisterNUICallback('close', function(data, cb)
StopTheoryTest(true)
cb()
end)
RegisterNUICallback('kick', function(data, cb)
StopTheoryTest(false)
cb()
end)
AddEventHandler('esx_dmvschool:hasEnteredMarker', function(zone)
if zone == 'DMVSchool' then
CurrentAction = 'dmvschool_menu'
CurrentActionMsg = _U('press_open_menu')
CurrentActionData = {}
end
end)
AddEventHandler('esx_dmvschool:hasExitedMarker', function(zone)
CurrentAction = nil
ESX.UI.Menu.CloseAll()
end)
RegisterNetEvent('esx_dmvschool:loadLicenses')
AddEventHandler('esx_dmvschool:loadLicenses', function(licenses)
Licenses = licenses
end)
-- Create Blips
Citizen.CreateThread(function()
local blip = AddBlipForCoord(Config.Zones.DMVSchool.Pos.x, Config.Zones.DMVSchool.Pos.y, Config.Zones.DMVSchool.Pos.z)
SetBlipSprite (blip, 408)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('driving_school_blip'))
EndTextCommandSetBlipName(blip)
end)
-- Display markers
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local coords = GetEntityCoords(PlayerPedId())
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(100)
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_dmvschool:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_dmvschool:hasExitedMarker', LastZone)
end
end
end)
-- Block UI
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
if CurrentTest == 'theory' then
local playerPed = PlayerPedId()
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisablePlayerFiring(playerPed, true) -- Disable weapon firing
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
else
Citizen.Wait(500)
end
end
end)
-- Key Controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction then
ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, Keys['E']) then
if CurrentAction == 'dmvschool_menu' then
OpenDMVSchoolMenu()
end
CurrentAction = nil
end
else
Citizen.Wait(500)
end
end
end)
-- Drive test
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentTest == 'drive' then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nextCheckPoint = CurrentCheckPoint + 1
if Config.CheckPoints[nextCheckPoint] == nil then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
CurrentTest = nil
ESX.ShowNotification(_U('driving_test_complete'))
if DriveErrors < Config.MaxErrors then
StopDriveTest(true)
else
StopDriveTest(false)
end
else
if CurrentCheckPoint ~= LastCheckPoint then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
end
CurrentBlip = AddBlipForCoord(Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z)
SetBlipRoute(CurrentBlip, 1)
LastCheckPoint = CurrentCheckPoint
end
local distance = GetDistanceBetweenCoords(coords, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, true)
if distance <= 100.0 then
DrawMarker(1, Config.CheckPoints[nextCheckPoint].Pos.x, Config.CheckPoints[nextCheckPoint].Pos.y, Config.CheckPoints[nextCheckPoint].Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, 1.5, 1.5, 1.5, 102, 204, 102, 100, false, true, 2, false, false, false, false)
end
if distance <= 3.0 then
Config.CheckPoints[nextCheckPoint].Action(playerPed, CurrentVehicle, SetCurrentZoneType)
CurrentCheckPoint = CurrentCheckPoint + 1
end
end
else
-- not currently taking driver test
Citizen.Wait(500)
end
end
end)
-- Speed / Damage control
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if CurrentTest == 'drive' then
local playerPed = PlayerPedId()
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
local tooMuchSpeed = false
for k,v in pairs(Config.SpeedLimits) do
if CurrentZoneType == k and speed > v then
tooMuchSpeed = true
if not IsAboveSpeedLimit then
DriveErrors = DriveErrors + 1
IsAboveSpeedLimit = true
ESX.ShowNotification(_U('driving_too_fast', v))
ESX.ShowNotification(_U('errors', DriveErrors, Config.MaxErrors))
end
end
end
if not tooMuchSpeed then
IsAboveSpeedLimit = false
end
local health = GetEntityHealth(vehicle)
if health < LastVehicleHealth then
DriveErrors = DriveErrors + 1
ESX.ShowNotification(_U('you_damaged_veh'))
ESX.ShowNotification(_U('errors', DriveErrors, Config.MaxErrors))
-- avoid stacking faults
LastVehicleHealth = health
Citizen.Wait(1500)
end
end
else
-- not currently taking driver test
Citizen.Wait(500)
end
end
end)