1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-11 17:38:19 +02:00
parent c6dcdfb78a
commit 638b76bc38
2 changed files with 83 additions and 5 deletions

View file

@ -1,5 +1,29 @@
local QBCore = exports['qb-core']:GetCoreObject()
-- Check if player has an item (uses server-side check for compatibility with all inventory systems)
local function checkHasItem(item)
local hasItem = false
local checkComplete = false
-- Request item check from server
TriggerServerEvent('dynyx_gym:server:CheckItem', item)
-- Wait for response
RegisterNetEvent('dynyx_gym:client:ItemCheckResult', function(result)
hasItem = result
checkComplete = true
end)
-- Wait for the response with a timeout
local timeout = 500 -- 500ms timeout
local start = GetGameTimer()
while not checkComplete and GetGameTimer() - start < timeout do
Wait(0)
end
return hasItem
end
CreateThread(function()
for k, v in pairs(Config.Threadmills) do
exports['qb-target']:AddBoxZone("treadmill"..k, v.coords - vector3(0.0, 0.0, 1.0), 1, 2, {
@ -91,7 +115,7 @@ CreateThread(function()
end)
RegisterNetEvent('dynyx-gym:treadmill', function()
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
local hasItem = checkHasItem(Config.GymPassItem)
if hasItem then
Treadmill()
else
@ -100,7 +124,7 @@ RegisterNetEvent('dynyx-gym:treadmill', function()
end)
RegisterNetEvent('dynyx-gym:chinup', function()
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
local hasItem = checkHasItem(Config.GymPassItem)
if hasItem then
Chinup()
else
@ -109,7 +133,7 @@ RegisterNetEvent('dynyx-gym:chinup', function()
end)
RegisterNetEvent('dynyx-gym:chinup2', function()
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
local hasItem = checkHasItem(Config.GymPassItem)
if hasItem then
Chinup2()
else
@ -118,7 +142,7 @@ RegisterNetEvent('dynyx-gym:chinup2', function()
end)
RegisterNetEvent('dynyx-gym:liftweights', function()
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
local hasItem = checkHasItem(Config.GymPassItem)
if hasItem then
LiftWeight()
else
@ -127,7 +151,7 @@ RegisterNetEvent('dynyx-gym:liftweights', function()
end)
RegisterNetEvent('dynyx-gym:yoga', function()
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
local hasItem = checkHasItem(Config.GymPassItem)
if hasItem then
Yoga()
else

View file

@ -13,6 +13,16 @@ function Notify(source, text, status)
print("Config.Notifications is invalid.")
end
end
-- Check if TGIANN inventory is available
local function isTGIANNAvailable()
local available = false
pcall(function()
available = exports["tgiann-inventory"] ~= nil
end)
return available
end
RegisterServerEvent('dynyx_gym:BuyGymM', function()
local src = source
if Config.Inventory == 'qb' then
@ -35,5 +45,49 @@ RegisterServerEvent('dynyx_gym:BuyGymM', function()
else
Notify(src, 'Not Enough Money', 'error')
end
elseif Config.Inventory == 'tgiann' then
if isTGIANNAvailable() then
local money = exports["tgiann-inventory"]:GetItemByName(src, "money")
if money and money.amount >= Config.GymPassPrice then
local success = exports["tgiann-inventory"]:RemoveItem(src, "money", Config.GymPassPrice)
if success then
exports["tgiann-inventory"]:AddItem(src, Config.GymPassItem, 1)
Notify(src, 'You purchased a gym membership!', 'success')
else
Notify(src, 'Transaction Failed', 'error')
end
else
Notify(src, 'Not Enough Money', 'error')
end
else
print("TGIANN Inventory not available but configured to be used!")
Notify(src, 'System Error', 'error')
end
else
print("Invalid Config.Inventory setting: " .. Config.Inventory)
Notify(src, 'System Error', 'error')
end
end)
-- Server-side function to check if player has an item
RegisterNetEvent('dynyx_gym:server:CheckItem', function(item)
local src = source
local hasItem = false
if Config.Inventory == 'qb' then
local Player = QBCore.Functions.GetPlayer(src)
hasItem = Player.Functions.HasItem(item)
elseif Config.Inventory == 'ox' then
local count = exports.ox_inventory:GetItem(src, item, nil, true)
hasItem = count > 0
elseif Config.Inventory == 'tgiann' then
if isTGIANNAvailable() then
hasItem = exports["tgiann-inventory"]:HasItem(src, item, 1)
else
print("TGIANN Inventory not available but configured to be used!")
end
end
TriggerClientEvent('dynyx_gym:client:ItemCheckResult', src, hasItem)
end)