Can help me someone?

I trying to make Revive by ID for medics in esx_ambulancejob.

 if IsControlJustPressed(1, Keys[',']) and IsControlPressed(1, Keys['LEFTCTRL']) and PlayerData.job ~= nil and PlayerData.job.name == 'ambulance' and not IsDead then
		ESX.TriggerServerCallback('esx_ambulancejob:getItemAmount', function(quantity)
		  if quantity > 0 then
			DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", "", "", "", "", 30)
			    while (UpdateOnscreenKeyboard() == 0) do
				    DisableAllControlActions(0);
				    Wait(0);
			    end
			    if (GetOnscreenKeyboardResult()) then
				    local serverID = GetOnscreenKeyboardResult()
			    end
			TriggerServerEvent('esx_ambulancejob:revivee', serverID)
			TriggerServerEvent('esx_ambulancejob:removeItem', 'medikit')
		  else
		    ESX.ShowNotification('Nie posiadasz apteczki.')
		  end
		end, 'medikit')
	  end

And i have a problem with ( local serverID = GetOnscreenKeyboardResult() ) he doesn’t give me revive and he takes the first aid kit :C.

No error in ( TriggerServerEvent(‘esx_ambulancejob:revivee’, serverID) ) I have changed TriggerServerEvents.

Thank you all for trying to help me.

1 Like

I just tried this in my test sv, I will try to explain it to you and I hope you understand.
The command can only be used by EMS

we first look at:
esx_ambulancejob\client\main.lua

RegisterNetEvent('esx_ambulancejob:revive')
AddEventHandler('esx_ambulancejob:revive', function()
	local playerPed = PlayerPedId()
	local coords = GetEntityCoords(playerPed)

	TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)

	Citizen.CreateThread(function()
		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)
		}

		ESX.SetPlayerData('lastPosition', formattedCoords)

		TriggerServerEvent('esx:updateLastPosition', formattedCoords)

		RespawnPed(playerPed, formattedCoords, 0.0)

		StopScreenEffect('DeathFailOut')
		DoScreenFadeIn(800)
	end)
end)

and below you put this.


RegisterNetEvent('esx_ambulancejob2:revive')
AddEventHandler('esx_ambulancejob2:revive', function()

	local playerPed = PlayerPedId()
	local coords = GetEntityCoords(playerPed)

if (ESX.PlayerData.job.name == 'ambulance') then

	TriggerServerEvent('esx_ambulancejob:setDeathStatus', false)

	Citizen.CreateThread(function()
		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)
		}

		ESX.SetPlayerData('lastPosition', formattedCoords)

		TriggerServerEvent('esx:updateLastPosition', formattedCoords)

		RespawnPed(playerPed, formattedCoords, 0.0)

		StopScreenEffect('DeathFailOut')
		DoScreenFadeIn(800)
	end)

else
				ESX.ShowNotification('NO ERES EMS PARA USAR ESTE COMANDO')
end

end)

go to the archive:

\esx_ambulancejob\server\main.lua

then you add this on any line:

TriggerEvent('es:addGroupCommand', 'reviveems', 'user', function(source, args, user)
	if args[1] ~= nil then
		if GetPlayerName(tonumber(args[1])) ~= nil then
			TriggerClientEvent('esx_ambulancejob2:revive', tonumber(args[1]))
		end
	else
		TriggerClientEvent('esx_ambulancejob2:revive', source)
	end
end, function(source, args, user)
end, { help = _U('revive_help'), params = {{ name = 'id' }} })

should work you out without problems :heart:

1 Like

I must change few things in this code but this works thanks :*

Now i have other problem :C.

I use
if PlayerData.job ~= nil and PlayerData.job.name == 'ambulance' and not IsDead then
becouse
if (ESX.PlayerData.job.name == 'ambulance') then
not work for me, but now if i change job i can still use revive or if i will join to server as offduty medic then i cant revive by id :C.

Something like PlayerData.job ~= nil and PlayerData.job.name == 'ambulance' refresh only while joining server.

My English is bad xD

try to look for this:

while ESX.GetPlayerData().job == nil do
        Citizen.Wait(10)
    end

and below put this:

`PlayerData = ESX.GetPlayerData()`

I don’t have it xD

maybe that’s why, try it and try

Paste IT to client?

if in the first lines

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.