From 7b614c3c7ba45e89f08544597e8c38da508a9f21 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 24 Feb 2019 12:44:06 +0100 Subject: [PATCH] Bandage & Medkit animations upon usage, closes #116 --- client/job.lua | 6 ++++-- client/main.lua | 36 ++++++++++++++++++++++++++++++++++++ server/main.lua | 29 +++++++++++++++++++---------- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/client/job.lua b/client/job.lua index 7da6270a..e9407f23 100644 --- a/client/job.lua +++ b/client/job.lua @@ -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) diff --git a/client/main.lua b/client/main.lua index 3a51e192..d2cb053e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -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 diff --git a/server/main.lua b/server/main.lua index 347f334d..52c8e52a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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)