-----------------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, baitType) -- Find the bait data local baitData = nil 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) 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)