Improved ammo handling

This commit is contained in:
ElPumpo
2018-06-22 22:25:34 +02:00
parent 5bf8dc2b80
commit 3de26d020b
5 changed files with 65 additions and 57 deletions
+16 -9
View File
@@ -173,20 +173,27 @@ end)
RegisterNetEvent('esx:addWeapon')
AddEventHandler('esx:addWeapon', function(weaponName, ammo)
local playerPed = GetPlayerPed(-1)
local weaponHash = GetHashKey(weaponName)
local playerPed = GetPlayerPed(-1)
local weaponHash = GetHashKey(weaponName)
GiveWeaponToPed(playerPed, weaponHash, ammo, false, false)
SetPedAmmo(playerPed, weaponHash, ammo) -- remove leftover ammo
GiveWeaponToPed(playerPed, weaponHash, ammo, false, false)
--AddAmmoToPed(playerPed, weaponHash, ammo) possibly not needed
end)
RegisterNetEvent('esx:removeWeapon')
AddEventHandler('esx:removeWeapon', function(weaponName)
local playerPed = GetPlayerPed(-1)
local weaponHash = GetHashKey(weaponName)
AddEventHandler('esx:removeWeapon', function(weaponName, ammo)
local playerPed = GetPlayerPed(-1)
local weaponHash = GetHashKey(weaponName)
RemoveWeaponFromPed(playerPed, weaponHash)
SetPedAmmo(playerPed, weaponHash, 0) -- remove leftover ammo
RemoveWeaponFromPed(playerPed, weaponHash)
if ammo then
local pedAmmo = GetAmmoInPedWeapon(playerPed, weaponHash)
local finalAmmo = math.floor(pedAmmo - ammo)
SetPedAmmo(playerPed, weaponHash, finalAmmo)
else
SetPedAmmo(playerPed, weaponHash, 0) -- remove leftover ammo
end
end)
-- Commands