From 4863082a60f12d0d60a0a1922ccc937b0caa2bbd Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:39:19 +0100 Subject: [PATCH] refactor: bpt_fishermanjob inventory implementation --- .github/CHANGELOG.md | 3 +- .../[bpt_addons]/bpt_fisherman/README.md | 25 +++++--- .../bpt_fisherman/client/main.lua | 56 ++++++++++-------- .../[bpt_addons]/bpt_fisherman/config.lua | 3 +- .../[bpt_addons]/bpt_fisherman/fxmanifest.lua | 4 +- .../[bpt_addons]/bpt_fisherman/locales/en.lua | 17 ++++-- .../[bpt_addons]/bpt_fisherman/locales/it.lua | 15 +++-- .../bpt_fisherman/server/main.lua | 59 +++++++++++++++++++ .../[ox]/ox_inventory/data/stashes.lua | 19 ------ 9 files changed, 138 insertions(+), 63 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 104e71196..20ad7fe37 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -82,4 +82,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse 55. [bpt_crafting]: Refactor: created support for translations natively through local files @bitpredator 56. [bpt_deliveries]: feat + chore: updated readme file + creation of Italian translation @bitpredator 57. [bpt_dustman]: refactor: bpt_dustman inventory implementation @bitpredator -58. [bpt_farmer]: refactor: support for translations through local files @bitpredator \ No newline at end of file +58. [bpt_farmer]: refactor: support for translations through local files @bitpredator +59. [bpt_fishermanjob]: refactor: bpt_fishermanjob inventory implementation @bitpredator \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/README.md b/server-data/resources/[bpt_addons]/bpt_fisherman/README.md index 49034a16b..213a53f2a 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/README.md +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/README.md @@ -1,12 +1,23 @@ -This program is a project for the fivem community, you have legal permission to distribute and / or modify it . -ATTENTION: You are not authorized to change the name of the resources present within it. -You are not authorized to sell this software (this is a free project). +
Discord + +📌 License +Copyright (C) 2022-2023 bitpredator + +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. + +If you want to contribute you can open a pull request. + +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 - -EMPIRETOWN - FRAMEWORK FOR FIVEM -Copyright (C) 2023 bitpredator \ No newline at end of file +## Info +This Script will allow you to simulate the creation of sandwiches using flour and water \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/client/main.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/client/main.lua index 53158dcd4..975314f06 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/client/main.lua @@ -60,7 +60,7 @@ function OpenCloakroom() end end) end - ESX.CloseContext() + ESX.CloseContext() end, function() CurrentAction = 'cloakroom' CurrentActionMsg = _U('cloakroom_prompt') @@ -76,7 +76,7 @@ function OpenVehicleSpawnerMenu() if Config.EnableSocietyOwnedVehicles then ESX.TriggerServerCallback('esx_society:getVehiclesInGarage', function(vehicles) - if #vehicles == 0 then + if #vehicles == 0 then ESX.ShowNotification(_U('empty_garage')) return end @@ -95,7 +95,7 @@ function OpenVehicleSpawnerMenu() return end - if element.value == nil then + if element.value == nil then print("ERROR: Context menu clicked item value is nil!") return end @@ -112,7 +112,8 @@ function OpenVehicleSpawnerMenu() end) end, 'fisherman') else -- not society vehicles - if #Config.AuthorizedVehicles == 0 then + + if #Config.AuthorizedVehicles == 0 then ESX.ShowNotification(_U('empty_garage')) return end @@ -130,10 +131,12 @@ function OpenVehicleSpawnerMenu() ESX.ShowNotification(_U('spawnpoint_blocked')) return end - if element.value == nil then + + if element.value == nil then print("ERROR: Context menu clicked item value is nil!") return end + ESX.TriggerServerCallback("bpt_fishermanjob:SpawnVehicle", function() ESX.ShowNotification(_U('vehicle_spawned'), "success") end, element.value, {plate = "FISH JOB"}) @@ -147,7 +150,6 @@ function OpenVehicleSpawnerMenu() end function DeleteJobVehicle() - if Config.EnableSocietyOwnedVehicles then local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle) TriggerServerEvent('esx_society:putVehicleInGarage', 'fisherman', vehicleProps) @@ -163,7 +165,9 @@ end function OpenFishermanActionsMenu() local elements = { - {unselectable = true, icon = "fas fa-fisherman", title = _U('fisherman')} + {unselectable = true, icon = "fas fa-fisherman", title = _U('fisherman')}, + {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 @@ -174,13 +178,16 @@ function OpenFishermanActionsMenu() } end - ESX.OpenContext("right", elements, function(_,element) - local menu = { - {unselectable = true, "fas fa-fisherman", title = _U('boss_actions')} - } - - if element.value == 'boss_actions' then - TriggerEvent('esx_society:openBossMenu', 'fisherman', function() + 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_fisherman') + 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', 'fisherman', function(_, menu) menu.close() end) end @@ -197,12 +204,12 @@ function OpenMobileFishermanActionsMenu() {icon = "fas fa-scroll", title = _U('billing'), value = "billing"}, } - ESX.OpenContext("right", elements, function(_,element) + ESX.OpenContext("right", elements, function(_, element) if element.value == "billing" then local elements2 = { {unselectable = true, icon = "fas fa-fisherman", title = element.title}, - {title = "Amount", input = true, inputType = "number", inputMin = 1, inputMax = 250000, inputPlaceholder = "Amount to bill.."}, - {icon = "fas fa-check-double", title = "Confirm", value = "confirm"} + {title = _U('amount'), input = true, inputType = "number", inputMin = 1, inputMax = 250000, inputPlaceholder = _U('bill_amount')}, + {icon = "fas fa-check-double", title = _U('confirm'), value = "confirm"} } ESX.OpenContext("right", elements2, function(menu2) @@ -276,11 +283,11 @@ CreateThread(function() local blip = AddBlipForCoord(Config.Zones.FishermanActions.Pos.x, Config.Zones.FishermanActions.Pos.y, Config.Zones.FishermanActions.Pos.z) - SetBlipSprite(blip, 478) - SetBlipDisplay(blip, 4) - SetBlipScale(blip, 1.0) - SetBlipColour(blip, 21) - SetBlipAsShortRange(blip, true) + SetBlipSprite(blip, 478) + SetBlipDisplay(blip, 4) + SetBlipScale(blip, 1.0) + SetBlipColour(blip, 21) + SetBlipAsShortRange(blip, true) BeginTextCommandSetBlipName('STRING') AddTextComponentSubstringPlayerName(_U('blip_fisherman')) @@ -295,7 +302,7 @@ CreateThread(function() local coords = GetEntityCoords(PlayerPedId()) local isInMarker, currentZone = false - local inVeh = IsPedInAnyVehicle(PlayerPedId()) + local inVeh = IsPedInAnyVehicle(PlayerPedId()) for k, v in pairs(Config.Zones) do local zonePos = vector3(v.Pos.x, v.Pos.y, v.Pos.z) @@ -303,7 +310,7 @@ CreateThread(function() if v.Type ~= -1 and distance < Config.DrawDistance then sleep = 0 - if k == "VehicleDeleter" then + if k == "VehicleDeleter" then if inVeh then DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, false, 2, v.Rotate, nil, nil, false) @@ -312,6 +319,7 @@ CreateThread(function() DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, false, 2, v.Rotate, nil, nil, false) end + end if distance < v.Size.x then diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/config.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/config.lua index 52f3f7566..aef7bc60f 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/config.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/config.lua @@ -2,7 +2,8 @@ Config = {} Config.DrawDistance = 10.0 -- How close do you need to be for the markers to be drawn (in GTA units). Config.EnablePlayerManagement = true -- Enable society managing. Config.EnableSocietyOwnedVehicles = false -Config.Locale = 'it' +Config.Locale = 'en' +Config.OxInventory = ESX.GetConfig().OxInventory Config.AuthorizedVehicles = { {model = 'rumpo', label = 'Rumpo'} diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/fxmanifest.lua index 38345b786..05e3f9ce1 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/fxmanifest.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/fxmanifest.lua @@ -4,7 +4,7 @@ game 'gta5' description 'bpt_fishermanjob' lua54 'yes' -version '0.0.5' +version '1.0.0' shared_script '@es_extended/imports.lua' @@ -22,4 +22,4 @@ server_scripts { 'server/main.lua' } -dependency 'es_extended' +dependency 'es_extended' \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/locales/en.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/locales/en.lua index b6de33929..6f8d35e2c 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/locales/en.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/locales/en.lua @@ -2,8 +2,13 @@ Locales['en'] = { -- cloakroom ['cloakroom_menu'] = 'cloakroom', ['cloakroom_prompt'] = 'press [E] to access the cloakroom.', - ['wear_citizen'] = 'ivilian clothes', + ['wear_citizen'] = 'civilian clothes', ['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 picked up successfully!", @@ -13,11 +18,13 @@ Locales['en'] = { ['only_fisherman'] = 'you can only deposit company vehicles.', ['amount_invalid'] = 'invalid amount', ['press_to_open'] = 'press [E] to access the menu', - ['billing'] = 'biling', - ['billing_sent'] = 'the invoice has been posted!', ['invoice_amount'] = 'invoice amount', ['no_players_near'] = 'no players nearby', ['boss_actions'] = 'Boss actions', ['blip_fisherman'] = 'Fisherman', - ['fisherman'] = 'fisherman' -} + ['fisherman'] = 'fisherman', + -- billing + ['bill_amount'] = "Amount to bill..", + ['confirm'] = "Confirm", + ['amount'] = 'amount' +} \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/locales/it.lua index d9c04bece..16b334d6e 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/locales/it.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/locales/it.lua @@ -4,6 +4,11 @@ Locales['it'] = { ['cloakroom_prompt'] = 'premi [E] per accedere al guardaroba.', ['wear_citizen'] = 'abiti civili', ['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!", @@ -13,11 +18,13 @@ Locales['it'] = { ['only_fisherman'] = 'puoi solo depositare veicoli aziendali.', ['amount_invalid'] = 'importo non valido', ['press_to_open'] = 'premi [E] per accedere al menu', - ['billing'] = 'fattura', - ['billing_sent'] = 'la fattura è stata registrata!', ['invoice_amount'] = 'importo della fattura', ['no_players_near'] = 'nessun giocatore nelle vicinanze', ['boss_actions'] = 'Azioni del boss', ['blip_fisherman'] = 'Fisherman', - ['fisherman'] = 'fisherman' -} + ['fisherman'] = 'fisherman', + -- billing + ['bill_amount'] = "importo della fattura", + ['confirm'] = "Conferma", + ['amount'] = "Importo" +} \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua b/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua index 1f03dd4de..2a72e1952 100644 --- a/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua @@ -2,6 +2,10 @@ TriggerEvent('esx_society:registerSociety', 'fisherman', 'Fisherman', 'society_f type = 'public' }) +if Config.MaxInService ~= -1 then + TriggerEvent('esx_service:activateService', 'fisherman', Config.MaxInService) +end + ESX.RegisterServerCallback("bpt_fishermanjob:SpawnVehicle", function(source, cb, model , props) local xPlayer = ESX.GetPlayerFromId(source) @@ -18,4 +22,59 @@ ESX.RegisterServerCallback("bpt_fishermanjob:SpawnVehicle", function(source, cb, TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1) end) cb() +end) + +RegisterNetEvent('bpt_fishermanjob:getStockItem') +AddEventHandler('bpt_fishermanjob:getStockItem', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'fisherman' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_fisherman', 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_fishermanjob:getStockItem^7 (cheating)'):format(source)) + end +end) + +ESX.RegisterServerCallback('bpt_fishermanjob:getStockItems', function(_, cb) + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_fisherman', function(inventory) + cb(inventory.items) + end) +end) + +RegisterNetEvent('bpt_fishermanjob:putStockItems') +AddEventHandler('bpt_fishermanjob:putStockItems', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + local sourceItem = xPlayer.getInventoryItem(itemName) + + if xPlayer.job.name == 'fisherman' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_fisherman', 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_fishermanjob: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 dbcec35bf..160cdc12b 100644 --- a/server-data/resources/[ox]/ox_inventory/data/stashes.lua +++ b/server-data/resources/[ox]/ox_inventory/data/stashes.lua @@ -131,23 +131,4 @@ return { weight = 70000, groups = {['cardealer'] = 0} }, - - { - coords = vec3(-321.402191, -2785.134033, 5.201416), - target = { - loc = vec3(-321.402191, -2785.134033, 5.201416), - length = 0.6, - width = 1.8, - heading = 340, - minZ = 43.34, - maxZ = 44.74, - label = 'Storage' - }, - name = 'fishermanlocker', - label = 'fisherman', - owner = false, - slots = 70, - weight = 70000, - groups = {['fisherman'] = 0} - }, }