diff --git a/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua index 28794fdcf..3deb3da27 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/client.lua @@ -1,68 +1,68 @@ if GetResourceState("es_extended") ~= "started" then - return + return end ESX = exports["es_extended"]:getSharedObject() Framework, PlayerLoaded, PlayerData = "esx", nil, {} RegisterNetEvent("esx:playerLoaded", function(xPlayer) - PlayerData = xPlayer - PlayerLoaded = true + PlayerData = xPlayer + PlayerLoaded = true end) RegisterNetEvent("esx:onPlayerSpawn", function() - TriggerEvent("wasabi_fishing:onPlayerSpawn") + TriggerEvent("wasabi_fishing:onPlayerSpawn") end) AddEventHandler("esx:onPlayerDeath", function(data) - TriggerEvent("wasabi_fishing:onPlayerDeath") + TriggerEvent("wasabi_fishing:onPlayerDeath") end) RegisterNetEvent("esx:onPlayerLogout", function() - table.wipe(PlayerData) - PlayerLoaded = false + table.wipe(PlayerData) + PlayerLoaded = false end) RegisterNetEvent("esx:setJob", function(job) - PlayerData.job = job + PlayerData.job = job end) AddEventHandler("onResourceStart", function(resourceName) - if GetCurrentResourceName() ~= resourceName or not ESX.PlayerLoaded then - return - end - PlayerData = ESX.GetPlayerData() - PlayerLoaded = true + 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 + if GetInvokingResource() ~= "es_extended" then + return + end + PlayerData[key] = value end) function HasGroup(filter) - local type = type(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 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 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 + 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 index 401593169..2d56efce1 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/esx/server.lua @@ -1,91 +1,91 @@ if GetResourceState("es_extended") ~= "started" then - return + return end ESX = exports["es_extended"]:getSharedObject() Framework = "esx" function GetPlayer(source) - return ESX.GetPlayerFromId(source) + return ESX.GetPlayerFromId(source) end function KickPlayer(source, reason) - local player = GetPlayer(source) - return player.kick(reason) + local player = GetPlayer(source) + return player.kick(reason) end function HasGroup(source, filter) - local player = GetPlayer(source) - local type = type(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 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 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 + 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 + local xPlayer = ESX.GetPlayerFromId(source) + return xPlayer.identifier end function GetName(source) - local xPlayer = ESX.GetPlayerFromId(source) - return xPlayer.getName() + local xPlayer = ESX.GetPlayerFromId(source) + return xPlayer.getName() end function RegisterUsableItem(item, cb) - ESX.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 + 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) + 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) + 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) + 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) + 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 index 271812fdd..0626f160c 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua @@ -1,91 +1,87 @@ if GetResourceState("qb-core") ~= "started" then - return + 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 + 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 + 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 + 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") + TriggerEvent("wasabi_fishing:onPlayerSpawn") end) RegisterNetEvent("QBCore:Player:SetPlayerData", function(newPlayerData) - if source ~= "" and GetInvokingResource() ~= "qb-core" then - return - end - PlayerData = newPlayerData + if source ~= "" and GetInvokingResource() ~= "qb-core" then + return + end + PlayerData = newPlayerData end) function HasGroup(filter) - local groups = { "job", "gang" } - local type = type(filter) + local groups = { "job", "gang" } + local type = type(filter) - if type == "string" then - for i = 1, #groups do - local data = PlayerData[groups[i]] + 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 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 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] + 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]] + 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 + 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/client/client.lua b/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua index c1adb39cf..898a248b8 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/client/client.lua @@ -1,182 +1,123 @@ local fishing = false 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, - }) + 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: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) + 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() - if water then - if not fishing then - fishing = true - local model = `prop_fishing_rod_01` - lib.requestModel(model, 100) - local pole = CreateObject(model, GetEntityCoords(cache.ped), true, false, false) - AttachEntityToEntity( - pole, - cache.ped, - GetPedBoneIndex(cache.ped, 18905), - 0.1, - 0.05, - 0, - 80.0, - 120.0, - 160.0, - true, - true, - false, - true, - 1, - true - ) - SetModelAsNoLongerNeeded(model) - lib.requestAnimDict("mini@tennis", 100) - lib.requestAnimDict("amb@world_human_stand_fishing@idle_a", 100) - TaskPlayAnim(cache.ped, "mini@tennis", "forehand_ts_md_far", 1.0, -1.0, 1.0, 48, 0, 0, 0, 0) - Wait(3000) - TaskPlayAnim( - cache.ped, - "amb@world_human_stand_fishing@idle_a", - "idle_c", - 1.0, - -1.0, - 1.0, - 11, - 0, - 0, - 0, - 0 - ) - while fishing do - Wait() - local unarmed = `WEAPON_UNARMED` - SetCurrentPedWeapon(ped, unarmed) - 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) - TriggerEvent("wasabi_fishing:notify", Strings.waiting_bite, Strings.waiting_bite_desc, "inform") - Wait(math.random(Config.timeForBite.min, Config.timeForBite.max)) - TriggerEvent("wasabi_fishing:notify", Strings.got_bite, Strings.got_bite_desc, "inform") - Wait(1000) - local fishData = lib.callback.await("wasabi_fishing:getFishData", 100) - if lib.skillCheck(fishData.difficulty) then - ClearPedTasks(cache.ped) - TryFish(fishData) - TaskPlayAnim( - cache.ped, - "amb@world_human_stand_fishing@idle_a", - "idle_c", - 1.0, - -1.0, - 1.0, - 11, - 0, - 0, - 0, - 0 - ) - else - local breakChance = math.random(1, 100) - if breakChance < Config.fishingRod.breakChance then - TriggerServerEvent("wasabi_fishing:rodBroke") - TriggerEvent( - "wasabi_fishing:notify", - Strings.rod_broke, - Strings.rod_broke_desc, - "error" - ) - ClearPedTasks(cache.ped) - fishing = false - break - end - TriggerEvent( - "wasabi_fishing:notify", - Strings.failed_fish, - Strings.failed_fish_desc, - "error" - ) - end - elseif IsControlJustReleased(0, 194) then - ClearPedTasks(cache.ped) - break - elseif #(GetEntityCoords(cache.ped) - waterLoc) > 30 then - break - end - end - fishing = false - DeleteObject(pole) - RemoveAnimDict("mini@tennis") - RemoveAnimDict("amb@world_human_stand_fishing@idle_a") - end - else - TriggerEvent("wasabi_fishing:notify", Strings.no_water, Strings.no_water_desc, "error") - end - else - TriggerEvent("wasabi_fishing:notify", Strings.no_bait, Strings.no_bait_desc, "error") - end + 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() + if water then + if not fishing then + fishing = true + local model = `prop_fishing_rod_01` + lib.requestModel(model, 100) + local pole = CreateObject(model, GetEntityCoords(cache.ped), true, false, false) + AttachEntityToEntity(pole, cache.ped, GetPedBoneIndex(cache.ped, 18905), 0.1, 0.05, 0, 80.0, 120.0, 160.0, true, true, false, true, 1, true) + SetModelAsNoLongerNeeded(model) + lib.requestAnimDict("mini@tennis", 100) + lib.requestAnimDict("amb@world_human_stand_fishing@idle_a", 100) + TaskPlayAnim(cache.ped, "mini@tennis", "forehand_ts_md_far", 1.0, -1.0, 1.0, 48, 0, 0, 0, 0) + Wait(3000) + TaskPlayAnim(cache.ped, "amb@world_human_stand_fishing@idle_a", "idle_c", 1.0, -1.0, 1.0, 11, 0, 0, 0, 0) + while fishing do + Wait() + local unarmed = `WEAPON_UNARMED` + SetCurrentPedWeapon(ped, unarmed) + 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) + TriggerEvent("wasabi_fishing:notify", Strings.waiting_bite, Strings.waiting_bite_desc, "inform") + Wait(math.random(Config.timeForBite.min, Config.timeForBite.max)) + TriggerEvent("wasabi_fishing:notify", Strings.got_bite, Strings.got_bite_desc, "inform") + Wait(1000) + local fishData = lib.callback.await("wasabi_fishing:getFishData", 100) + if lib.skillCheck(fishData.difficulty) then + ClearPedTasks(cache.ped) + TryFish(fishData) + TaskPlayAnim(cache.ped, "amb@world_human_stand_fishing@idle_a", "idle_c", 1.0, -1.0, 1.0, 11, 0, 0, 0, 0) + else + local breakChance = math.random(1, 100) + if breakChance < Config.fishingRod.breakChance then + TriggerServerEvent("wasabi_fishing:rodBroke") + TriggerEvent("wasabi_fishing:notify", Strings.rod_broke, Strings.rod_broke_desc, "error") + ClearPedTasks(cache.ped) + fishing = false + break + end + TriggerEvent("wasabi_fishing:notify", Strings.failed_fish, Strings.failed_fish_desc, "error") + end + elseif IsControlJustReleased(0, 194) then + ClearPedTasks(cache.ped) + break + elseif #(GetEntityCoords(cache.ped) - waterLoc) > 30 then + break + end + end + fishing = false + DeleteObject(pole) + RemoveAnimDict("mini@tennis") + RemoveAnimDict("amb@world_human_stand_fishing@idle_a") + end + else + TriggerEvent("wasabi_fishing:notify", Strings.no_water, Strings.no_water_desc, "error") + end + else + TriggerEvent("wasabi_fishing:notify", Strings.no_bait, Strings.no_bait_desc, "error") + end end) RegisterNetEvent("wasabi_fishing:interupt", function() - fishing = false - ClearPedTasks(cache.ped) + 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 25acbe5d2..ffce76cff 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/client/functions.lua @@ -1,33 +1,32 @@ ShowHelp = function(msg) - BeginTextCommandDisplayHelp("STRING") - AddTextComponentSubstringPlayerName(msg) - EndTextCommandDisplayHelp(0, false, true, -1) + BeginTextCommandDisplayHelp("STRING") + AddTextComponentSubstringPlayerName(msg) + EndTextCommandDisplayHelp(0, false, true, -1) end 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 = - TestProbeAgainstWater(headPos.x, headPos.y, headPos.z, offsetPos.x, offsetPos.y, offsetPos.z) - return water, waterPos + 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 = TestProbeAgainstWater(headPos.x, headPos.y, headPos.z, offsetPos.x, offsetPos.y, offsetPos.z) + return water, waterPos end CreateBlip = function(coords, sprite, colour, text, scale) - local blip = AddBlipForCoord(coords) - SetBlipSprite(blip, sprite) - SetBlipColour(blip, colour) - SetBlipAsShortRange(blip, true) - SetBlipScale(blip, scale) - AddTextEntry(text, text) - BeginTextCommandSetBlipName(text) - EndTextCommandSetBlipName(blip) - return blip + local blip = AddBlipForCoord(coords) + SetBlipSprite(blip, sprite) + SetBlipColour(blip, colour) + SetBlipAsShortRange(blip, true) + SetBlipScale(blip, scale) + AddTextEntry(text, text) + BeginTextCommandSetBlipName(text) + EndTextCommandSetBlipName(blip) + return blip end TryFish = function(data) - TriggerServerEvent("wasabi_fishing:tryFish", data) + TriggerServerEvent("wasabi_fishing:tryFish", data) end FishingSellItems = function() - TriggerServerEvent("wasabi_fishing:sellFish") + 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 9a6dd7c71..af35a17b4 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/configuration/config.lua @@ -5,48 +5,48 @@ 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, - coords = vec3(-1612.19, -989.18, 13.01 - 0.9), -- X, Y, Z Coords of where fish buyer will spawn - heading = 45.3, -- Heading of fish buyer ped - ped = "cs_old_man2", -- Ped name here + enabled = true, + coords = vec3(-1612.19, -989.18, 13.01 - 0.9), -- X, Y, Z Coords of where fish buyer will spawn + heading = 45.3, -- Heading of fish buyer ped + ped = "cs_old_man2", -- Ped name here } Config.bait = { - itemName = "fishbait", -- Item name of bait - loseChance = 65, -- Chance of loosing bait(Setting to 100 will use bait every cast) + itemName = "fishbait", -- Item name of bait + loseChance = 65, -- Chance of loosing bait(Setting to 100 will use bait every cast) } Config.fishingRod = { - itemName = "fishingrod", -- Item name of fishing rod - breakChance = 25, --Chance of breaking pole when failing skillbar (Setting to 0 means never break) + itemName = "fishingrod", -- Item name of fishing rod + 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 = 2 * seconds, - max = 20 * seconds, + min = 2 * seconds, + max = 20 * seconds, } Config.fish = { - { 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" } }, + { 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, - description = message, - type = "inform", - }) - else - lib.notify({ - title = title, - description = message, - type = msgType, - }) - end + -- Place notification system info here, ex: exports['mythic_notify']:SendAlert('inform', message) + if not msgType then + lib.notify({ + title = title, + description = message, + type = "inform", + }) + else + lib.notify({ + title = title, + description = message, + type = msgType, + }) + end end) diff --git a/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua b/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua index d3c7eb2f7..90e71e2ca 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/configuration/strings.lua @@ -1,28 +1,28 @@ Strings = { - intro_instruction = "Press ~INPUT_ATTACK~ to cast line, ~INPUT_FRONTEND_RRIGHT~ to cancel.", - rod_broke = "Rod Snapped", - rod_broke_desc = "You pulled to hard and your fishing rod snapped!", - cannot_perform = "Action Incomplete", - cannot_perform_desc = "You cannot do this right now.", - failed = "Failed", - failed_fish = "You failed to catch fish!", - no_water = "No Water", - no_water_desc = "You are not facing any water.", - no_bait = "Missing Bait", - no_bait_desc = "You don't have fishing bait.", - bait_lost = "Bait Lost", - 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", - sold_for_desc = "You sold %sx %s for $%s", - got_bite = "Bite Detected", - got_bite_desc = "Your pole has a fish on the line, get ready!", - waiting_bite = "Awaiting Bite", - waiting_bite_desc = "Please wait for a fish to bite your hook.", - cannot_carry = "Cannot Carry", - cannot_carry_desc = "You cannot carry reward!", + intro_instruction = "Press ~INPUT_ATTACK~ to cast line, ~INPUT_FRONTEND_RRIGHT~ to cancel.", + rod_broke = "Rod Snapped", + rod_broke_desc = "You pulled to hard and your fishing rod snapped!", + cannot_perform = "Action Incomplete", + cannot_perform_desc = "You cannot do this right now.", + failed = "Failed", + failed_fish = "You failed to catch fish!", + no_water = "No Water", + no_water_desc = "You are not facing any water.", + no_bait = "Missing Bait", + no_bait_desc = "You don't have fishing bait.", + bait_lost = "Bait Lost", + 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", + sold_for_desc = "You sold %sx %s for $%s", + got_bite = "Bite Detected", + got_bite_desc = "Your pole has a fish on the line, get ready!", + waiting_bite = "Awaiting Bite", + waiting_bite_desc = "Please wait for a fish to bite your hook.", + cannot_carry = "Cannot Carry", + cannot_carry_desc = "You cannot carry reward!", } diff --git a/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua b/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua index ddc327bdc..01401b920 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/server/server.lua @@ -1,110 +1,82 @@ local addCommas = function(n) - return tostring(math.floor(n)):reverse():gsub("(%d%d%d)", "%1,"):gsub(",(%-?)$", "%1"):reverse() + 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 + 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 + 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) + 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 + 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 + 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) + TriggerClientEvent("wasabi_fishing:startFishing", source) end) diff --git a/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua b/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua index bab52a051..41ac9e7bb 100644 --- a/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua +++ b/server-data/resources/[wasabi]/wasabi_fishing/server/updater.lua @@ -2,66 +2,58 @@ 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 + 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