From f1c8e7e357ceb7960f463043b9d8bbe01d0fe310 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:43:44 +0100 Subject: [PATCH] refactor: bpt_ammujob inventory implementation Implementation of company inventory directly in bpt_ammujob source code without having to use ox_inventory for creating it. --- .github/CHANGELOG.md | 3 +- .../[bpt_addons]/bpt_ammujob/README.md | 7 ++- .../[bpt_addons]/bpt_ammujob/client/main.lua | 15 ++++- .../[bpt_addons]/bpt_ammujob/config.lua | 1 + .../[bpt_addons]/bpt_ammujob/fxmanifest.lua | 2 +- .../[bpt_addons]/bpt_ammujob/locales/en.lua | 5 ++ .../[bpt_addons]/bpt_ammujob/locales/it.lua | 5 ++ .../[bpt_addons]/bpt_ammujob/server/main.lua | 55 +++++++++++++++++++ .../[ox]/ox_inventory/data/stashes.lua | 38 ------------- 9 files changed, 86 insertions(+), 45 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3213ae1e9..481f0ac7f 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -67,4 +67,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse 41. [ox_inventory\data\shops.lua]: chore: the possibility of purchasing the radio has been added @bitpredator [ox_inventory\data\stashes.lua]: fix: removed the inventory for the taxi job as it was included in the esx_taxijob resource @bitpredator 42. [esx_joblisting]: refactor: correct the good year for the license + varius fix @bitpredator -43. [EUP]: delete: removed package [EUP] @bitpredator \ No newline at end of file +43. [EUP]: delete: removed package [EUP] @bitpredator +44. [bpt_ammujob]: refactor: bpt_ammujob inventory implementation @bitpredator \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/README.md b/server-data/resources/[bpt_addons]/bpt_ammujob/README.md index 86bd8d9b3..a8ddc397a 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/README.md +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/README.md @@ -1,8 +1,11 @@ -# bpt_ammujob +

bpt_ammujob

+

