Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: bpt_ballasjob inventory implementation #582

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse
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
49. [bpt_bakerjob]: refactor: bpt_bakerjob inventory implementation @bitpredator
49. [bpt_bakerjob]: refactor: bpt_bakerjob inventory implementation @bitpredator
50. [bpt_ballasjob]: refactor: bpt_ballasjob inventory implementation @bitpredator
51. [bpt_ballasjob]: feat: bpt_ballasjob\locales\en.lua @bitpredator
14 changes: 9 additions & 5 deletions server-data/resources/[bpt_addons]/bpt_ballasjob/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# bpt_ballasjob
<h1 align='center'>bpt_ballasjob</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/.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
51 changes: 34 additions & 17 deletions server-data/resources/[bpt_addons]/bpt_ballasjob/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local HasAlreadyEnteredMarker
local CurrentAction, CurrentActionMsg = nil, {}
local CurrentAction, CurrentActionMsg, CurrentActionData = nil, '', {}
local LastZone

RegisterNetEvent('esx:playerLoaded')
Expand Down Expand Up @@ -39,8 +39,11 @@ function ShowLoadingPromt(msg, time, type)
end)
end

function OpenBallasActionsMenu()
function OpenballasActionsMenu()
local elements = {
{unselectable = true, icon = "fas fa-ballas", title = _U('ballas')},
{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 @@ -51,18 +54,23 @@ function OpenBallasActionsMenu()
}
end

ESX.UI.Menu.CloseAll()

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_ballas')
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', 'ballas', function(_, menu)
menu.close()
end)
end

end, function()
CurrentAction = 'ballas_actions_menu'
CurrentActionMsg = _U('press_to_open')
CurrentActionData = {}
end)
end

Expand Down Expand Up @@ -103,11 +111,12 @@ AddEventHandler('bpt_ballasjob:hasEnteredMarker', function(zone)
if zone == 'BallasActions' then
CurrentAction = 'ballas_actions_menu'
CurrentActionMsg = _U('press_to_open')
CurrentActionData = {}
end
end)

AddEventHandler('bpt_ballasjob:hasExitedMarker', function()
ESX.UI.Menu.CloseAll()
ESX.CloseContext()
CurrentAction = nil
end)

Expand All @@ -116,11 +125,11 @@ CreateThread(function()
local blip = AddBlipForCoord(Config.Zones.BallasActions.Pos.x, Config.Zones.BallasActions.Pos.y,
Config.Zones.BallasActions.Pos.z)

SetBlipSprite(blip, 106)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, 1.0)
SetBlipColour(blip, 27)
SetBlipAsShortRange(blip, true)
SetBlipSprite(blip, 106)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, 1.0)
SetBlipColour(blip, 27)
SetBlipAsShortRange(blip, true)

BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(_U('blip_ballas'))
Expand All @@ -142,8 +151,16 @@ CreateThread(function()

if v.Type ~= -1 and distance < Config.DrawDistance then
sleep = 0
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)
if k == "" 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)
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)
end

end

if distance < v.Size.x then
Expand Down Expand Up @@ -175,7 +192,7 @@ CreateThread(function()

if IsControlJustReleased(0, 38) and ESX.PlayerData.job and ESX.PlayerData.job.name == 'ballas' then
if CurrentAction == 'ballas_actions_menu' then
OpenBallasActionsMenu()
OpenballasActionsMenu()
end

CurrentAction = nil
Expand All @@ -192,4 +209,4 @@ RegisterCommand('ballasmenu', function()
end
end, false)

RegisterKeyMapping('ballasmenu', 'Open ballas Menu', 'keyboard', 'f6')
RegisterKeyMapping('ballasmenu', 'Open Ballas Menu', 'keyboard', 'f6')
4 changes: 0 additions & 4 deletions server-data/resources/[bpt_addons]/bpt_ballasjob/config.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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.Locale = 'it'

Config.OxInventory = ESX.GetConfig().OxInventory

Config.Zones = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game 'gta5'

description 'bpt_ballasjob'
lua54 'yes'
version '0.0.4'
version '1.0.0'
autthor'bitpredator'

shared_script '@es_extended/imports.lua'
Expand Down
16 changes: 16 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_ballasjob/locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Locales['en'] = {
['amount_invalid'] = 'invalid amount',
['press_to_open'] = 'press [E] to access the menu',
['billing'] = 'billing',
['billing_sent'] = 'the account has been registered!',
['invoice_amount'] = 'invoice amount',
['no_players_near'] = 'no players nearby',
['boss_actions'] = 'Boss actions',
['blip_ballas'] = 'ballas',
['ballas'] = 'ballas',
-- Inventory
['deposit_stock'] = 'deposit stock',
['take_stock'] = 'take stock',
['have_deposited'] = 'have deposited',
['quantity_invalid'] = 'quantity invalid'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ Locales['it'] = {
['no_players_near'] = 'nessun giocatore nelle vicinanze',
['boss_actions'] = 'Azioni del boss',
['blip_ballas'] = 'ballas',
['ballas'] = 'ballas'
['ballas'] = 'ballas',
-- Inventory
['deposit_stock'] = 'Depositare',
['take_stock'] = 'Prendi',
['have_deposited'] = 'Hai depositato',
['quantity_invalid'] = 'Qunatità non valida'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,58 @@ ESX.RegisterServerCallback('bpt_ballasjob:getPlayerInventory', function(source,
items = items
})
end)

RegisterNetEvent('bpt_ballasjob:getStockItem')
AddEventHandler('bpt_ballasjob:getStockItem', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.job.name == 'ballas' then
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', 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_ballasjob:getStockItem^7 (cheating)'):format(source))
end
end)

ESX.RegisterServerCallback('bpt_ballasjob:getStockItems', function(_, cb)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', function(inventory)
cb(inventory.items)
end)
end)

RegisterNetEvent('bpt_ballasjob:putStockItems')
AddEventHandler('bpt_ballasjob:putStockItems', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
local sourceItem = xPlayer.getInventoryItem(itemName)

if xPlayer.job.name == 'ballas' then
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_ballas', 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_ballasjob: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 @@ -132,25 +132,6 @@ return {
groups = {['dustman'] = 0}
},

{
coords = vec3(78.738464, -1962.184570, 18.041016),
target = {
loc = vec3(78.738464, -1962.184570, 18.041016),
length = 0.6,
width = 1.8,
heading = 340,
minZ = 43.34,
maxZ = 44.74,
label = 'Storage'
},
name = 'ballaslocker',
label = 'Storage',
owner = false,
slots = 70,
weight = 70000,
groups = {['ballas'] = 0}
},

{
coords = vec3(-29.287910, -1103.182373, 26.415405),
target = {
Expand Down
Loading