I apologise if post this in the wrong section. I wasn’t sure where to post this. I’m trying to make an item to revive peds such as an defibrilator. Say i die, i call a friend, he buys a defib and comes to my rescue. I was thinking that i could modify the esx_ambulance to use the medikits usable and maybe rename them into defib. Is there a ready script/resource for esx? or can someone help me make one?
In this one u are able to use a medkit: [Release][ESX] [EMS/Ambulance Job]
So if you change the label of the medkit to defibrilator, you have a defibrilator instead of a medkit.
thing is that you need to be a medic to revive someone. if a civilian uses it, it only raises your health, not the dead person infront
Pretty easy to re-use the code from esx_ambulancejob. Look around line 331.
Make a new client script, it will look pretty much like this:
-- Name of defibrillator item in database
local defibItemName = 'defib'
-- Function to use defibrillator
local function useDefib()
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
if closestPlayer == -1 or closestDistance > 3.0 then
ESX.ShowNotification("No players")
else
ESX.TriggerServerCallback('esx_ambulancejob:getItemAmount', function(qtty)
if qtty > 0 then
local closestPlayerPed = GetPlayerPed(closestPlayer)
local health = GetEntityHealth(closestPlayerPed)
if health == 0 then
local playerPed = GetPlayerPed(-1)
ESX.ShowNotification("Reviving")
TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
Citizen.Wait(10000)
ClearPedTasks(playerPed)
TriggerServerEvent('esx_ambulancejob:removeItem',defibItemName)
TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
else
ESX.ShowNotification("Not dead")
end
else
ESX.ShowNotification("No defib")
end
end, defibItemName)
end
end
-- Simple loop to call the defibrillator function if "E" is pressed
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if(IsControlJustReleased(1, 51))then
useDefib()
end
end
end)
That snippet should allow any player with the item “defib” in their inventory to press “E” next to a dead player and revive them. It is using the esx_ambulancejob server side scripts, so you obviously need that installed. You also need an item named defib in your database.
Assuming you’re using the normal ESX database structure, this SQL query would work:
INSERT INTO `items` (`id`, `name`, `label`, `limit`, `rare`, `can_remove`) VALUES (NULL, 'defib', 'Defibrillator', '-1', '0', '1');
TriggerServerEvent('esx_ambulancejob:removeItem', 'medikit')
I think you have to change this line to this:
TriggerServerEvent('esx_ambulancejob:removeItem', 'defib')
You’re right, fixed it. Thanks for pointing that out
Thank you so much! you saved me from hours of looking for it
I an getting a attempt to index null value global ESX error when i try this any ideas
Is it possible to convert this to be a marker instead of an item? So, for example, a dead player can be dragged to a spot in a hospital where they can then press a button to be revived?
https://gyazo.com/72a24855351af67d259f3b268d933bc6, this is the error of my code, don’t know what else to do with my knowledge, if anyone is willing to help, would be appreciated. Below is the folder i fooled around and tried to make but didn’t work
main.lua (1.3 KB) config.lua (39 Bytes) esx_defib.sql (259 Bytes) en.lua (289 Bytes) main.lua (469 Bytes) __resource.lua (308 Bytes)
Problem : client/main.lua
Here is the code needed to make my friend’s script work
could I use it please thank you
to drop underneath de local defibItemName = ‘defib’
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
so i finally got this working but when for some reason you can revive someone when they are alive still. happen to know a way to fix that?
I get the failed to index global ESX error, any help?
Great code, works almost perfect just the fact it doesn’t actually revive them and just says player revive. Could you help as you wrote the code, please?