Skip to content

Commit

Permalink
Merge pull request #592 from bitpredator/dev
Browse files Browse the repository at this point in the history
refactor: bpt_fishermanjob inventory implementation
  • Loading branch information
bitpredator authored Dec 27, 2023
2 parents dc0745c + 4863082 commit d540a0c
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse
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
57. [bpt_dustman]: refactor: bpt_dustman inventory implementation @bitpredator
58. [bpt_farmer]: refactor: support for translations through local files @bitpredator
58. [bpt_farmer]: refactor: support for translations through local files @bitpredator
59. [bpt_fishermanjob]: refactor: bpt_fishermanjob inventory implementation @bitpredator
25 changes: 18 additions & 7 deletions server-data/resources/[bpt_addons]/bpt_fisherman/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
This program is a project for the fivem community, you have legal permission to distribute and / or modify it .
ATTENTION: You are not authorized to change the name of the resources present within it.
You are not authorized to sell this software (this is a free project).
<h1 align='center'>bpt_fisherman</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

📌 License
Copyright (C) 2022-2023 bitpredator

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/.

### 📌 License

EMPIRETOWN - FRAMEWORK FOR FIVEM
Copyright (C) 2023 bitpredator
## Info
This Script will allow you to simulate the creation of sandwiches using flour and water
56 changes: 32 additions & 24 deletions server-data/resources/[bpt_addons]/bpt_fisherman/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, 'fisherman')
else -- not society vehicles
if #Config.AuthorizedVehicles == 0 then

if #Config.AuthorizedVehicles == 0 then
ESX.ShowNotification(_U('empty_garage'))
return
end
Expand All @@ -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_fishermanjob:SpawnVehicle", function()
ESX.ShowNotification(_U('vehicle_spawned'), "success")
end, element.value, {plate = "FISH JOB"})
Expand All @@ -147,7 +150,6 @@ function OpenVehicleSpawnerMenu()
end

function DeleteJobVehicle()

if Config.EnableSocietyOwnedVehicles then
local vehicleProps = ESX.Game.GetVehicleProperties(CurrentActionData.vehicle)
TriggerServerEvent('esx_society:putVehicleInGarage', 'fisherman', vehicleProps)
Expand All @@ -163,7 +165,9 @@ end

function OpenFishermanActionsMenu()
local elements = {
{unselectable = true, icon = "fas fa-fisherman", title = _U('fisherman')}
{unselectable = true, icon = "fas fa-fisherman", title = _U('fisherman')},
{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,13 +178,16 @@ function OpenFishermanActionsMenu()
}
end

ESX.OpenContext("right", elements, function(_,element)
local menu = {
{unselectable = true, "fas fa-fisherman", title = _U('boss_actions')}
}

if element.value == 'boss_actions' then
TriggerEvent('esx_society:openBossMenu', 'fisherman', 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_fisherman')
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', 'fisherman', function(_, menu)
menu.close()
end)
end
Expand All @@ -197,12 +204,12 @@ function OpenMobileFishermanActionsMenu()
{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-fisherman", 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)
Expand Down Expand Up @@ -276,11 +283,11 @@ CreateThread(function()
local blip = AddBlipForCoord(Config.Zones.FishermanActions.Pos.x, Config.Zones.FishermanActions.Pos.y,
Config.Zones.FishermanActions.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_fisherman'))
Expand All @@ -295,15 +302,15 @@ 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)
Expand All @@ -312,6 +319,7 @@ CreateThread(function()
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
3 changes: 2 additions & 1 deletion server-data/resources/[bpt_addons]/bpt_fisherman/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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.EnableSocietyOwnedVehicles = false
Config.Locale = 'it'
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 @@ -4,7 +4,7 @@ game 'gta5'

description 'bpt_fishermanjob'
lua54 'yes'
version '0.0.5'
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'
17 changes: 12 additions & 5 deletions server-data/resources/[bpt_addons]/bpt_fisherman/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ Locales['en'] = {
-- cloakroom
['cloakroom_menu'] = 'cloakroom',
['cloakroom_prompt'] = 'press [E] to access the cloakroom.',
['wear_citizen'] = 'ivilian clothes',
['wear_citizen'] = 'civilian clothes',
['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 picked up successfully!",
Expand All @@ -13,11 +18,13 @@ Locales['en'] = {
['only_fisherman'] = 'you can only deposit company vehicles.',
['amount_invalid'] = 'invalid amount',
['press_to_open'] = 'press [E] to access the menu',
['billing'] = 'biling',
['billing_sent'] = 'the invoice has been posted!',
['invoice_amount'] = 'invoice amount',
['no_players_near'] = 'no players nearby',
['boss_actions'] = 'Boss actions',
['blip_fisherman'] = 'Fisherman',
['fisherman'] = 'fisherman'
}
['fisherman'] = 'fisherman',
-- billing
['bill_amount'] = "Amount to bill..",
['confirm'] = "Confirm",
['amount'] = 'amount'
}
15 changes: 11 additions & 4 deletions server-data/resources/[bpt_addons]/bpt_fisherman/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'] = '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!",
Expand All @@ -13,11 +18,13 @@ Locales['it'] = {
['only_fisherman'] = 'puoi solo depositare veicoli aziendali.',
['amount_invalid'] = 'importo non valido',
['press_to_open'] = 'premi [E] per accedere al menu',
['billing'] = 'fattura',
['billing_sent'] = 'la fattura è stata registrata!',
['invoice_amount'] = 'importo della fattura',
['no_players_near'] = 'nessun giocatore nelle vicinanze',
['boss_actions'] = 'Azioni del boss',
['blip_fisherman'] = 'Fisherman',
['fisherman'] = 'fisherman'
}
['fisherman'] = 'fisherman',
-- billing
['bill_amount'] = "importo della fattura",
['confirm'] = "Conferma",
['amount'] = "Importo"
}
59 changes: 59 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_fisherman/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ TriggerEvent('esx_society:registerSociety', 'fisherman', 'Fisherman', 'society_f
type = 'public'
})

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

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

Expand All @@ -18,4 +22,59 @@ ESX.RegisterServerCallback("bpt_fishermanjob:SpawnVehicle", function(source, cb,
TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1)
end)
cb()
end)

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

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

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

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

if xPlayer.job.name == 'fisherman' then
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_fisherman', 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_fishermanjob: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 @@ -131,23 +131,4 @@ return {
weight = 70000,
groups = {['cardealer'] = 0}
},

{
coords = vec3(-321.402191, -2785.134033, 5.201416),
target = {
loc = vec3(-321.402191, -2785.134033, 5.201416),
length = 0.6,
width = 1.8,
heading = 340,
minZ = 43.34,
maxZ = 44.74,
label = 'Storage'
},
name = 'fishermanlocker',
label = 'fisherman',
owner = false,
slots = 70,
weight = 70000,
groups = {['fisherman'] = 0}
},
}

0 comments on commit d540a0c

Please sign in to comment.