From fc96bc5167a20acd1cc91fb29006b07ad31327a4 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Sat, 22 Jun 2024 18:43:23 +0200 Subject: [PATCH] refactor: big update --- .../[wasabi]/wasabi_fishing/README.md | 14 +- .../wasabi_fishing/bridge/esx/client.lua | 68 +++++++++ .../wasabi_fishing/bridge/esx/server.lua | 91 ++++++++++++ .../wasabi_fishing/bridge/qb/client.lua | 91 ++++++++++++ .../wasabi_fishing/bridge/qb/server.lua | 98 +++++++++++++ .../[wasabi]/wasabi_fishing/client/client.lua | 72 ++++++++-- .../wasabi_fishing/client/functions.lua | 12 +- .../wasabi_fishing/configuration/config.lua | 18 +-- .../wasabi_fishing/configuration/strings.lua | 1 + .../[wasabi]/wasabi_fishing/fxmanifest.lua | 25 +--- .../[wasabi]/wasabi_fishing/server/server.lua | 135 ++++++++---------- .../wasabi_fishing/server/updater.lua | 67 +++++++++ .../sql/wasabi_fishing_limit.sql | 8 -- .../sql/wasabi_fishing_weight.sql | 8 -- 14 files changed, 568 insertions(+), 140 deletions(-) create mode 100644 server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua create mode 100644 server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua create mode 100644 server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua create mode 100644 server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/server.lua create mode 100644 server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua delete mode 100644 server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_limit.sql delete mode 100644 server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_weight.sql diff --git a/server-data/resources/[wasabi]/wasabi_fishing/README.md b/server-data/resources/[wasabi]/wasabi_fishing/README.md index 53784c7a9..357874a31 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/README.md +++ b/server-data/resources/[wasabi]/wasabi_fishing/README.md @@ -1,8 +1,9 @@ # wasabi_fishing -This resource was created as a free interactive fishing script for ESX servers. +This resource was created as a free interactive fishing script for ESX/QBCore servers. ## Features +- Out of the box compatible with ESX and QBCore - Optimized 0.00ms usage on idle - Skill-check based success - Full animations and props @@ -16,7 +17,7 @@ This resource was created as a free interactive fishing script for ESX servers. - Fully configurable fish buyer to sell fish ## Dependencies -- es_extended +- es_extended OR qb-core - ox_lib - https://github.com/overextended/ox_lib/releases @@ -24,19 +25,20 @@ This resource was created as a free interactive fishing script for ESX servers. - Make sure you have dependencies -- Insert proper item sql or ensure items are present that you will be using in the configuration +- Make sure items are added to server(Check `Inventory_Items` directory for images/examples - Put script in your `resources` directory -- If using limit system for inventory please set Old ESX config to true otherwise put false - - Add `ensure wasabi_fishing` in your `server.cfg` (*After* dependencies) ### Extra Information - Make sure `ox_lib` starts before `wasabi_fishing` -- Inventory images included in the `InventoryImages` directory +- Inventory images included in the `Inventory_Items/InventoryImages` directory - You must add the item `fishingrod` and `fishbait` to one of your in-game shops or have a place for your players to obtain. ## Preview https://www.youtube.com/watch?v=kLLPGJIK3Q0 + +# Support +![Discord Banner 2](https://discordapp.com/api/guilds/1025493337031049358/widget.png?style=banner2) diff --git a/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua new file mode 100644 index 000000000..28794fdcf --- /dev/null +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua @@ -0,0 +1,68 @@ +if GetResourceState("es_extended") ~= "started" then + return +end +ESX = exports["es_extended"]:getSharedObject() +Framework, PlayerLoaded, PlayerData = "esx", nil, {} + +RegisterNetEvent("esx:playerLoaded", function(xPlayer) + PlayerData = xPlayer + PlayerLoaded = true +end) + +RegisterNetEvent("esx:onPlayerSpawn", function() + TriggerEvent("wasabi_fishing:onPlayerSpawn") +end) + +AddEventHandler("esx:onPlayerDeath", function(data) + TriggerEvent("wasabi_fishing:onPlayerDeath") +end) + +RegisterNetEvent("esx:onPlayerLogout", function() + table.wipe(PlayerData) + PlayerLoaded = false +end) + +RegisterNetEvent("esx:setJob", function(job) + PlayerData.job = job +end) + +AddEventHandler("onResourceStart", function(resourceName) + if GetCurrentResourceName() ~= resourceName or not ESX.PlayerLoaded then + return + end + PlayerData = ESX.GetPlayerData() + PlayerLoaded = true +end) + +AddEventHandler("esx:setPlayerData", function(key, value) + if GetInvokingResource() ~= "es_extended" then + return + end + PlayerData[key] = value +end) + +function HasGroup(filter) + local type = type(filter) + + if type == "string" then + if PlayerData.job.name == filter then + return PlayerData.job.name, PlayerData.job.grade + end + else + local tabletype = table.type(filter) + + if tabletype == "hash" then + local grade = filter[PlayerData.job.name] + + if grade and grade <= PlayerData.job.grade then + return PlayerData.job.name, PlayerData.job.grade + end + elseif tabletype == "array" then + for i = 1, #filter do + if PlayerData.job.name == filter[i] then + return PlayerData.job.name, PlayerData.job.grade + end + end + end + end +end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua new file mode 100644 index 000000000..401593169 --- /dev/null +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua @@ -0,0 +1,91 @@ +if GetResourceState("es_extended") ~= "started" then + return +end +ESX = exports["es_extended"]:getSharedObject() +Framework = "esx" + +function GetPlayer(source) + return ESX.GetPlayerFromId(source) +end + +function KickPlayer(source, reason) + local player = GetPlayer(source) + return player.kick(reason) +end + +function HasGroup(source, filter) + local player = GetPlayer(source) + local type = type(filter) + + if type == "string" then + if player.job.name == filter then + return player.job.name, player.job.grade + end + else + local tabletype = table.type(filter) + + if tabletype == "hash" then + local grade = filter[player.job.name] + + if grade and grade <= player.job.grade then + return player.job.name, player.job.grade + end + elseif tabletype == "array" then + for i = 1, #filter do + if player.job.name == filter[i] then + return player.job.name, player.job.grade + end + end + end + end +end + +function GetIdentifier(source) + local xPlayer = ESX.GetPlayerFromId(source) + return xPlayer.identifier +end + +function GetName(source) + local xPlayer = ESX.GetPlayerFromId(source) + return xPlayer.getName() +end + +function RegisterUsableItem(item, cb) + ESX.RegisterUsableItem(item, cb) +end + +function HasItem(source, item) + local player = GetPlayer(source) + local item = player.getInventoryItem(item) + if item ~= nil then + return item.count + else + return 0 + end +end + +function AddItem(source, item, count, slot, metadata) + local player = GetPlayer(source) + return player.addInventoryItem(item, count, metadata, slot) +end + +function RemoveItem(source, item, count, slot, metadata) + local player = GetPlayer(source) + player.removeInventoryItem(item, count, metadata, slot) +end + +function AddMoney(source, type, amount) + if type == "cash" then + type = "money" + end + local player = GetPlayer(source) + player.addAccountMoney(type, amount) +end + +function RemoveMoney(source, type, amount) + if type == "cash" then + type = "money" + end + local player = GetPlayer(source) + player.removeAccountMoney(type, amount) +end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua b/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua new file mode 100644 index 000000000..271812fdd --- /dev/null +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua @@ -0,0 +1,91 @@ +if GetResourceState("qb-core") ~= "started" then + return +end +QBCore = exports["qb-core"]:GetCoreObject() +Framework, PlayerLoaded, PlayerData = "qb", nil, {} + +AddStateBagChangeHandler("isLoggedIn", "", function(_bagName, _key, value, _reserved, _replicated) + if value then + PlayerData = QBCore.Functions.GetPlayerData() + else + table.wipe(PlayerData) + end + PlayerLoaded = value +end) + +AddEventHandler("onResourceStart", function(resourceName) + if GetCurrentResourceName() ~= resourceName or not LocalPlayer.state.isLoggedIn then + return + end + PlayerData = QBCore.Functions.GetPlayerData() + PlayerLoaded = true +end) + +AddEventHandler("gameEventTriggered", function(event, data) + if event ~= "CEventNetworkEntityDamage" then + return + end + local victim, victimDied = data[1], data[4] + if not IsPedAPlayer(victim) then + return + end + local player = PlayerId() + if + victimDied + and NetworkGetPlayerIndexFromPed(victim) == player + and (IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)) + then + TriggerEvent("wasabi_fishing:onPlayerDeath") + end +end) + +RegisterNetEvent("QBCore:Client:OnPlayerLoaded", function() + TriggerEvent("wasabi_fishing:onPlayerSpawn") +end) + +RegisterNetEvent("QBCore:Player:SetPlayerData", function(newPlayerData) + if source ~= "" and GetInvokingResource() ~= "qb-core" then + return + end + PlayerData = newPlayerData +end) + +function HasGroup(filter) + local groups = { "job", "gang" } + local type = type(filter) + + if type == "string" then + for i = 1, #groups do + local data = PlayerData[groups[i]] + + if data.name == filter then + return data.name, data.grade.level + end + end + else + local tabletype = table.type(filter) + + if tabletype == "hash" then + for i = 1, #groups do + local data = PlayerData[groups[i]] + local grade = filter[data.name] + + if grade and grade <= data.grade.level then + return data.name, data.grade.level + end + end + elseif tabletype == "array" then + for i = 1, #filter do + local group = filter[i] + + for j = 1, #groups do + local data = PlayerData[groups[j]] + + if data.name == group then + return data.name, data.grade.level + end + end + end + end + end +end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/server.lua b/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/server.lua new file mode 100644 index 000000000..8d272bd35 --- /dev/null +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/server.lua @@ -0,0 +1,98 @@ +if GetResourceState('qb-core') ~= 'started' then return end +QBCore = exports['qb-core']:GetCoreObject() +Framework = 'qb' + +function GetPlayer(source) + return QBCore.Functions.GetPlayer(source) +end + +function KickPlayer(source, reason) + QBCore.Functions.Kick(source, reason, true, true) +end + +function HasGroup(source, filter) + local groups = { 'job', 'gang' } + local player = GetPlayer(source) + local type = type(filter) + + if type == 'string' then + for i = 1, #groups do + local data = player.PlayerData[groups[i]] + + if data.name == filter then + return data.name, data.grade.level + end + end + else + local tabletype = table.type(filter) + + if tabletype == 'hash' then + for i = 1, #groups do + local data = player.PlayerData[groups[i]] + local grade = filter[data.name] + + if grade and grade <= data.grade.level then + return data.name, data.grade.level + end + end + elseif tabletype == 'array' then + for i = 1, #filter do + local group = filter[i] + + for j = 1, #groups do + local data = player.PlayerData[groups[j]] + + if data.name == group then + return data.name, data.grade.level + end + end + end + end + end +end + +function GetIdentifier(source) + local xPlayer = QBCore.Functions.GetPlayer(source) + return xPlayer.PlayerData.citizenid +end + +function GetName(source) + local xPlayer = QBCore.Functions.GetPlayer(source) + return xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname +end + +function RegisterUsableItem(item, cb) + QBCore.Functions.CreateUseableItem(item, cb) +end + +function HasItem(source, item) + local player = GetPlayer(source) + local item = player.Functions.GetItemByName(item) + if GetResourceState('ox_inventory') == 'started' then + return item?.count or 0 + else + return item?.amount or 0 + end +end + +function AddItem(source, item, count, slot, metadata) + local player = GetPlayer(source) + return player.Functions.AddItem(item, count, slot, metadata) +end + +function RemoveItem(source, item, count, slot, metadata) + local player = GetPlayer(source) + player.Functions.RemoveItem(item, count, slot, metadata) +end + +function AddMoney(source, type, amount) + if type == 'money' then type = 'cash' end + local player = GetPlayer(source) + player.Functions.AddMoney(type, amount) +end + +function RemoveMoney(source, type, amount) + if type == 'money' then type = 'cash' end + local player = GetPlayer(source) + player.Functions.RemoveMoney(type, amount) +end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua b/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua index e57b89af5..c1adb39cf 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua @@ -1,20 +1,75 @@ -ESX = exports["es_extended"]:getSharedObject() local fishing = false -RegisterNetEvent("wasabi_fishing:startFishing") -AddEventHandler("wasabi_fishing:startFishing", function() +if Config.sellShop.enabled then + CreateThread(function() + local ped, textUI + CreateBlip(Config.sellShop.coords, 356, 1, Strings.sell_shop_blip, 0.80) + local point = lib.points.new({ + coords = Config.sellShop.coords, + distance = 30, + }) + + function point:nearby() + if self.currentDistance < self.distance then + if not ped then + lib.requestAnimDict("mini@strip_club@idles@bouncer@base", 100) + lib.requestModel(Config.sellShop.ped, 100) + ped = CreatePed( + 28, + Config.sellShop.ped, + Config.sellShop.coords.x, + Config.sellShop.coords.y, + Config.sellShop.coords.z, + Config.sellShop.heading, + false, + false + ) + FreezeEntityPosition(ped, true) + SetEntityInvincible(ped, true) + SetBlockingOfNonTemporaryEvents(ped, true) + TaskPlayAnim(ped, "mini@strip_club@idles@bouncer@base", "base", 8.0, 0.0, -1, 1, 0, 0, 0, 0) + end + if self.currentDistance <= 1.8 then + if not textUI then + lib.showTextUI(Strings.sell_fish) + textUI = true + end + if IsControlJustReleased(0, 38) then + FishingSellItems() + end + elseif self.currentDistance >= 1.9 and textUI then + lib.hideTextUI() + textUI = nil + end + end + end + + function point:onExit() + if ped then + local model = GetEntityModel(ped) + SetModelAsNoLongerNeeded(model) + DeletePed(ped) + SetPedAsNoLongerNeeded(ped) + RemoveAnimDict("mini@strip_club@idles@bouncer@base") + ped = nil + end + end + end) +end + +RegisterNetEvent("wasabi_fishing:startFishing", function() if IsPedInAnyVehicle(cache.ped) or IsPedSwimming(cache.ped) then TriggerEvent("wasabi_fishing:notify", Strings.cannot_perform, Strings.cannot_perform_desc, "error") return end local hasItem = lib.callback.await("wasabi_fishing:checkItem", 100, Config.bait.itemName) if hasItem then - local water, waterLoc = waterCheck() + local water, waterLoc = WaterCheck() if water then if not fishing then fishing = true local model = `prop_fishing_rod_01` - lib.requestModel(model, timeout) + lib.requestModel(model, 100) local pole = CreateObject(model, GetEntityCoords(cache.ped), true, false, false) AttachEntityToEntity( pole, @@ -55,7 +110,7 @@ AddEventHandler("wasabi_fishing:startFishing", function() Wait() local unarmed = `WEAPON_UNARMED` SetCurrentPedWeapon(ped, unarmed) - showHelp(Strings.intro_instruction) + ShowHelp(Strings.intro_instruction) DisableControlAction(0, 24, true) if IsDisabledControlJustReleased(0, 24) then TaskPlayAnim(cache.ped, "mini@tennis", "forehand_ts_md_far", 1.0, -1.0, 1.0, 48, 0, 0, 0, 0) @@ -66,7 +121,7 @@ AddEventHandler("wasabi_fishing:startFishing", function() local fishData = lib.callback.await("wasabi_fishing:getFishData", 100) if lib.skillCheck(fishData.difficulty) then ClearPedTasks(cache.ped) - tryFish(fishData) + TryFish(fishData) TaskPlayAnim( cache.ped, "amb@world_human_stand_fishing@idle_a", @@ -121,8 +176,7 @@ AddEventHandler("wasabi_fishing:startFishing", function() end end) -RegisterNetEvent("wasabi_fishing:interupt") -AddEventHandler("wasabi_fishing:interupt", function() +RegisterNetEvent("wasabi_fishing:interupt", function() fishing = false ClearPedTasks(cache.ped) end) diff --git a/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua b/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua index fc87cbb1f..25acbe5d2 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua @@ -1,10 +1,10 @@ -showHelp = function(msg) +ShowHelp = function(msg) BeginTextCommandDisplayHelp("STRING") AddTextComponentSubstringPlayerName(msg) EndTextCommandDisplayHelp(0, false, true, -1) end -waterCheck = function() +WaterCheck = function() local headPos = GetPedBoneCoords(cache.ped, 31086, 0.0, 0.0, 0.0) local offsetPos = GetOffsetFromEntityInWorldCoords(cache.ped, 0.0, 50.0, -25.0) local water, waterPos = @@ -12,7 +12,7 @@ waterCheck = function() return water, waterPos end -createBlip = function(coords, sprite, colour, text, scale) +CreateBlip = function(coords, sprite, colour, text, scale) local blip = AddBlipForCoord(coords) SetBlipSprite(blip, sprite) SetBlipColour(blip, colour) @@ -24,10 +24,10 @@ createBlip = function(coords, sprite, colour, text, scale) return blip end -tryFish = function(data) +TryFish = function(data) TriggerServerEvent("wasabi_fishing:tryFish", data) end -FishingSellItems = function(distance) - TriggerServerEvent("wasabi_fishing:sellFish", distance) +FishingSellItems = function() + TriggerServerEvent("wasabi_fishing:sellFish") end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua b/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua index 2373dfe3c..9a6dd7c71 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua @@ -1,7 +1,8 @@ local seconds, minutes = 1000, 60000 Config = {} -Config.oldESX = false -- Using ESX 1.1 or older put true +Config.checkForUpdates = true -- Check for updates? +Config.oldESX = false -- Nothing to do with qb / Essentially when set to true it disables the check of if player can carry item Config.sellShop = { enabled = true, @@ -17,23 +18,24 @@ Config.bait = { Config.fishingRod = { itemName = "fishingrod", -- Item name of fishing rod - breakChance = 10, --Chance of breaking pole when failing skillbar (Setting to 0 means never break) + breakChance = 25, --Chance of breaking pole when failing skillbar (Setting to 0 means never break) } Config.timeForBite = { -- Set min and max random range of time it takes for fish to be on the line. - min = 1 * seconds, - max = 10 * seconds, + min = 2 * seconds, + max = 20 * seconds, } Config.fish = { - { item = "tuna", price = { 300, 550 }, difficulty = { "medium", "easy", "easy" } }, -- name is the item name of the fish(must be in DB of items) / Price is the range of price it will sell to fish buyer / difficulty is how many & how hard skillcheck is - { item = "salmon", price = { 235, 300 }, difficulty = { "medium", "easy" } }, - { item = "trout", price = { 190, 235 }, difficulty = { "easy", "easy" } }, - { item = "anchovy", price = { 100, 190 }, difficulty = { "easy" } }, + { item = "tuna", label = "Tuna", price = { 300, 550 }, difficulty = { "medium", "easy", "easy" } }, -- name is the item name of the fish(must be in DB of items) / Price is the range of price it will sell to fish buyer / difficulty is how many & how hard skillcheck is + { item = "salmon", label = "Salmon", price = { 235, 300 }, difficulty = { "medium", "easy" } }, + { item = "trout", label = "Trout", price = { 190, 235 }, difficulty = { "easy", "easy" } }, + { item = "anchovy", label = "Anchovy", price = { 100, 190 }, difficulty = { "easy" } }, } RegisterNetEvent("wasabi_fishing:notify") AddEventHandler("wasabi_fishing:notify", function(title, message, msgType) + -- Place notification system info here, ex: exports['mythic_notify']:SendAlert('inform', message) if not msgType then lib.notify({ title = title, diff --git a/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua b/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua index f64b6704f..d3c7eb2f7 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua @@ -14,6 +14,7 @@ Strings = { bait_lost_desc = "Fishing bait was lost.", fish_success = "Caught Fish", fish_success_desc = "You caught a %s!", + sell_shop_blip = "Fish Market", sell_fish = "[E] - Sell Fish", kicked = "Nice try, please do not attempt to exploit!", sold_for = "Sold Fish", diff --git a/server-data/resources/[wasabi]/wasabi_fishing/fxmanifest.lua b/server-data/resources/[wasabi]/wasabi_fishing/fxmanifest.lua index a6d007057..7e401fe43 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/fxmanifest.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/fxmanifest.lua @@ -2,25 +2,14 @@ fx_version("cerulean") game("gta5") lua54("yes") -description("Wasabi ESX Skill Based Fishing") -author("wasabirobby#5110") +version("2.0.7") +author("wasabirobby") +description("Wasabi ESX/QBCore Skill Based Fishing") -version("2.0.3") +shared_scripts({ "@ox_lib/init.lua", "configuration/*.lua" }) -client_scripts({ - "client/*.lua", -}) +client_scripts({ "bridge/**/client.lua", "client/*.lua" }) -server_scripts({ - "server/*.lua", -}) +server_scripts({ "bridge/**/server.lua", "server/*.lua" }) -shared_scripts({ - "@ox_lib/init.lua", - "configuration/*.lua", -}) - -dependencies({ - "es_extended", - "ox_lib", -}) +dependencies({ "ox_lib" }) diff --git a/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua b/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua index f2ae6c900..ddc327bdc 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua @@ -1,8 +1,9 @@ -ESX = exports["es_extended"]:getSharedObject() +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 xPlayer = ESX.GetPlayerFromId(source) - local item = xPlayer.getInventoryItem(itemname).count + local item = HasItem(source, itemname) if item >= 1 then return true else @@ -10,40 +11,34 @@ lib.callback.register("wasabi_fishing:checkItem", function(source, itemname) end end) -lib.callback.register("wasabi_fishing:getFishData", function() +lib.callback.register("wasabi_fishing:getFishData", function(source) local data = Config.fish[math.random(#Config.fish)] return data end) -RegisterServerEvent("wasabi_fishing:rodBroke") -AddEventHandler("wasabi_fishing:rodBroke", function() - local xPlayer = ESX.GetPlayerFromId(source) - xPlayer.removeInventoryItem(Config.fishingRod.itemName, 1) +RegisterNetEvent("wasabi_fishing:rodBroke", function() + RemoveItem(source, Config.fishingRod.itemName, 1) TriggerClientEvent("wasabi_fishing:interupt", source) end) -RegisterServerEvent("wasabi_fishing:tryFish") -AddEventHandler("wasabi_fishing:tryFish", function(data) - local xPlayer = ESX.GetPlayerFromId(source) - local xPole = xPlayer.getInventoryItem(Config.fishingRod.itemName).count - local xBait = xPlayer.getInventoryItem(Config.bait.itemName).count +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 - xPlayer.removeInventoryItem(Config.bait.itemName, 1) + RemoveItem(source, Config.bait.itemName, 1) TriggerClientEvent("wasabi_fishing:notify", source, Strings.bait_lost, Strings.bait_lost_desc, "error") end - local awardItem = data.item - local awardLabel = ESX.GetItemLabel(awardItem) - if Config.OldESX then - local limitItem = xPlayer.getInventoryItem(awardItem) - if limitItem.limit == -1 or (limitItem.count + 1) <= limitItem.limit then - xPlayer.addInventoryItem(awardItem, 1) + 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, awardLabel), + string.format(Strings.fish_success_desc, data.label), "success" ) else @@ -56,74 +51,60 @@ AddEventHandler("wasabi_fishing:tryFish", function(data) ) end else - if xPlayer.canCarryItem(awardItem, 1) then - xPlayer.addInventoryItem(awardItem, 1) - TriggerClientEvent( - "wasabi_fishing:notify", - source, - Strings.fish_success, - string.format(Strings.fish_success_desc, awardLabel), - "success" - ) - else - TriggerClientEvent( - "wasabi_fishing:notify", - source, - Strings.cannot_carry, - Strings.cannot_carry_desc, - "error" - ) - end + 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 - xPlayer.kick(Strings.kicked) + KickPlayer(source, Strings.kicked) end end) -RegisterServerEvent("wasabi_fishing:sellFish") -AddEventHandler("wasabi_fishing:sellFish", function(distance) - if distance ~= nil then - if distance <= 3 then - for i = 1, #Config.fish do - local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer.getInventoryItem(Config.fish[i].item).count > 0 then - local rewardAmount = 0 - for _ = 1, xPlayer.getInventoryItem(Config.fish[i].item).count do - rewardAmount = rewardAmount + math.random(Config.fish[i].price[1], Config.fish[i].price[2]) - end - xPlayer.addMoney(rewardAmount) - TriggerClientEvent( - "wasabi_fishing:notify", - source, - Strings.sold_for, - (Strings.sold_for_desc):format( - xPlayer.getInventoryItem(Config.fish[i].item).count, - xPlayer.getInventoryItem(Config.fish[i].item).label, - addCommas(rewardAmount) - ), - "success" - ) - xPlayer.removeInventoryItem( - Config.fish[i].item, - xPlayer.getInventoryItem(Config.fish[i].item).count - ) - 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 - else - xPlayer.kick(Strings.kicked) end - else - xPlayer.kick(Strings.kicked) end end) -ESX.RegisterUsableItem(Config.fishingRod.itemName, function(source) +RegisterUsableItem(Config.fishingRod.itemName, function(source) TriggerClientEvent("wasabi_fishing:startFishing", source) end) - -addCommas = function(n) - return tostring(math.floor(n)):reverse():gsub("(%d%d%d)", "%1,"):gsub(",(%-?)$", "%1"):reverse() -end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua b/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua new file mode 100644 index 000000000..bab52a051 --- /dev/null +++ b/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua @@ -0,0 +1,67 @@ +local curVersion = GetResourceMetadata(GetCurrentResourceName(), "version") +local resourceName = "wasabi_fishing" + +if Config.checkForUpdates then + CreateThread(function() + if GetCurrentResourceName() ~= "wasabi_fishing" then + resourceName = "wasabi_fishing (" .. GetCurrentResourceName() .. ")" + end + end) + + CreateThread(function() + while true do + PerformHttpRequest( + "https://api.github.com/repos/wasabirobby/wasabi_fishing/releases/latest", + CheckVersion, + "GET" + ) + Wait(3600000) + end + end) + + CheckVersion = function(err, responseText, headers) + local repoVersion, repoURL, repoBody = GetRepoInformations() + + CreateThread(function() + if curVersion ~= repoVersion then + Wait(4000) + print("^0[^3WARNING^0] " .. resourceName .. " is ^1NOT ^0up to date!") + print("^0[^3WARNING^0] Your Version: ^2" .. curVersion .. "^0") + print("^0[^3WARNING^0] Latest Version: ^2" .. repoVersion .. "^0") + print("^0[^3WARNING^0] Get the latest Version from: ^2" .. repoURL .. "^0") + print("^0[^3WARNING^0] Changelog:^0") + print("^1" .. repoBody .. "^0") + else + Wait(4000) + print("^0[^2INFO^0] " .. resourceName .. " is up to date! (^2" .. curVersion .. "^0)") + end + end) + end + + GetRepoInformations = function() + local repoVersion, repoURL, repoBody = nil, nil, nil + + PerformHttpRequest( + "https://api.github.com/repos/wasabirobby/wasabi_fishing/releases/latest", + function(err, response, headers) + if err == 200 then + local data = json.decode(response) + + repoVersion = data.tag_name + repoURL = data.html_url + repoBody = data.body + else + repoVersion = curVersion + repoURL = "https://github.com/wasabirobby/wasabi_fishing" + end + end, + "GET" + ) + + repeat + Wait(50) + until repoVersion and repoURL and repoBody + + return repoVersion, repoURL, repoBody + end +end diff --git a/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_limit.sql b/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_limit.sql deleted file mode 100644 index 277d33f78..000000000 --- a/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_limit.sql +++ /dev/null @@ -1,8 +0,0 @@ -INSERT INTO `items` (`name`, `label`, `limit`) VALUES - ('fishingrod', 'Fishing Rod', 20), - ('fishbait', 'Fish Bait', 20), - ('anchovy', 'Anchovy', 20), - ('trout', 'Trout', 20), - ('salmon', 'Salmon', 20), - ('tuna', 'Tuna', 40) -; diff --git a/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_weight.sql b/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_weight.sql deleted file mode 100644 index 6cc2fb54e..000000000 --- a/server-data/resources/[wasabi]/wasabi_fishing/sql/wasabi_fishing_weight.sql +++ /dev/null @@ -1,8 +0,0 @@ -INSERT INTO `items` (`name`, `label`, `weight`) VALUES - ('fishingrod', 'Fishing Rod', 20), - ('fishbait', 'Fish Bait', 20), - ('anchovy', 'Anchovy', 20), - ('trout', 'Trout', 20), - ('salmon', 'Salmon', 20), - ('tuna', 'Tuna', 40) -;