1
0
Fork 0
forked from Simnation/Main
Main/resources/[freizeit]/[gym]/dynyx-gym/server/main.lua
2025-08-11 17:38:19 +02:00

93 lines
3.4 KiB
Lua

local QBCore = exports['qb-core']:GetCoreObject()
function Notify(source, text, status)
if Config.Notifications == "ox" then
TriggerClientEvent('ox_lib:notify', source, {
title = 'GYM',
description = text,
type = status
})
elseif Config.Notifications == "qb" then
TriggerClientEvent('QBCore:Notify', source, text, status)
else
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
local Player = QBCore.Functions.GetPlayer(src)
local cashcurr = Player.Functions.GetMoney('cash')
if cashcurr >= Config.GymPassPrice then
Player.Functions.RemoveMoney('cash', Config.GymPassPrice)
Player.Functions.AddItem(Config.GymPassItem, 1)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[Config.GymPassItem], "add")
else
Notify(src, 'Not Enough Money', 'error')
end
elseif Config.Inventory == 'ox' then
local item = exports.ox_inventory:GetItem(src, "money")
if item.count >= Config.GymPassPrice then
exports.ox_inventory:RemoveItem(src, "money", Config.GymPassPrice)
exports.ox_inventory:AddItem(src, Config.GymPassItem, 1)
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)