ed
This commit is contained in:
parent
30c73f0bfb
commit
75db08b9a1
3 changed files with 204 additions and 238 deletions
|
|
@ -15,177 +15,9 @@ lib.callback.register('wasabi_fishing:checkItem', function(source, itemname)
|
|||
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
|
||||
local baitData = nil
|
||||
for _, bait in pairs(Config.bait.types) do
|
||||
if bait.itemName == baitType then
|
||||
baitData = bait
|
||||
|
|
@ -239,3 +71,166 @@ lib.callback.register('wasabi_fishing:getFishData', function(source, baitType)
|
|||
-- Apply catch bonus logic here if needed
|
||||
return availableFish[math.random(#availableFish)]
|
||||
end)
|
||||
|
||||
RegisterNetEvent('wasabi_fishing:rodBroke', function()
|
||||
RemoveItem(source, Config.fishingRod.itemName, 1)
|
||||
TriggerClientEvent('wasabi_fishing:interupt', source)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('wasabi_fishing:loseBait', function(baitType)
|
||||
RemoveItem(source, baitType, 1)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('wasabi_fishing:tryFish', function(data)
|
||||
local xPole = HasItem(source, Config.fishingRod.itemName)
|
||||
local xBait = false
|
||||
|
||||
-- Check if player has any type of bait
|
||||
for _, bait in pairs(Config.bait.types) do
|
||||
if HasItem(source, bait.itemName) > 0 then
|
||||
xBait = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if xPole > 0 and xBait then
|
||||
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 not xBait 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:processItem', function(fishItem)
|
||||
-- Find processing data for this fish
|
||||
local processData = nil
|
||||
for _, data in pairs(Config.processing.products) do
|
||||
if data.sourceItem == fishItem then
|
||||
processData = data
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not processData then
|
||||
TriggerClientEvent('wasabi_fishing:notify', source, 'Cannot Process', 'This fish cannot be processed', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if player has the fish and knife
|
||||
local hasFish = HasItem(source, fishItem)
|
||||
local hasKnife = HasItem(source, Config.processing.knifeItem)
|
||||
|
||||
if hasFish < 1 or hasKnife < 1 then
|
||||
TriggerClientEvent('wasabi_fishing:notify', source, 'Missing Items', 'You need both the fish and a knife', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
-- Remove the fish
|
||||
RemoveItem(source, fishItem, 1)
|
||||
|
||||
-- Add fish fillets
|
||||
local filletYield = processData.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, 'Processing Success',
|
||||
'You obtained ' .. filletAmount .. ' fish fillets', '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, fishItem, 1)
|
||||
return
|
||||
end
|
||||
else
|
||||
AddItem(source, filletYield.item, filletAmount)
|
||||
TriggerClientEvent('wasabi_fishing:notify', source, 'Processing Success',
|
||||
'You obtained ' .. filletAmount .. ' fish fillets', 'success')
|
||||
end
|
||||
|
||||
-- Check for caviar
|
||||
for i=2, #processData.yield do
|
||||
local extraYield = processData.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, 'Caviar Found', 'You found some valuable caviar!', 'success')
|
||||
end
|
||||
else
|
||||
AddItem(source, extraYield.item, 1)
|
||||
TriggerClientEvent('wasabi_fishing:notify', source, 'Caviar Found', 'You found some valuable caviar!', 'success')
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
-- 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
|
||||
|
||||
-- Register usable items for all fish types for processing
|
||||
for _, fish in pairs(Config.fish) do
|
||||
RegisterUsableItem(fish.item, function(source)
|
||||
TriggerClientEvent('wasabi_fishing:processFish', source, fish.item)
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterUsableItem(Config.fishingRod.itemName, function(source)
|
||||
TriggerClientEvent('wasabi_fishing:startFishing', source)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue