From 825685311da180c34cc89a1eccdd9fc55a7a07d9 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:16:58 +0100 Subject: [PATCH 1/3] refactor: bpt_importjob inventory implementation --- .github/CHANGELOG.md | 3 +- .../[bpt_addons]/bpt_importjob/README.md | 13 ++-- .../bpt_importjob/client/main.lua | 64 +++++++++++-------- .../[bpt_addons]/bpt_importjob/config.lua | 1 + .../[bpt_addons]/bpt_importjob/fxmanifest.lua | 2 +- .../[bpt_addons]/bpt_importjob/locales/it.lua | 10 ++- .../bpt_importjob/server/main.lua | 59 +++++++++++++++++ .../[ox]/ox_inventory/data/stashes.lua | 19 ------ 8 files changed, 118 insertions(+), 53 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 0c5c8428a..203bc7ce9 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -84,4 +84,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse 57. [bpt_dustman]: refactor: bpt_dustman inventory implementation @bitpredator 58. [bpt_farmer]: refactor: support for translations through local files @bitpredator 59. [bpt_fishermanjob]: refactor: bpt_fishermanjob inventory implementation @bitpredator -60. [bpt_hud]: chore: push for version 1.0.0 @bitpredator \ No newline at end of file +60. [bpt_hud]: chore: push for version 1.0.0 @bitpredator +61. [bpt_importjob]: refactor: bpt_importjob inventory implementation @bitpredator \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/README.md b/server-data/resources/[bpt_addons]/bpt_importjob/README.md index 1f227eda6..aa204e336 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/README.md +++ b/server-data/resources/[bpt_addons]/bpt_importjob/README.md @@ -1,16 +1,19 @@ -# bpt_importjob +

bpt_importjob

