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_dustman inventory implementation #590

Merged
merged 3 commits into from
Dec 24, 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
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse
53. [bpt_bakerjob]: Fixed the problem that prevented the creation of invoices @bitpredator
54. [bpt_ballasjob]: Fixed the problem that prevented the creation of invoices @bitpredator
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
56. [bpt_deliveries]: feat + chore: updated readme file + creation of Italian translation @bitpredator
57. [bpt_dustman]: refactor: bpt_dustman inventory implementation @bitpredator
10 changes: 4 additions & 6 deletions server-data/resources/[bpt_addons]/bpt_dustman/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# bpt_dustman
<h1 align='center'>bpt_dustman</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.

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/.
65 changes: 41 additions & 24 deletions server-data/resources/[bpt_addons]/bpt_dustman/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function OpenCloakroom()
end
end)
end
ESX.CloseContext()
ESX.CloseContext()
end, function()
CurrentAction = 'cloakroom'
CurrentActionMsg = _U('cloakroom_prompt')
Expand All @@ -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
Expand All @@ -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
Expand All @@ -112,7 +112,8 @@ function OpenVehicleSpawnerMenu()
end)
end, 'dustman')
else -- not society vehicles
if #Config.AuthorizedVehicles == 0 then

if #Config.AuthorizedVehicles == 0 then
ESX.ShowNotification(_U('empty_garage'))
return
end
Expand All @@ -130,13 +131,15 @@ 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_dustmanjob:SpawnVehicle", function()
ESX.ShowNotification(_U('vehicle_spawned'), "success")
end, element.value, {plate = "DUST JOB"})
end, element.value, {plate = "DUSTMAN"})
ESX.CloseContext()
end, function()
CurrentAction = 'vehicle_spawner'
Expand All @@ -147,14 +150,17 @@ function OpenVehicleSpawnerMenu()
end

function DeleteJobVehicle()

if Config.EnableSocietyOwnedVehicles then
local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle)
TriggerServerEvent('esx_society:putVehicleInGarage', 'dustman', vehicleProps)
ESX.Game.DeleteVehicle(CurrentActionData.vehicle)
else
if IsInAuthorizedVehicle() then
ESX.Game.DeleteVehicle(CurrentActionData.vehicle)

if Config.MaxInService ~= -1 then
TriggerServerEvent('esx_service:disableService', 'dustman')
end
else
ESX.ShowNotification(_U('only_dustman'))
end
Expand All @@ -163,7 +169,9 @@ end

