Skip to content

Commit

Permalink
refactor: bpt_ammujob inventory implementation
Browse files Browse the repository at this point in the history
Implementation of company inventory directly in bpt_ammujob source code without having to use ox_inventory for creating it.
  • Loading branch information
bitpredator committed Dec 4, 2023
1 parent 29c8f2d commit f1c8e7e
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
43. [EUP]: delete: removed package [EUP] @bitpredator
44. [bpt_ammujob]: refactor: bpt_ammujob inventory implementation @bitpredator
7 changes: 5 additions & 2 deletions server-data/resources/[bpt_addons]/bpt_ammujob/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# bpt_ammujob
<h1 align='center'>bpt_ammujob</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

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.
Expand Down
15 changes: 12 additions & 3 deletions server-data/resources/[bpt_addons]/bpt_ammujob/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions server-data/resources/[bpt_addons]/bpt_ammujob/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 5 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_ammujob/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
5 changes: 5 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_ammujob/locales/it.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down
55 changes: 55 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_ammujob/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
38 changes: 0 additions & 38 deletions server-data/resources/[ox]/ox_inventory/data/stashes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit f1c8e7e

Please sign in to comment.