Skip to content

Commit

Permalink
refactor: big update
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Jun 22, 2024
1 parent 40df466 commit fc96bc5
Show file tree
Hide file tree
Showing 14 changed files with 568 additions and 140 deletions.
14 changes: 8 additions & 6 deletions server-data/resources/[wasabi]/wasabi_fishing/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,27 +17,28 @@ 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


## Installation

- 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
<a href='https://discord.gg/79zjvy4JMs'>![Discord Banner 2](https://discordapp.com/api/guilds/1025493337031049358/widget.png?style=banner2)</a>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
91 changes: 91 additions & 0 deletions server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/client.lua
Original file line number Diff line number Diff line change
@@ -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
98 changes: 98 additions & 0 deletions server-data/resources/[wasabi]/wasabi_fishing/bridge/qb/server.lua
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit fc96bc5

Please sign in to comment.