Discord Copyright (C) 2022-2023 bitpredator -This program is a project for the fivem community, you have legal permission to distribute and / or modify it only if you have forked this repository, if it is not a fork repository, the version will be removed from the DMCA request. +This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. + +This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. ATTENTION: You are not authorized to change the name of the resource and the resources within it. diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/client/main.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/client/main.lua index d30489240..25fa39902 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/client/main.lua @@ -169,7 +169,9 @@ end function OpenAmmuActionsMenu() local elements = { - {unselectable = true, icon = "fas fa-ammu", title = _U('ammu')} + {unselectable = true, icon = "fas fa-ammu", title = _U('ammu')}, + {icon = "fas fa-box",title = _U('deposit_stock'),value = 'put_stock'}, + {icon = "fas fa-box", title = _U('take_stock'), value = 'get_stock'} } if Config.EnablePlayerManagement and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.grade_name == 'boss' then @@ -180,8 +182,15 @@ function OpenAmmuActionsMenu() } end - ESX.OpenContext("right", elements, function(_,element) - if element.value == 'boss_actions' then + ESX.OpenContext("right", elements, function(_, element) + if Config.OxInventory and (element.value == 'put_stock' or element.value == 'get_stock') then + exports.ox_inventory:openInventory('stash', 'society_ammu') + return ESX.CloseContext() + elseif element.value == 'put_stock' then + OpenPutStocksMenu() + elseif element.value == 'get_stock' then + OpenGetStocksMenu() + elseif element.value == 'boss_actions' then TriggerEvent('esx_society:openBossMenu', 'ammu', function(_, menu) menu.close() end) diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/config.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/config.lua index 5db2782e4..5ae93e2c9 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/config.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/config.lua @@ -4,6 +4,7 @@ Config.MaxInService = -1 -- How much people can be in service at o Config.EnablePlayerManagement = true -- Enable society managing. Config.EnableSocietyOwnedVehicles = false Config.Locale = 'en' +Config.OxInventory = ESX.GetConfig().OxInventory Config.AuthorizedVehicles = { {model = 'rumpo', label = 'Rumpo'} diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/fxmanifest.lua index 2ba7961e5..2f518d67e 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/fxmanifest.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/fxmanifest.lua @@ -5,7 +5,7 @@ game 'gta5' description 'bpt_ammunation job' author 'bitpredator' lua54 'yes' -version '0.0.4' +version '1.0.0' shared_script '@es_extended/imports.lua' diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/locales/en.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/locales/en.lua index 591812113..3cad3db87 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/locales/en.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/locales/en.lua @@ -4,6 +4,11 @@ Locales['en'] = { ['cloakroom_prompt'] = 'press [E] to access the cloakroom.', ['wear_citizen'] = 'civilian clothing', ['wear_work'] = 'work clothes', + -- Inventory + ['deposit_stock'] = 'Deposit stock', + ['take_stock'] = 'Take stock', + ['have_deposited'] = 'Have deposited', + ['quantity_invalid'] = 'Quantity invelid', -- garage ['spawner_prompt'] = 'press [E] to access the garage.', ["vehicle_spawned"] = "vehicle spawned successfully!", diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/locales/it.lua index 99f689fc5..38f6a4436 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/locales/it.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/locales/it.lua @@ -4,6 +4,11 @@ Locales['it'] = { ['cloakroom_prompt'] = 'premi [E] per accedere al guardaroba.', ['wear_citizen'] = 'abbigliamento civile', ['wear_work'] = 'abiti da lavoro', + -- Inventory + ['deposit_stock'] = 'Depositare', + ['take_stock'] = 'Prendi', + ['have_deposited'] = 'Hai depositato', + ['quantity_invalid'] = 'Qunatità non valida', -- garage ['spawner_prompt'] = 'premi [E] per accedere al garage.', ["vehicle_spawned"] = "veicolo generato con successo!", diff --git a/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua index 21de201b9..4169b78a1 100644 --- a/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua @@ -22,4 +22,59 @@ ESX.RegisterServerCallback("bpt_ammujob:SpawnVehicle", function(source, cb, mode TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1) end) cb() +end) + +RegisterNetEvent('bpt_ammujob:getStockItem') +AddEventHandler('bpt_ammujob:getStockItem', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'ammu' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ammu', function(inventory) + local item = inventory.getItem(itemName) + + -- is there enough in the society? + if count > 0 and item.count >= count then + -- can the player carry the said amount of x item? + if xPlayer.canCarryItem(itemName, count) then + inventory.removeItem(itemName, count) + xPlayer.addInventoryItem(itemName, count) + xPlayer.showNotification(_U('have_withdrawn', count, item.label)) + else + xPlayer.showNotification(_U('player_cannot_hold')) + end + else + xPlayer.showNotification(_U('quantity_invalid')) + end + end) + else + print(('[^3WARNING^7] Player ^5%s^7 attempted ^5bpt_ammujob:getStockItem^7 (cheating)'):format(source)) + end +end) + +ESX.RegisterServerCallback('bpt_ammujob:getStockItems', function(_, cb) + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ammu', function(inventory) + cb(inventory.items) + end) +end) + +RegisterNetEvent('bpt_ammujob:putStockItems') +AddEventHandler('bpt_ammujob:putStockItems', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + local sourceItem = xPlayer.getInventoryItem(itemName) + + if xPlayer.job.name == 'ammu' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ammu', function(inventory) + local item = inventory.getItem(itemName) + + if sourceItem.count >= count and count > 0 then + xPlayer.removeInventoryItem(itemName, count) + inventory.addItem(itemName, count) + xPlayer.showNotification(_U('have_deposited', count, item.label)) + else + xPlayer.showNotification(_U('quantity_invalid')) + end + end) + else + print(('[^3WARNING^7] Player ^5%s^7 attempted ^5bpt_ammujob:putStockItems^7 (cheating)'):format(source)) + end end) \ No newline at end of file diff --git a/server-data/resources/[ox]/ox_inventory/data/stashes.lua b/server-data/resources/[ox]/ox_inventory/data/stashes.lua index 892910ddb..ffc8fc546 100644 --- a/server-data/resources/[ox]/ox_inventory/data/stashes.lua +++ b/server-data/resources/[ox]/ox_inventory/data/stashes.lua @@ -37,25 +37,6 @@ return { groups = {['ambulance'] = 0} }, - { - coords = vec3(810.026367, -2159.353760, 29.616821), - target = { - loc = vec3(810.026367, -2159.353760, 29.616821), - length = 0.6, - width = 1.8, - heading = 340, - minZ = 43.34, - maxZ = 44.74, - label = 'Storage' - }, - name = 'ammulocker', - label = 'Storage', - owner = false, - slots = 70, - weight = 70000, - groups = {['ammu'] = 0} - }, - { coords = vec3(129.507690, -1281.454956, 29.263062), target = { @@ -208,25 +189,6 @@ return { groups = {['baker'] = 0} }, - { - coords = vec3(206.241760, -1395.758301, 30.577271), - target = { - loc = vec3(206.241760, -1395.758301, 30.577271), - length = 0.6, - width = 1.8, - heading = 340, - minZ = 43.34, - maxZ = 44.74, - label = 'Storage' - }, - name = 'drivinglocker', - label = 'driving', - owner = false, - slots = 70, - weight = 70000, - groups = {['driving'] = 0} - }, - { coords = vec3(-321.402191, -2785.134033, 5.201416), target = {