Skip to content

Commit

Permalink
Merge pull request #580 from bitpredator/dev
Browse files Browse the repository at this point in the history
refactor: bpt_bakerjob inventory implementation
  • Loading branch information
bitpredator authored Dec 8, 2023
2 parents c035067 + 5d1c8bf commit 50bdd8b
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
48. fix: No such export getSharedObject in resource es_extended @bitpredator
49. [bpt_bakerjob]: refactor: bpt_bakerjob inventory implementation @bitpredator
18 changes: 10 additions & 8 deletions server-data/resources/[bpt_addons]/bpt_bakerjob/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# bpt_bakerjob
<h1 align='center'>bpt_bakerjob</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

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

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

0 comments on commit 50bdd8b

Please sign in to comment.