1
0
Fork 0
forked from Simnation/Main
Main/resources/[jobs]/[civ]/wasabi_fishing/server/server.lua
2025-07-01 11:20:24 +02:00

241 lines
9.2 KiB
Lua

-----------------For support, scripts, and more----------------
--------------- https://discord.gg/wasabiscripts -------------
---------------------------------------------------------------
local addCommas = function(n)
return tostring(math.floor(n)):reverse():gsub("(%d%d%d)","%1,")
:gsub(",(%-?)$","%1"):reverse()
end
lib.callback.register('wasabi_fishing:checkItem', function(source, itemname)
local item = HasItem(source, itemname)
if item >= 1 then
return true
else
return false
end
end)
lib.callback.register('wasabi_fishing:getFishData', function(source)
local data = Config.fish[math.random(#Config.fish)]
return data
end)
RegisterNetEvent('wasabi_fishing:rodBroke', function()
RemoveItem(source, Config.fishingRod.itemName, 1)
TriggerClientEvent('wasabi_fishing:interupt', source)
end)
RegisterNetEvent('wasabi_fishing:tryFish', function(data)
local xPole = HasItem(source, Config.fishingRod.itemName)
local xBait = HasItem(source, Config.bait.itemName)
if xPole > 0 and xBait > 0 then
local chance = math.random(1,100)
if chance <= Config.bait.loseChance then
RemoveItem(source, Config.bait.itemName, 1)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.bait_lost, Strings.bait_lost_desc, 'error')
end
if Framework == 'esx' and not Config.oldESX then
local player = GetPlayer(source)
if player.canCarryItem(data.item, 1) then
AddItem(source, data.item, 1)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.fish_success, string.format(Strings.fish_success_desc, data.label), 'success')
else
TriggerClientEvent('wasabi_fishing:notify', source, Strings.cannot_carry, Strings.cannot_carry_desc, 'error')
end
else
AddItem(source, data.item, 1)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.fish_success, string.format(Strings.fish_success_desc, data.label), 'success')
end
elseif xPole > 0 and xBait < 1 then
TriggerClientEvent('wasabi_fishing:interupt', source)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.no_bait, Strings.no_bait_desc, 'error')
elseif xPole < 1 then
KickPlayer(source, Strings.kicked)
end
end)
RegisterNetEvent('wasabi_fishing:sellFish', function()
local playerPed = GetPlayerPed(source)
local playerCoord = GetEntityCoords(playerPed)
local distance = #(playerCoord - Config.sellShop.coords)
if distance == nil then
KickPlayer(source, Strings.kicked)
return
end
if distance > 3 then
KickPlayer(source, Strings.kicked)
return
end
for i=1, #Config.fish do
if HasItem(source, Config.fish[i].item) > 0 then
local rewardAmount = 0
for j=1, HasItem(source, Config.fish[i].item) do
rewardAmount = rewardAmount + math.random(Config.fish[i].price[1], Config.fish[i].price[2])
end
if rewardAmount > 0 then
AddMoney(source, 'money', rewardAmount)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.sold_for, (Strings.sold_for_desc):format(HasItem(source, Config.fish[i].item), Config.fish[i].label, addCommas(rewardAmount)), 'success')
RemoveItem(source, Config.fish[i].item, HasItem(source, Config.fish[i].item))
end
end
end
end)
RegisterUsableItem(Config.fishingRod.itemName, function(source)
TriggerClientEvent('wasabi_fishing:startFishing', source)
end)
-- Register usable items for all fish types for processing
for _, fish in pairs(Config.processing.products) do
RegisterUsableItem(fish.sourceItem, function(source)
local hasKnife = HasItem(source, Config.processing.knifeItem)
if hasKnife > 0 then
ProcessFish(source, fish)
else
TriggerClientEvent('wasabi_fishing:notify', source, Strings.no_knife, Strings.no_knife_desc, 'error')
end
end)
end
-- Function to process fish
function ProcessFish(source, fishData)
-- Remove the fish
RemoveItem(source, fishData.sourceItem, 1)
-- Add fish fillets
local filletYield = fishData.yield[1]
local filletAmount = math.random(filletYield.amount[1], filletYield.amount[2])
if Framework == 'esx' and not Config.oldESX then
local player = GetPlayer(source)
if player.canCarryItem(filletYield.item, filletAmount) then
AddItem(source, filletYield.item, filletAmount)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.processing_success,
string.format(Strings.processing_success_desc, filletAmount, GetItemLabel(filletYield.item)), 'success')
else
TriggerClientEvent('wasabi_fishing:notify', source, Strings.cannot_carry, Strings.cannot_carry_desc, 'error')
-- Give back the fish if they can't carry the fillets
AddItem(source, fishData.sourceItem, 1)
return
end
else
AddItem(source, filletYield.item, filletAmount)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.processing_success,
string.format(Strings.processing_success_desc, filletAmount, GetItemLabel(filletYield.item)), 'success')
end
-- Check for caviar
for i=2, #fishData.yield do
local extraYield = fishData.yield[i]
if extraYield.item == 'caviar' and extraYield.chance then
local chance = math.random(1, 100)
if chance <= extraYield.chance then
if Framework == 'esx' and not Config.oldESX then
local player = GetPlayer(source)
if player.canCarryItem(extraYield.item, 1) then
AddItem(source, extraYield.item, 1)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.caviar_found, Strings.caviar_found_desc, 'success')
end
else
AddItem(source, extraYield.item, 1)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.caviar_found, Strings.caviar_found_desc, 'success')
end
end
end
end
end
-- Modify the sellFish event to include processed items
RegisterNetEvent('wasabi_fishing:sellFish', function()
local playerPed = GetPlayerPed(source)
local playerCoord = GetEntityCoords(playerPed)
local distance = #(playerCoord - Config.sellShop.coords)
if distance == nil or distance > 3 then
KickPlayer(source, Strings.kicked)
return
end
-- Sell fish
for i=1, #Config.fish do
SellItem(source, Config.fish[i])
end
-- Sell processed items
for i=1, #Config.processedItems do
SellItem(source, Config.processedItems[i])
end
end)
-- Helper function to sell items
function SellItem(source, itemData)
if HasItem(source, itemData.item) > 0 then
local rewardAmount = 0
for j=1, HasItem(source, itemData.item) do
rewardAmount = rewardAmount + math.random(itemData.price[1], itemData.price[2])
end
if rewardAmount > 0 then
AddMoney(source, 'money', rewardAmount)
TriggerClientEvent('wasabi_fishing:notify', source, Strings.sold_for,
(Strings.sold_for_desc):format(HasItem(source, itemData.item), itemData.label, addCommas(rewardAmount)), 'success')
RemoveItem(source, itemData.item, HasItem(source, itemData.item))
end
end
end
-- Modify the getFishData callback to handle bait types
lib.callback.register('wasabi_fishing:getFishData', function(source, baitType)
local baitData = nil
-- Find the bait data
for _, bait in pairs(Config.bait.types) do
if bait.itemName == baitType then
baitData = bait
break
end
end
if not baitData then
-- Use default bait data if the provided bait type is not found
for _, bait in pairs(Config.bait.types) do
if bait.itemName == Config.bait.defaultBait then
baitData = bait
break
end
end
end
-- If using illegal bait, only catch pufferfish
if baitData.exclusive then
for _, fishType in pairs(baitData.exclusive) do
for _, fish in pairs(Config.fish) do
if fish.item == fishType then
return fish
end
end
end
end
-- Otherwise, random fish with catch bonus
local availableFish = {}
for _, fish in pairs(Config.fish) do
-- Don't include exclusive fish types unless using the right bait
local isExclusive = false
for _, bait in pairs(Config.bait.types) do
if bait.exclusive then
for _, exclusiveFish in pairs(bait.exclusive) do
if fish.item == exclusiveFish then
isExclusive = true
break
end
end
end
if isExclusive then break end
end
if not isExclusive then
table.insert(availableFish, fish)
end
end
-- Apply catch bonus logic here if needed
return availableFish[math.random(#availableFish)]
end)