From 5d1c8bfe26582a584dfc68e9d25e1f363ad463eb Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Fri, 8 Dec 2023 21:28:25 +0100 Subject: [PATCH] refactor: bpt_bakerjob inventory implementation --- .github/CHANGELOG.md | 3 +- .../[bpt_addons]/bpt_bakerjob/README.md | 18 +++--- .../[bpt_addons]/bpt_bakerjob/client/main.lua | 15 ++++- .../[bpt_addons]/bpt_bakerjob/config.lua | 1 + .../[bpt_addons]/bpt_bakerjob/fxmanifest.lua | 2 +- .../[bpt_addons]/bpt_bakerjob/locales/en.lua | 5 ++ .../[bpt_addons]/bpt_bakerjob/locales/it.lua | 5 ++ .../[bpt_addons]/bpt_bakerjob/server/main.lua | 55 +++++++++++++++++++ .../[ox]/ox_inventory/data/stashes.lua | 19 ------- 9 files changed, 91 insertions(+), 32 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 6d62a3b85..09c3877e2 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -72,4 +72,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse 45. [SQL]: fix: es_extended.sql "addon_inventory" syntax error @bitpredator 46. [npwd]: fix: Warning: could not find @bitpredator 47. [server.cfg]: fix: Couldn't find resource @bitpredator -48. fix: No such export getSharedObject in resource es_extended @bitpredator \ No newline at end of file +48. fix: No such export getSharedObject in resource es_extended @bitpredator +49. [bpt_bakerjob]: refactor: bpt_bakerjob inventory implementation @bitpredator \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/README.md b/server-data/resources/[bpt_addons]/bpt_bakerjob/README.md index 646d6084b..9885bdfb1 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/README.md +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/README.md @@ -1,21 +1,23 @@ -# bpt_bakerjob +

bpt_bakerjob

+

Discord +📌 License 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. +You are not authorized to change the name of the resource and the resources within it. + +If you want to contribute you can open a pull request. -You are not authorized to sell this software (this is a free project). +You are not authorized to sell this software (this is free project). 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. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. -### 📌 License - -Copyright (C) 2022-2023 bitpredator - ## Info This Script will allow you to simulate the creation of sandwiches using flour and water diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua index fdef012a8..11b040121 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua @@ -165,7 +165,9 @@ end function OpenbakerActionsMenu() local elements = { - {unselectable = true, icon = "fas fa-baker", title = _U('baker')} + {unselectable = true, icon = "fas fa-baker", title = _U('baker')}, + {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 @@ -176,8 +178,15 @@ function OpenbakerActionsMenu() } 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_baker') + 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', 'baker', function(_, menu) menu.close() end) diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/config.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/config.lua index c36fede0f..7b4511a79 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/config.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/config.lua @@ -3,6 +3,7 @@ Config.DrawDistance = 10.0 -- How close do you need to be for the 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_bakerjob/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/fxmanifest.lua index 25b6f491b..ea0b6038e 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/fxmanifest.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/fxmanifest.lua @@ -5,7 +5,7 @@ game 'gta5' description 'bpt_bakerjob' 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_bakerjob/locales/en.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/locales/en.lua index bbca96c28..0aef6b517 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/locales/en.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/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_bakerjob/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/locales/it.lua index e2f89d189..09139d85a 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/locales/it.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/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 ritirato con successo!", diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua index a09a4db45..e72350b1c 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua @@ -22,4 +22,59 @@ ESX.RegisterServerCallback("bpt_bakerjob:SpawnVehicle", function(source, cb, mod TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1) end) cb() +end) + +RegisterNetEvent('bpt_bakerjob:getStockItem') +AddEventHandler('bpt_bakerjob:getStockItem', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'baker' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_baker', 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_bakerjob:getStockItem^7 (cheating)'):format(source)) + end +end) + +ESX.RegisterServerCallback('bpt_bakerjob:getStockItems', function(_, cb) + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_baker', function(inventory) + cb(inventory.items) + end) +end) + +RegisterNetEvent('bpt_bakerjob:putStockItems') +AddEventHandler('bpt_bakerjob:putStockItems', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + local sourceItem = xPlayer.getInventoryItem(itemName) + + if xPlayer.job.name == 'baker' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_baker', 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_bakerjob: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 ffc8fc546..cd4c07305 100644 --- a/server-data/resources/[ox]/ox_inventory/data/stashes.lua +++ b/server-data/resources/[ox]/ox_inventory/data/stashes.lua @@ -170,25 +170,6 @@ return { groups = {['cardealer'] = 0} }, - { - coords = vec3(2347.964844, 3139.292236, 48.202148), - target = { - loc = vec3(2347.964844, 3139.292236, 48.202148), - length = 0.6, - width = 1.8, - heading = 340, - minZ = 43.34, - maxZ = 44.74, - label = 'Storage' - }, - name = 'bakerlocker', - label = 'Baker', - owner = false, - slots = 70, - weight = 70000, - groups = {['baker'] = 0} - }, - { coords = vec3(-321.402191, -2785.134033, 5.201416), target = {