forked from Simnation/Main
es
This commit is contained in:
parent
c6dcdfb78a
commit
638b76bc38
2 changed files with 83 additions and 5 deletions
|
@ -1,5 +1,29 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
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()
|
CreateThread(function()
|
||||||
for k, v in pairs(Config.Threadmills) do
|
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, {
|
exports['qb-target']:AddBoxZone("treadmill"..k, v.coords - vector3(0.0, 0.0, 1.0), 1, 2, {
|
||||||
|
@ -91,7 +115,7 @@ CreateThread(function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('dynyx-gym:treadmill', function()
|
RegisterNetEvent('dynyx-gym:treadmill', function()
|
||||||
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
|
local hasItem = checkHasItem(Config.GymPassItem)
|
||||||
if hasItem then
|
if hasItem then
|
||||||
Treadmill()
|
Treadmill()
|
||||||
else
|
else
|
||||||
|
@ -100,7 +124,7 @@ RegisterNetEvent('dynyx-gym:treadmill', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('dynyx-gym:chinup', function()
|
RegisterNetEvent('dynyx-gym:chinup', function()
|
||||||
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
|
local hasItem = checkHasItem(Config.GymPassItem)
|
||||||
if hasItem then
|
if hasItem then
|
||||||
Chinup()
|
Chinup()
|
||||||
else
|
else
|
||||||
|
@ -109,7 +133,7 @@ RegisterNetEvent('dynyx-gym:chinup', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('dynyx-gym:chinup2', function()
|
RegisterNetEvent('dynyx-gym:chinup2', function()
|
||||||
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
|
local hasItem = checkHasItem(Config.GymPassItem)
|
||||||
if hasItem then
|
if hasItem then
|
||||||
Chinup2()
|
Chinup2()
|
||||||
else
|
else
|
||||||
|
@ -118,7 +142,7 @@ RegisterNetEvent('dynyx-gym:chinup2', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('dynyx-gym:liftweights', function()
|
RegisterNetEvent('dynyx-gym:liftweights', function()
|
||||||
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
|
local hasItem = checkHasItem(Config.GymPassItem)
|
||||||
if hasItem then
|
if hasItem then
|
||||||
LiftWeight()
|
LiftWeight()
|
||||||
else
|
else
|
||||||
|
@ -127,7 +151,7 @@ RegisterNetEvent('dynyx-gym:liftweights', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('dynyx-gym:yoga', function()
|
RegisterNetEvent('dynyx-gym:yoga', function()
|
||||||
local hasItem = QBCore.Functions.HasItem(Config.GymPassItem)
|
local hasItem = checkHasItem(Config.GymPassItem)
|
||||||
if hasItem then
|
if hasItem then
|
||||||
Yoga()
|
Yoga()
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,6 +13,16 @@ function Notify(source, text, status)
|
||||||
print("Config.Notifications is invalid.")
|
print("Config.Notifications is invalid.")
|
||||||
end
|
end
|
||||||
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()
|
RegisterServerEvent('dynyx_gym:BuyGymM', function()
|
||||||
local src = source
|
local src = source
|
||||||
if Config.Inventory == 'qb' then
|
if Config.Inventory == 'qb' then
|
||||||
|
@ -35,5 +45,49 @@ RegisterServerEvent('dynyx_gym:BuyGymM', function()
|
||||||
else
|
else
|
||||||
Notify(src, 'Not Enough Money', 'error')
|
Notify(src, 'Not Enough Money', 'error')
|
||||||
end
|
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
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue