Bandage & Medkit animations upon usage, closes #116

This commit is contained in:
ElPumpo
2019-02-24 12:44:06 +01:00
parent ea6c31f1d9
commit 7b614c3c7b
3 changed files with 59 additions and 12 deletions
+4 -2
View File
@@ -907,7 +907,7 @@ function WarpPedInClosestVehicle(ped)
end
RegisterNetEvent('esx_ambulancejob:heal')
AddEventHandler('esx_ambulancejob:heal', function(healType)
AddEventHandler('esx_ambulancejob:heal', function(healType, quiet)
local playerPed = PlayerPedId()
local maxHealth = GetEntityMaxHealth(playerPed)
@@ -919,5 +919,7 @@ AddEventHandler('esx_ambulancejob:heal', function(healType)
SetEntityHealth(playerPed, maxHealth)
end
ESX.ShowNotification(_U('healed'))
if not quiet then
ESX.ShowNotification(_U('healed'))
end
end)
+36
View File
@@ -102,6 +102,42 @@ function OnPlayerDeath()
StartScreenEffect('DeathFailOut', 0, false)
end
RegisterNetEvent('esx_ambulancejob:useItem')
AddEventHandler('esx_ambulancejob:useItem', function(itemName)
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(100)
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(100)
end
TriggerEvent('esx_ambulancejob:heal', 'small', true)
ESX.ShowNotification(_U('used_bandage'))
end)
end
end)
function StartDistressSignal()
Citizen.CreateThread(function()
local timer = Config.BleedoutTimer
+19 -10
View File
@@ -1,4 +1,5 @@
ESX = nil
local playersHealing = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
@@ -250,21 +251,29 @@ end, function(source, args, user)
end, { help = _U('revive_help'), params = {{ name = 'id' }} })
ESX.RegisterUsableItem('medikit', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('medikit', 1)
if not playersHealing[source] then
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('medikit', 1)
playersHealing[source] = true
TriggerClientEvent('esx_ambulancejob:useItem', source, 'medikit')
TriggerClientEvent('esx_ambulancejob:heal', _source, 'big')
TriggerClientEvent('esx:showNotification', _source, _U('used_medikit'))
Citizen.Wait(10000)
playersHealing[source] = nil
end
end)
ESX.RegisterUsableItem('bandage', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('bandage', 1)
if not playersHealing[source] then
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('bandage', 1)
playersHealing[source] = true
TriggerClientEvent('esx_ambulancejob:useItem', source, 'bandage')
TriggerClientEvent('esx_ambulancejob:heal', _source, 'small')
TriggerClientEvent('esx:showNotification', _source, _U('used_bandage'))
Citizen.Wait(10000)
playersHealing[source] = nil
end
end)
ESX.RegisterServerCallback('esx_ambulancejob:getDeathStatus', function(source, cb)