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