! Refactor: ESX_Ambulancejob: New Death System, 2nd spawn point

Added a New Death System that sends both a new blip and new Notification to EMS .
Added Sandy Shores Respawn Point
Added TextUI functionality
Added Debug Prints
Removed Weird FX on death
This commit is contained in:
Mycroft
2022-07-16 23:56:06 +01:00
parent 86bfceb510
commit 9447aa184d
6 changed files with 155 additions and 24 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
root = true
[*]
indent_size = 4
indent_size = 1
indent_style = tab
end_of_line = crlf
charset = utf-8
+78 -3
View File
@@ -322,13 +322,15 @@ AddEventHandler('esx_ambulancejob:hasEnteredMarker', function(hospital, part, pa
CurrentActionMsg = travelItem.Prompt
CurrentActionData = {to = travelItem.To.coords, heading = travelItem.To.heading}
end
ESX.TextUI(CurrentActionMsg)
end)
AddEventHandler('esx_ambulancejob:hasExitedMarker', function(hospital, part, partNum)
if not isInShopMenu then
ESX.UI.Menu.CloseAll()
end
ESX.HideUI()
CurrentAction = nil
end)
@@ -339,7 +341,6 @@ CreateThread(function()
if CurrentAction then
sleep = 0
ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, 38) then
if CurrentAction == 'AmbulanceActions' then
@@ -426,6 +427,10 @@ function OpenCloakroomMenu()
RemoveBlip(v)
deadPlayerBlips[playerId] = nil
end
deadPlayers = {}
if Config.Debug then
print("[INFO] Now Off Duty")
end
end)
elseif data.current.value == 'ambulance_wear' then
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
@@ -436,7 +441,13 @@ function OpenCloakroomMenu()
end
isOnDuty = true
TriggerEvent('esx_ambulancejob:setDeadPlayers', deadPlayers)
ESX.TriggerServerCallback('esx_ambulancejob:getDeadPlayers', function(_deadPlayers)
TriggerEvent('esx_ambulancejob:setDeadPlayers', _deadPlayers)
end)
if Config.Debug then
print("[INFO] Player Sex |" .. tostring(skin.sex))
print("[INFO] Now On Duty")
end
end)
end
@@ -456,6 +467,9 @@ function OpenPharmacyMenu()
{label = _U('pharmacy_take', _U('medikit')), item = 'medikit', type = 'slider', value = 1, min = 1, max = 100},
{label = _U('pharmacy_take', _U('bandage')), item = 'bandage', type = 'slider', value = 1, min = 1, max = 100}
}}, function(data, menu)
if Config.Debug then
print("[INFO] Attempting to Give Item |" .. tostring(data.current.item))
end
TriggerServerEvent('esx_ambulancejob:giveItem', data.current.item, data.current.value)
end, function(data, menu)
menu.close()
@@ -475,6 +489,9 @@ AddEventHandler('esx_ambulancejob:heal', function(healType, quiet)
SetEntityHealth(playerPed, maxHealth)
end
if Config.Debug then
print("[INFO] Healing Player |" .. tostring(healType))
end
if not quiet then
ESX.ShowNotification(_U('healed'))
end
@@ -484,6 +501,9 @@ RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
if isOnDuty and job ~= 'ambulance' then
for playerId,v in pairs(deadPlayerBlips) do
if Config.Debug then
print("[INFO] removing dead player blip |" .. tostring(playerId))
end
RemoveBlip(v)
deadPlayerBlips[playerId] = nil
end
@@ -492,6 +512,26 @@ AddEventHandler('esx:setJob', function(job)
end
end)
RegisterNetEvent('esx_ambulancejob:PlayerDead')
AddEventHandler('esx_ambulancejob:PlayerDead', function(Player)
if Config.Debug then
print("[INFO] Setting Player Dead |" .. tostring(Player))
end
deadPlayers[Player] = "dead"
end)
RegisterNetEvent('esx_ambulancejob:PlayerNotDead')
AddEventHandler('esx_ambulancejob:PlayerNotDead', function(Player)
if deadPlayerBlips[Player] then
RemoveBlip(deadPlayerBlips[Player])
deadPlayerBlips[Player] = nil
end
if Config.Debug then
print("[INFO] Setting Player Not Dead |" .. tostring(Player))
end
deadPlayers[Player] = nil
end)
RegisterNetEvent('esx_ambulancejob:setDeadPlayers')
AddEventHandler('esx_ambulancejob:setDeadPlayers', function(_deadPlayers)
deadPlayers = _deadPlayers
@@ -503,7 +543,13 @@ AddEventHandler('esx_ambulancejob:setDeadPlayers', function(_deadPlayers)
end
for playerId,status in pairs(deadPlayers) do
if Config.Debug then
print("[INFO] Setting Player As Dead |" .. tostring(playerId))
end
if status == 'distress' then
if Config.Debug then
print("[INFO] Creating Distress Blip for Player |" .. tostring(playerId))
end
local player = GetPlayerFromServerId(playerId)
local playerPed = GetPlayerPed(player)
local blip = AddBlipForEntity(playerPed)
@@ -522,3 +568,32 @@ AddEventHandler('esx_ambulancejob:setDeadPlayers', function(_deadPlayers)
end
end
end)
RegisterNetEvent('esx_ambulancejob:PlayerDistressed')
AddEventHandler('esx_ambulancejob:PlayerDistressed', function(Player)
deadPlayers[Player] = 'distress'
if isOnDuty then
if Config.Debug then
print("[INFO] Player Distress Recived - ID |" .. tostring(Player))
end
ESX.ShowNotification("[DISPATCH]: An Unconscious Person Has Been Reported", "error", 10000)
deadPlayerBlips[Player] = nil
local player = GetPlayerFromServerId(Player)
local playerPed = GetPlayerPed(player)
local blip = AddBlipForEntity(playerPed)
SetBlipSprite(blip, Config.DistressBlip.Sprite)
SetBlipColour(blip, Config.DistressBlip.Color)
SetBlipScale(blip, Config.DistressBlip.Scale)
SetBlipFlashes(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(_U('blip_dead'))
EndTextCommandSetBlipName(blip)
deadPlayerBlips[Player] = blip
end
end)
+8 -10
View File
@@ -55,9 +55,12 @@ CreateThread(function()
if isDead then
Sleep = 0
DisableAllControlActions(0)
EnableControlAction(0, 47, true)
EnableControlAction(0, 245, true)
EnableControlAction(0, 38, true)
EnableControlAction(0, 47, true) -- G
EnableControlAction(0, 245, true) -- T
EnableControlAction(0, 270, true) -- LEFT
EnableControlAction(0, 271, true) -- RIGHT
EnableControlAction(0, 272, true) -- UP
EnableControlAction(0, 273, true) -- DOWN
if isSearched then
local playerPed = PlayerPedId()
@@ -97,12 +100,10 @@ end)
function OnPlayerDeath()
isDead = true
ESX.UI.Menu.CloseAll()
ESX.HideUI()
TriggerServerEvent('esx_ambulancejob:setDeathStatus', true)
StartDeathTimer()
StartDistressSignal()
AnimpostfxPlay('DeathFailOut', 0, false)
end
RegisterNetEvent('esx_ambulancejob:useItem')
@@ -322,7 +323,6 @@ function RemoveItemsAfterRPDeath()
while not IsScreenFadedOut() do
Wait(0)
end
AnimpostfxStop('DeathFailOut')
DoScreenFadeIn(800)
end)
end)
@@ -359,7 +359,7 @@ AddEventHandler('esx_ambulancejob:revive', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
@@ -373,8 +373,6 @@ AddEventHandler('esx_ambulancejob:revive', function()
}
RespawnPed(playerPed, formattedCoords, 0.0)
AnimpostfxStop('DeathFailOut')
DoScreenFadeIn(800)
end)
+9 -2
View File
@@ -1,7 +1,7 @@
Config = {}
Config.DrawDistance = 10.0 -- How close do you need to be in order for the markers to be drawn (in GTA units).
Config.Debug = ESX.GetConfig().EnableDebug
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
@@ -10,6 +10,12 @@ Config.LoadIpl = true -- Disable if you're using fivem-ipl or
Config.Locale = 'en'
Config.DistressBlip = {
Sprite = 310,
Color = 48,
Scale = 2.0
}
Config.EarlyRespawnTimer = 60000 * 1 -- time til respawn is available
Config.BleedoutTimer = 60000 * 10 -- time til the player bleeds out
@@ -25,7 +31,8 @@ Config.EarlyRespawnFineAmount = 5000
Config.OxInventory = ESX.GetConfig().OxInventory
Config.RespawnPoints = {
{coords = vector3(341.0, -1397.3, 32.5), heading = 48.5}
{coords = vector3(341.0, -1397.3, 32.5), heading = 48.5}, -- Central Los Santos
{coords = vector3(1836.03, 3670.99, 34.28), heading = 296.06} -- Sandy Shores
}
Config.Hospitals = {
+1 -1
View File
@@ -81,5 +81,5 @@ Locales['en'] = {
['healed'] = 'You have been treated.',
-- Blips
['blip_hospital'] = 'Hospital',
['blip_dead'] = 'Unconscious player',
['blip_dead'] = 'Dying Player',
}
+58 -7
View File
@@ -15,7 +15,6 @@ AddEventHandler('esx_ambulancejob:revive', function(playerId)
if xPlayer and xPlayer.job.name == 'ambulance' then
local xTarget = ESX.GetPlayerFromId(playerId)
if xTarget then
if deadPlayers[playerId] then
if Config.ReviveReward > 0 then
@@ -26,6 +25,14 @@ AddEventHandler('esx_ambulancejob:revive', function(playerId)
xPlayer.showNotification(_U('revive_complete', xTarget.name))
xTarget.triggerEvent('esx_ambulancejob:revive')
end
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
if xPlayer.job.name == 'ambulance' then
xPlayer.triggerEvent('esx_ambulancejob:PlayerNotDead', playerId)
end
end
deadPlayers[playerId] = nil
else
xPlayer.showNotification(_U('player_not_unconscious'))
end
@@ -41,13 +48,26 @@ AddEventHandler('txAdmin:events:healedPlayer', function(eventData)
end
if deadPlayers[eventData.id] then
TriggerClientEvent('esx_ambulancejob:revive', eventData.id)
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
if xPlayer.job.name == 'ambulance' then
xPlayer.triggerEvent('esx_ambulancejob:PlayerNotDead', eventData.id)
end
end
deadPlayers[eventData.id] = nil
end
end)
RegisterNetEvent('esx:onPlayerDeath')
AddEventHandler('esx:onPlayerDeath', function(data)
local source = source
deadPlayers[source] = 'dead'
TriggerClientEvent('esx_ambulancejob:setDeadPlayers', -1, deadPlayers)
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
xPlayer.triggerEvent('esx_ambulancejob:PlayerDead', source)
end
end)
RegisterServerEvent('esx_ambulancejob:svsearch')
@@ -57,24 +77,40 @@ end)
RegisterNetEvent('esx_ambulancejob:onPlayerDistress')
AddEventHandler('esx_ambulancejob:onPlayerDistress', function()
local source = source
if deadPlayers[source] then
deadPlayers[source] = 'distress'
TriggerClientEvent('esx_ambulancejob:setDeadPlayers', -1, deadPlayers)
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
TriggerClientEvent('esx_ambulancejob:PlayerDistressed', xPlayer.source, source)
end
end
end)
RegisterNetEvent('esx:onPlayerSpawn')
AddEventHandler('esx:onPlayerSpawn', function()
local source = soruce
if deadPlayers[source] then
deadPlayers[source] = nil
TriggerClientEvent('esx_ambulancejob:setDeadPlayers', -1, deadPlayers)
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
xPlayer.triggerEvent('esx_ambulancejob:PlayerNotDead', source)
end
end
end)
AddEventHandler('esx:playerDropped', function(playerId, reason)
if deadPlayers[playerId] then
deadPlayers[playerId] = nil
TriggerClientEvent('esx_ambulancejob:setDeadPlayers', -1, deadPlayers)
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
if xPlayer.job.name == 'ambulance' then
xPlayer.triggerEvent('esx_ambulancejob:PlayerNotDead', playerId)
end
end
end
end)
@@ -243,10 +279,10 @@ AddEventHandler('esx_ambulancejob:giveItem', function(itemName, amount)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name ~= 'ambulance' then
print(('[esx_ambulancejob] [^2INFO^7] "%s" attempted to spawn in an item!'):format(xPlayer.identifier))
print(('[esx_ambulancejob] [^2WARNING^7] "%s" attempted to spawn in an item!'):format(xPlayer.identifier))
return
elseif (itemName ~= 'medikit' and itemName ~= 'bandage') then
print(('[esx_ambulancejob] [^2INFO^7] "%s" attempted to spawn in an item!'):format(xPlayer.identifier))
print(('[esx_ambulancejob] [^2WARNING^7] "%s" attempted to spawn in an item!'):format(xPlayer.identifier))
return
end
@@ -293,6 +329,13 @@ ESX.RegisterUsableItem('bandage', function(source)
end
end)
ESX.RegisterServerCallback('esx_ambulancejob:getDeadPlayers', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == "ambulance" then
cb(deadPlayers)
end
end)
ESX.RegisterServerCallback('esx_ambulancejob:getDeathStatus', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.scalar('SELECT is_dead FROM users WHERE identifier = ?', {xPlayer.identifier}, function(isDead)
@@ -306,5 +349,13 @@ AddEventHandler('esx_ambulancejob:setDeathStatus', function(isDead)
if type(isDead) == 'boolean' then
MySQL.update('UPDATE users SET is_dead = ? WHERE identifier = ?', {isDead, xPlayer.identifier})
if not isDead then
local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
for _, xPlayer in pairs(Ambulance) do
xPlayer.triggerEvent('esx_ambulancejob:PlayerNotDead', source)
end
end
end
end)