I loved to do it!
<3
I saw and followed the new README but it is still the same symptom.
@dlrbgh0313 Can you show me how your server.lua from ambulancejob looks like please ?
main.lua from esx_ambulancejob/server shared in Description.
TYSM. Finally it works
I have everything needed, changed medkit label to Defib but when I go to revive someone with K all I get is that I donāt have a defib in my inventory though I do.
BE carreful it has to be a āmedikitā not a āmedkitā . You have the correct item value in the client.lua at the first line. If you are completely stuck, drop me your discord in MP and I will help you.
I totally forgot that its setup as medikit instead of medkit, will test again, thanks!
Same here. We tried this on our server, everything seemed to work including the animation, but the revive does not occur.
Is there a way to make this work without using a keybind but rather just simply āUseā through the inventory menu?
we done this
Blockquote
Even I try to replace your
Blockquote
Still Players Not Getting Revive !! Need a fix ! else good script if we can use it
@Hypnotic_92 There is probably a way to modify this but havenāt tested it yet.
@subhampro There is no fix needed for this script as we were able to have this working for other players/users.
Do you guys have kept in mind all the requirements and also make sure to use the item from esx_ambulancejob, which is āmedikitā ?
Also do not rename the script folder ādefibā to something else it has to stay as it is.
If you need assistance PM me so we can have a look with screen sharing.
Cheers
i want of vrp.
Iāve never been on VRP tho, canāt really help you on that side mate
This is really heavy for server it may cause hitch time warning care.
Script doesnāt seem to work, keep getting this error in console.
Error parsing script @defib/server.lua in resource defib: @defib/server.lua:23: āendā expected (to close āfunctionā at line 6) near
Failed to load script server.lua.
How i can change SCENARIO to anim ?
Because i try to do something like this but it doesnt work
client.lua (1.7 KB)
hey so i tried getting it everything works the animation but it uses like 3 medikits and wont even revive the player y is that
Hi everyone,
Iāve taken some time to Update this script with the current manifest version of FiveM.
Iāve also translated all in game notifications from french to english for this script.
All files within my github are updated since the 18th of August 2020.
As I am not a server owner anymore on FiveM, I would be glad to help someone who needs this script to set it up on his server. Feel free to contact me so we can have a look remotely.
Since the changes that have been made on FiveM are not drastic, I am assuming that the script should be working smoothly with the current update that I made.
the āKā How can I keybinding to Chat Command
Citizen.Wait(10)
if(IsControlJustReleased(1, 311))then
TriggerServerEvent('defib:getAmbulancesCount')
end
end
end)
i want to chang toRegisterCommand(āhealthā, function(source, args, rawCommand)
Weāve been wondering why our shiny new RP server has been dying and encountering server hitches with increasing frequency after a few hours and unusable in 12 - 14. We ran some profiling on the server with the built in tools and found the defib had some large numbers against it, although a specific line number wasnāt listed as the culprit. After inspection it became clear what is wrong. One thing that is seriously bugging about modding for online game communities is that itās fairly easy to do and LUA in particular whilst obscure, is a pretty decent language and people can get cracking pretty fast. The biggest problem is it isnāt type safe as with compiled language and IDE support limited so you donāt get hints as to where you may have done things poorly. Also, just jumping in and learning coding through this sounds great, but when you cause people weeks of agony from tacking on another published resource which is substandard onto the mass of crap out there the burden on the consumers to fix what should be clean to start with is ridiculous. I donāt expect everything to be perfect but please be careful when you decide to make something public, do testing, testing and more testing, learn about coding, donāt just throw code out there. Frankly, the issue Iāve spotted here is inexcusable. Soā¦ when you actually LEARN coding properly youāll reach the topic of recursive algorithms which can be used to create a small unit that can be reused and run over and over seeding each call with the next piece of information to process. It is absolutely critical that you provide a guard clause with a condition to return which ensures that your recursion doesnāt keep nested new calls forever, the key reason being that a call to a function allocates memory to hold the variables required for the function instance to execute. The memory is put onto the stack. A stack is a first in last out concept and as you add more allocations onto the stack you have more memory to unwind (IF you return and unwind). The only process that deallocates the memory is the function ending and returning to the caller. In the case of recursion you are dumping a new instance of the functionās initialised memory block onto the stack over and over again eventually filling up all available RAM.
So in regards to this defib script, note that there is a SetTimeout function that waits for 5 seconds and calls a function, which is the same function weāre in. Where is the guard clause? This recursive call goes on forever and if the 5000ms pause wasnāt there, your server would be dead in minutes, probably less. Memory is being allocated on each call and never released. Here is the code as currently published:
local ESX = nil
local ambulancesConnected = 0
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
function CountAmbulances()
local xPlayers = ESX.GetPlayers()
ambulancesConnected = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'ambulance' then
ambulancesConnected = ambulancesConnected + 1
end
end
SetTimeout(5000, CountAmbulances)
end
CountAmbulances()
RegisterServerEvent('defib:getAmbulancesCount')
AddEventHandler('defib:getAmbulancesCount', function()
TriggerClientEvent('defib:useDefib', source, ambulancesConnected)
end)
When I first looked at it I didnāt see any Citizen threads running which was a candidate for killing performance and it took awhile to realise the SetTimeout call was the likely candidate. You need to ask yourself, why does this script need to run that function every 5 seconds? Especially, why recursively? What it does is re-calculate the number of ambulances online, which only needs to be known when the debib is used. This script relies on ESX, so rather than loop and calculate here you could increase the ambulance count in an esx event handler for onPlayerConnected and decrement with onPlayerDisconnected. No loops just event handler subscribed to the ESX backend. In a pinch I decided to go with removing the initial global scoped call to CountAmbulances() and retain the method, but call it only when a defib is actually used. It still goes through the process of getting the players and testing for whether theyāre an EMS officer, but being all in memory itās not an expensive call. I may go with the event handlers eventually, but for now here is one reasonable way to go which Iām monitoring over the next 12 hours.
local ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
function CountAmbulances()
local xPlayers = ESX.GetPlayers()
local ambulancesConnected = 0
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'ambulance' then
ambulancesConnected = ambulancesConnected + 1
end
end
return ambulancesConnected
end
function UseDefib(source)
local ambulancesConnected = CountAmbulances()
TriggerClientEvent('defib:useDefib', source, ambulancesConnected)
end
ESX.RegisterUsableItem('defib', function(source)
UseDefib(source)
end)
Please check your systems and update if you have the broken recursive approach. There is simply no reason for that insanity.
Once Iāve test this and the event handler approach I will fork and pull request back to the original posterās Github repository. I wanted to share this in advance though to help anyone out who is using this and suffering the pain weāve been going through.
== Update
8 Hours after making the change and not a single server thread hitch.