+

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. +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/. +You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/client/main.lua b/server-data/resources/[bpt_addons]/bpt_importjob/client/main.lua index a1926bee1..d6f1ab4d9 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/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, 'import') 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_importjob:SpawnVehicle", function() ESX.ShowNotification(_U('vehicle_spawned'), "success") end, element.value, {plate = "IMPO 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', 'import', vehicleProps) @@ -155,6 +157,10 @@ function DeleteJobVehicle() else if IsInAuthorizedVehicle() then ESX.Game.DeleteVehicle(CurrentActionData.vehicle) + + if Config.MaxInService ~= -1 then + TriggerServerEvent('esx_service:disableService', 'import') + end else ESX.ShowNotification(_U('only_import')) end @@ -163,7 +169,9 @@ end function OpenImportActionsMenu() local elements = { - {unselectable = true, icon = "fas fa-import", title = _U('import')} + {unselectable = true, icon = "fas fa-import", title = _U('import')}, + {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 +182,16 @@ function OpenImportActionsMenu() } end - ESX.OpenContext("right", elements, function(_,element) - local menu = { - {unselectable = true, "fas fa-import", title = _U('boss_actions')} - } - - if element.value == 'boss_actions' then - TriggerEvent('esx_society:openBossMenu', 'import', 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_import') + 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', 'import', function(_, menu) menu.close() end) end @@ -197,12 +208,12 @@ function OpenMobileImportActionsMenu() {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-import", 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 +287,11 @@ CreateThread(function() local blip = AddBlipForCoord(Config.Zones.ImportActions.Pos.x, Config.Zones.ImportActions.Pos.y, Config.Zones.ImportActions.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_import')) @@ -295,7 +306,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,15 +314,16 @@ 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) + v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, false, 2, v.Rotate, nil, nil, false) end else 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) + 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_importjob/config.lua b/server-data/resources/[bpt_addons]/bpt_importjob/config.lua index 981b7bda5..533c3787d 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/config.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/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 = 'it' +Config.OxInventory = ESX.GetConfig().OxInventory Config.AuthorizedVehicles = { {model = 'rumpo', label = 'Rumpo'} diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_importjob/fxmanifest.lua index 71306ec49..709c92078 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/fxmanifest.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/fxmanifest.lua @@ -4,7 +4,7 @@ game 'gta5' description 'bpt_importjob' 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_importjob/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua index f38730c1b..b9a84606d 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/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!", @@ -21,5 +26,8 @@ Locales['it'] = { ['no_players_near'] = 'nessun giocatore nelle vicinanze', ['boss_actions'] = 'Azioni del boss', ['blip_import'] = 'Import/Export', - ['import'] = 'import' + ['import'] = 'import', + -- billing + ['bill_amount'] = "importo della fattura", + ['confirm'] = "Conferma" } diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua index c6a1c38e6..5a08b5856 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/server/main.lua @@ -2,6 +2,10 @@ TriggerEvent('esx_society:registerSociety', 'import', 'Import', 'society_import' type = 'public' }) +if Config.MaxInService ~= -1 then + TriggerEvent('esx_service:activateService', 'import', Config.MaxInService) +end + ESX.RegisterServerCallback("bpt_importjob:SpawnVehicle", function(source, cb, model , props) local xPlayer = ESX.GetPlayerFromId(source) @@ -18,4 +22,59 @@ ESX.RegisterServerCallback("bpt_importjob:SpawnVehicle", function(source, cb, mo TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1) end) cb() +end) + +RegisterNetEvent('bpt_importjob:getStockItem') +AddEventHandler('bpt_importjob:getStockItem', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.job.name == 'import' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_import', 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_importjob:getStockItem^7 (cheating)'):format(source)) + end +end) + +ESX.RegisterServerCallback('bpt_importjob:getStockItems', function(_, cb) + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_import', function(inventory) + cb(inventory.items) + end) +end) + +RegisterNetEvent('bpt_importjob:putStockItems') +AddEventHandler('bpt_importjob:putStockItems', function(itemName, count) + local xPlayer = ESX.GetPlayerFromId(source) + local sourceItem = xPlayer.getInventoryItem(itemName) + + if xPlayer.job.name == 'import' then + TriggerEvent('esx_addoninventory:getSharedInventory', 'society_import', 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_importjob: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 160cdc12b..9d44bf736 100644 --- a/server-data/resources/[ox]/ox_inventory/data/stashes.lua +++ b/server-data/resources/[ox]/ox_inventory/data/stashes.lua @@ -94,25 +94,6 @@ return { groups = {['mechanic'] = 0} }, - { - coords = vec3(1019.459351, -2392.589111, 30.122314), - target = { - loc = vec3(1019.459351, -2392.589111, 30.122314), - length = 0.6, - width = 1.8, - heading = 340, - minZ = 43.34, - maxZ = 44.74, - label = 'Storage' - }, - name = 'importlocker', - label = 'Storage', - owner = false, - slots = 70, - weight = 70000, - groups = {['import'] = 0} - }, - { coords = vec3(-29.287910, -1103.182373, 26.415405), target = { From 9460ca197f829c28260f784bea0b12014de716eb Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:37:47 +0100 Subject: [PATCH 2/3] feat: bpt_importjob translation for the English language --- .../[bpt_addons]/bpt_importjob/locales/en.lua | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server-data/resources/[bpt_addons]/bpt_importjob/locales/en.lua diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/locales/en.lua b/server-data/resources/[bpt_addons]/bpt_importjob/locales/en.lua new file mode 100644 index 000000000..597efcfd7 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_importjob/locales/en.lua @@ -0,0 +1,34 @@ +Locales['en'] = { + -- cloakroom + ['cloakroom_menu'] = 'cloakroom', + ['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!", + ['store_veh'] = 'press [E] to deposit the vehicle', + ['spawn_veh'] = 'spawn vehicle', + ['spawnpoint_blocked'] = 'vehicle blocks the spawnpoint!', + ['only_import'] = 'you can only deposit company vehicles.', + ['empty_garage'] = 'no vehicles in the garage!', + ['taking_service'] = 'Take service: Gunsmith', + ['full_service'] = 'complete service: ', + ['amount_invalid'] = 'invalid amount', + ['press_to_open'] = 'press [E] to access the menu', + ['billing'] = 'billing', + ['billing_sent'] = 'the invoice has been posted!', + ['invoice_amount'] = 'invoice amount', + ['no_players_near'] = 'no players nearby', + ['boss_actions'] = 'Boss actions', + ['blip_import'] = 'Import/Export.', + ['import'] = 'Import', + -- billing + ['bill_amount'] = "Amount to bill..", + ['confirm'] = "Confirm" +} \ No newline at end of file From 6dee8b7442372d570c97c0c05f993cc7fae9bb7b Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:38:14 +0100 Subject: [PATCH 3/3] fix: corrected typo --- server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua index b9a84606d..9e49b509f 100644 --- a/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua +++ b/server-data/resources/[bpt_addons]/bpt_importjob/locales/it.lua @@ -8,7 +8,7 @@ Locales['it'] = { ['deposit_stock'] = 'Depositare', ['take_stock'] = 'Prendi', ['have_deposited'] = 'Hai depositato', - ['quantity_invalid'] = 'Qunatità non valida', + ['quantity_invalid'] = 'Quantità non valida', -- garage ['spawner_prompt'] = 'premi [E] per accedere al Garage.', ["vehicle_spawned"] = "Veicolo ritirato con successo!",