Skip to content

Commit

Permalink
Update v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Nov 17, 2023
1 parent 356b8d0 commit 24a830a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3
1.4
15 changes: 15 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
ESX = exports["es_extended"]:getSharedObject()

RegisterNetEvent('msk_weaponammoitem:checkAmmo')
AddEventHandler('msk_weaponammoitem:checkAmmo', function(item, data)
local playerPed = PlayerPedId()
local hash = GetSelectedPedWeapon(playerPed)

if IsPedArmed(playerPed, 4) then
if hash then
if not Config.AmmoPacks[item] then return print(('[ITEM] [Add Ammo] Item ^3%s^0 is not configured in config.lua'):format(item)) end
local weapon = ESX.GetWeaponFromHash(hash)

TriggerServerEvent('msk_weaponammoitem:addWeaponAmmo', weapon.name, item, data)
end
end
end)

CreateThread(function()
while true do
local sleep = 100 -- Please don't touch otherwise you will break the Script
Expand Down
10 changes: 10 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ Config = {}
----------------------------------------------------------------
Config.VersionChecker = true
----------------------------------------------------------------
Config.AmmoPacks = {
-- Upload this item into your database!

['9mm_magazine'] = {item = '9mm', amount = 12},
['12gauge_magazine'] = {item = '12gauge', amount = 25},
['556mm_magazine'] = {item = '556mm', amount = 30},
['762mm_magazine'] = {item = '762mm', amount = 30},
['68kal_magazine'] = {item = '68kal', amount = 30},
}

Config.Ammunition = {
['9mm'] = { -- Upload this item into your database!
'WEAPON_PISTOL',
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_weaponammoitems'
description 'Weapon Ammunition with Items'
version '1.3'
version '1.4'

lua54 'yes'

Expand Down
26 changes: 26 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
ESX = exports["es_extended"]:getSharedObject()

for item, v in pairs(Config.AmmoPacks) do
ESX.RegisterUsableItem(item, function(playerId)
local src = playerId
local xPlayer = ESX.GetPlayerFromId(src)

xPlayer.triggerEvent('msk_weaponammoitem:checkAmmo', item, v)
end)
end

RegisterNetEvent('msk_weaponammoitem:addWeaponAmmo')
AddEventHandler('msk_weaponammoitem:addWeaponAmmo', function(weaponName, item, data)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local hasItem = xPlayer.getInventoryItem(item)
if not hasItem or hasItem.count == 0 then return end

xPlayer.removeInventoryItem(item, 1)
xPlayer.addInventoryItem(data.item, data.amount)

local hasAmmo = xPlayer.getInventoryItem(data.item)
if not hasAmmo or hasAmmo.count == 0 then return end

xPlayer.updateWeaponAmmo(weaponName, hasAmmo.count + data.amount)
SetPedAmmo(GetPlayerPed(xPlayer.source), joaat(weaponName), hasAmmo.count + data.amount)
end)

RegisterNetEvent('msk_weaponammoitem:updateWeaponAmmo')
AddEventHandler('msk_weaponammoitem:updateWeaponAmmo', function(item, weaponName, isShooting)
local src = source
Expand Down

0 comments on commit 24a830a

Please sign in to comment.