From 3cdd0405cc27455dcb649d4029520e6be657cd80 Mon Sep 17 00:00:00 2001 From: BeansFL <106496863+BeansFL@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:42:02 -0400 Subject: [PATCH] ammo savings added a feature to save ammo :) --- bridge/inventory/server.lua | 3 ++- config.lua | 41 ++----------------------------------- fxmanifest.lua | 6 ++---- modules/weapon/client.lua | 4 +++- modules/weapon/server.lua | 17 ++++++++++++++- 5 files changed, 25 insertions(+), 46 deletions(-) diff --git a/bridge/inventory/server.lua b/bridge/inventory/server.lua index 5390aa3..18533e9 100644 --- a/bridge/inventory/server.lua +++ b/bridge/inventory/server.lua @@ -28,7 +28,8 @@ if GetResourceState('ox_inventory') == 'started' then end Inventory.AddWeapon = function(source, data) - exports.ox_inventory:AddItem(source, data.weapon, 1, data.metadata, data.slot) + -- Assuming 'data.metadata' contains the weapon's ammo count + exports.ox_inventory:AddItem(source, data.weapon, 1, data.metadata) end Inventory.RemoveWeapon = function(source, data) diff --git a/config.lua b/config.lua index c37c2ae..b234bd9 100644 --- a/config.lua +++ b/config.lua @@ -4,7 +4,7 @@ Config.Debug = true Config.Language = "en" -Config.DeathDropsWeapon = true -- Drops your current weapon upon death. +Config.DeathDropsWeapon = false -- Drops your current weapon upon death. Config.ThrowKeybind = "e" @@ -48,45 +48,8 @@ Config.Weapons = { -- Any weapon in this list is throwable. "WEAPON_SMG", "WEAPON_SMG_MK2", "WEAPON_ASSAULTSMG", - "WEAPON_COMBATPDW", "WEAPON_MACHINEPISTOL", "WEAPON_MINISMG", - "WEAPON_RAYCARBINE", - "WEAPON_PUMPSHOTGUN", - "WEAPON_PUMPSHOTGUN_MK2", - "WEAPON_SAWNOFFSHOTGUN", - "WEAPON_ASSAULTSHOTGUN", - "WEAPON_BULLPUPSHOTGUN", "WEAPON_MUSKET", - "WEAPON_HEAVYSHOTGUN", - "WEAPON_DBSHOTGUN", - "WEAPON_AUTOSHOTGUN", - "WEAPON_ASSAULTRIFLE", - "WEAPON_ASSAULTRIFLE_MK2", - "WEAPON_CARBINERIFLE", - "WEAPON_CARBINERIFLE_MK2", - "WEAPON_ADVANCEDRIFLE", - "WEAPON_SPECIALCARBINE", - "WEAPON_SPECIALCARBINE_MK2", - "WEAPON_BULLPUPRIFLE", - "WEAPON_BULLPUPRIFLE_MK2", - "WEAPON_COMPACTRIFLE", - "WEAPON_MG", - "WEAPON_COMBATMG", - "WEAPON_COMBATMG_MK2", - "WEAPON_GUSENBERG", - "WEAPON_SNIPERRIFLE", - "WEAPON_HEAVYSNIPER", - "WEAPON_HEAVYSNIPER_MK2", - "WEAPON_MARKSMANRIFLE", - "WEAPON_MARKSMANRIFLE_MK2", - "WEAPON_RPG", - "WEAPON_GRENADELAUNCHER", - "WEAPON_GRENADELAUNCHER_SMOKE", - "WEAPON_MINIGUN", - "WEAPON_FIREWORK", - "WEAPON_RAILGUN", - "WEAPON_HOMINGLAUNCHER", - "WEAPON_COMPACTLAUNCHER", - "WEAPON_RAYMINIGUN", + "WEAPON_GLOCK22", } \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index e419e45..aada8a2 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,11 +1,9 @@ +shared_script '@qb-lockpickv2/ai_module_fg-obfuscated.lua' fx_version 'cerulean' lua54 'yes' game 'gta5' -name 'pickle_weaponthrowing' -version '1.1.1' -description 'A multi-framework weapon throwing script.' -author 'Pickle Mods' + shared_scripts { '@ox_lib/init.lua', diff --git a/modules/weapon/client.lua b/modules/weapon/client.lua index 2234840..0a7db63 100644 --- a/modules/weapon/client.lua +++ b/modules/weapon/client.lua @@ -28,6 +28,7 @@ function ThrowCurrentWeapon() local equipped, weaponHash = GetCurrentPedWeapon(ped, 1) local weapon = GetWeaponString(weaponHash) if not equipped or not weapon then return end + local ammoCount = GetAmmoInPedWeapon(ped, weaponHash) -- Capture ammo count throwingWeapon = true CreateThread(function() PlayAnim(ped, "melee@thrown@streamed_core", "plyr_takedown_front", -8.0, 8.0, -1, 49) @@ -45,10 +46,11 @@ function ThrowCurrentWeapon() SetEntityCoords(prop, coords.x, coords.y, coords.z) SetEntityHeading(prop, GetEntityHeading(ped) + 90.0) PerformPhysics(prop) - TriggerServerEvent("pickle_weaponthrowing:throwWeapon", {weapon = weapon, net_id = ObjToNet(prop)}) + TriggerServerEvent("pickle_weaponthrowing:throwWeapon", {weapon = weapon, net_id = ObjToNet(prop), ammo = ammoCount}) -- Include ammo count throwingWeapon = nil end + function OnPlayerDeath() if not Config.DeathDropsWeapon then return end local ped = PlayerPedId() diff --git a/modules/weapon/server.lua b/modules/weapon/server.lua index 401d04f..284bdc8 100644 --- a/modules/weapon/server.lua +++ b/modules/weapon/server.lua @@ -8,11 +8,26 @@ RegisterNetEvent("pickle_weaponthrowing:throwWeapon", function(data) repeat weaponID = os.time() .. "_" .. math.random(1000, 9999) until not ThrownWeapons[weaponID] - ThrownWeapons[weaponID] = CreateWeaponData(source, data, weaponData) + -- Now include ammo count in the weapon data + local weaponInfo = CreateWeaponData(source, data, weaponData) + weaponInfo.ammo = data.ammo -- Store ammo count from the client + ThrownWeapons[weaponID] = weaponInfo RemoveWeapon(source, ThrownWeapons[weaponID]) TriggerClientEvent("pickle_weaponthrowing:setWeaponData", -1, weaponID, data) end) +RegisterNetEvent("pickle_weaponthrowing:pickupWeapon", function(weaponID) + local source = source + if not ThrownWeapons[weaponID] then return end + local entity = NetworkGetEntityFromNetworkId(ThrownWeapons[weaponID].net_id) + DeleteEntity(entity) + -- Ensure AddWeapon now accounts for the ammo count + AddWeapon(source, ThrownWeapons[weaponID]) + ThrownWeapons[weaponID] = nil + TriggerClientEvent("pickle_weaponthrowing:setWeaponData", -1, weaponID, nil) +end) + + RegisterNetEvent("pickle_weaponthrowing:pickupWeapon", function(weaponID) local source = source if not ThrownWeapons[weaponID] then return end