function OpenDustmanActionsMenu()
local elements = {
{unselectable = true, icon = "fas fa-dustman", title = _U('dustman')}
{unselectable = true, icon = "fas fa-dustman", title = _U('dustman')},
{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 @@ -174,8 +182,15 @@ function OpenDustmanActionsMenu()
}
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_dustman')
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', 'dustman', function(_, menu)
menu.close()
end)
Expand All @@ -190,20 +205,23 @@ end
function OpenMobileDustmanActionsMenu()
local elements = {
{unselectable = true, icon = "fas fa-dustman", title = _U('dustman')},
{icon = "fas fa-scroll", title = _U('billing'), value = "billing"}
{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
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'billing', {
title = _U('invoice_amount')
}, function(data, menu)
local elements2 = {
{unselectable = true, icon = "fas fa-dustman", title = element.title},
{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"}
}

local amount = tonumber(data.value)
ESX.OpenContext("right", elements2, function(menu2)
local amount = tonumber(menu2.eles[2].inputValue)
if amount == nil then
ESX.ShowNotification(_U('amount_invalid'))
else
menu.close()
ESX.CloseContext()
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
if closestPlayer == -1 or closestDistance > 3.0 then
ESX.ShowNotification(_U('no_players_near'))
Expand All @@ -213,8 +231,6 @@ function OpenMobileDustmanActionsMenu()
ESX.ShowNotification(_U('billing_sent'))
end
end
end, function(_, menu)
menu.close()
end)
end
end)
Expand Down Expand Up @@ -290,23 +306,24 @@ 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)
local distance = #(coords - zonePos)

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
Expand Down Expand Up @@ -361,4 +378,4 @@ RegisterCommand('dustmanmenu', function()
end
end, false)

RegisterKeyMapping('dustmanmenu', 'Open dustman Menu', 'keyboard', 'f6')
RegisterKeyMapping('dustmanmenu', 'Open Dustman Menu', 'keyboard', 'f6')
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 = 'biff', label = 'Camion'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game 'gta5'

description 'bpt_dustmanjob'
lua54 'yes'
version '0.0.4'
version '1.0.0'

shared_script '@es_extended/imports.lua'

Expand All @@ -22,4 +22,4 @@ server_scripts {
'server/main.lua'
}

dependency 'es_extended'
dependency 'es_extended'
11 changes: 10 additions & 1 deletion server-data/resources/[bpt_addons]/bpt_dustman/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ Locales['en'] = {
['no_players_near'] = 'no players nearby',
['boss_actions'] = 'boss action',
['blip_dustman'] = 'dump',
['dustman'] = 'dustman'
['dustman'] = 'dustman',
-- Inventory
['deposit_stock'] = 'Deposit stock',
['take_stock'] = 'Take stock',
['have_deposited'] = 'Have deposited',
['quantity_invalid'] = 'Quantity invelid',
-- billing
['bill_amount'] = "bill amount",
['amount'] = "amount",
['confirm'] = "Confirm"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ Locales['it'] = {
['no_players_near'] = 'nessun giocatore nelle vicinanze',
['boss_actions'] = 'Azioni del boss',
['blip_dustman'] = 'discarica',
['dustman'] = 'dustman'
['dustman'] = 'dustman',
-- Inventory
['deposit_stock'] = 'Depositare',
['take_stock'] = 'Prendi',
['have_deposited'] = 'Hai depositato',
['quantity_invalid'] = 'Qunatità non valida',
-- billing
['bill_amount'] = "importo della fattura",
['confirm'] = "Conferma"
}
59 changes: 55 additions & 4 deletions server-data/resources/[bpt_addons]/bpt_dustman/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ TriggerEvent('esx_society:registerSociety', 'dustman', 'Dustman', 'society_dustm
type = 'public'
})

if Config.MaxInService ~= -1 then
TriggerEvent('esx_service:activateService', 'dustman', Config.MaxInService)
end

ESX.RegisterServerCallback("bpt_dustmanjob:SpawnVehicle", function(source, cb, model , props)
local xPlayer = ESX.GetPlayerFromId(source)

Expand All @@ -20,10 +24,57 @@ ESX.RegisterServerCallback("bpt_dustmanjob:SpawnVehicle", function(source, cb, m
cb()
end)

ESX.RegisterServerCallback('bpt_dustmanjob:getPlayerInventory', function(source, cb)
RegisterNetEvent('bpt_dustmanjob:getStockItem')
AddEventHandler('bpt_dustmanjob:getStockItem', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)

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

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

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

if xPlayer.job.name == 'dustman' then
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_dustman', function(inventory)
local item = inventory.getItem(itemName)

local minItems = xPlayer.getInventory(true)
cb(next(minItems) ~= nil and items or false)
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_dustmanjob: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 @@ -113,25 +113,6 @@ return {
groups = {['import'] = 0}
},

{
coords = vec3(-415.107697, -1676.782471, 19.018311),
target = {
loc = vec3(-415.107697, -1676.782471, 19.018311),
length = 0.6,
width = 1.8,
heading = 340,
minZ = 43.34,
maxZ = 44.74,
label = 'Storage'
},
name = 'dustmanlocker',
label = 'Storage',
owner = false,
slots = 70,
weight = 70000,
groups = {['dustman'] = 0}
},

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