Read a player's level and attributes, grant memberships, add XP or react to a workout from your own resources.
Attributes always use these keys: strength, endurance, speed, lungs and combat.
Server exports · progress
GetStats
Returns the overall level, XP and condition of an online player.
local stats = exports.cuxial_gym:GetStats(source)Returns: { level = number, xp = number, condition = { strength, endurance, speed, lungs, combat } }, with condition from 0 to 100; or nil if the player is not loaded.
local stats = exports.cuxial_gym:GetStats(source)
if stats and stats.condition.strength >= 50 then
-- strong enough to carry the crate
endAddStatXp
Adds XP to an online player's overall level.
local levels = exports.cuxial_gym:AddStatXp(source, nil, xp)| Parameter | Type | Description |
|---|---|---|
source | number | Player server id. |
| second | any | Ignored. Pass nil. |
xp | number | XP to add. Must be greater than 0. |
Returns: number. Levels gained; 0 if nothing was added.
exports.cuxial_gym:AddStatXp(source, nil, 150)MaxCondition
Sets all five attributes of an online player to 100 %, without changing their level.
local ok = exports.cuxial_gym:MaxCondition(source)Returns: boolean. false if the player is not loaded.
GetFatigue
Returns the current fatigue of each body part of an online player.
local fatigue = exports.cuxial_gym:GetFatigue(source)Returns: table<string, number> per body part (chest, shoulders, back, arms, abs, thighs, calves), or nil.
Server exports · membership
All three accept a server id or the character's citizenid as target. With a citizenid they also work on offline characters.
GrantMembership
Gives a player pass days. If they already have an active pass, the days are added.
local ok, reason = exports.cuxial_gym:GrantMembership(target, days)| Parameter | Type | Description |
|---|---|---|
target | number | string | Server id or citizenid. |
days | number | Days, from 1 to 3650. |
Returns: boolean and, on failure, a reason: 'not_ready', 'invalid_days' or 'player_not_found'.
exports.cuxial_gym:GrantMembership(source, 30)RevokeMembership
Removes a player's pass.
local ok, reason = exports.cuxial_gym:RevokeMembership(target)Returns: boolean and, on failure, 'not_ready', 'player_not_found' or 'no_membership'.
GetMembership
Returns a player's active pass.
local membership = exports.cuxial_gym:GetMembership(target)Returns: { expiresAt, purchasedAt, secondsLeft } (dates in Unix seconds), or nil if there is no active pass.
local m = exports.cuxial_gym:GetMembership(source)
if m then
print(('%d gym hours left'):format(m.secondsLeft // 3600))
endClient exports
| Export | Returns | What it does |
|---|---|---|
IsExercising() | boolean | true while the local player is doing a set. |
IsHelping() | boolean | true while the local player is spotting someone. |
OpenGymPanel() | boolean | Opens the gym panel on the nearest screen. false if none is nearby. |
if exports.cuxial_gym:IsExercising() then
return -- don't open the phone mid-set
endServer events
Fired on the server only. Listen with AddEventHandler.
| Event | Parameters | When |
|---|---|---|
cuxial_gym:exerciseStarted | source, ctx | A player starts a set. |
cuxial_gym:exerciseFinished | source, ctx | A set ends, for any reason. |
cuxial_gym:statLevelUp | source, data | A player gains an overall level. data is { level, gained }. |
ctx fields:
| Field | Type | Description |
|---|---|---|
exerciseId | string | Exercise, as in data/exercises.lua. |
eqId | string | Equipment from data/gym.lua. |
bodyPart | string | Main body part being trained. |
maxReps | number | Rep limit of the set. |
reps | number | Reps done. Only on finish. |
freeReps | number | Reps given by a spotter or by perks. Only on finish. |
levels | number | Overall levels gained. Only on finish. |
durationMs | number | Set duration. Only on finish. |
reason | string | Why it ended: esc_cancel, minigame_fail, max_reps, fatigue_overload, too_far, config_stop, anim_failed, server_ended, player_dropped or resource_stop. Only on finish. |
AddEventHandler('cuxial_gym:exerciseFinished', function(source, ctx)
if ctx.reps >= 20 then
-- reward a long set
end
end)Hooks
Two files are left open for your code: server/hooks.lua and client/hooks.lua. Fill in each function body; an error inside a hook is caught and printed to the console.
Server
| Hook | Called | Return |
|---|---|---|
hooks.onPlayerLoaded(src, cid, stats) | A character's gym data is loaded. | None |
hooks.onStatLevelUp(src, cid, stats, gained) | The player gains an overall level; gained is the number of levels. | None |
hooks.canStartExercise(src, ctx) | Before a set starts. | false blocks it. A second value sets the locale key of the message; error_exercise_blocked by default. |
hooks.onExerciseStarted(src, ctx) | A set starts. | None |
hooks.onExerciseFinished(src, ctx) | A set ends. | None |
stats is { level, xp, condition }, as in GetStats. ctx is the same table as in the events.
function hooks.canStartExercise(src, ctx)
-- no training outside the main world
if GetPlayerRoutingBucket(src) ~= 0 then
return false
end
return true
endClient
| Hook | Called | Return |
|---|---|---|
hooks.onExerciseRep(data) | After each rep of the local player. | false ends the set with reason config_stop. |
data is { exerciseId, eqId, reps, freeReps, maxReps, bodyPart }.
State bags
Set by the server on each player and replicated to every client. They are read-only.
| State bag | Value |
|---|---|
gymStats | { level, strength, endurance, speed, lungs, combat }: overall level and whole-number condition (0-100) of each attribute. |
gymExercise | { eqId, exerciseId, anchor, coords, helper } while training; nil otherwise. |
gymHelping | { owner, eqId } while spotting; nil otherwise. |
gymEffort | Current effort level, 1 to 4; nil at rest. |
local stats = Player(source).state.gymStats
if stats and stats.lungs >= 75 then
-- long dive allowed
endCompatibility exports
For resources written against a skill system with names such as Strength, Stamina and Running. Available as both exports.cuxial_gym and exports.CuxialGym.
| Export | What it does |
|---|---|
AddSkillToPlayer(source, skill, amount) | Adds amount × compat.xpPerPoint XP to the overall level, if skill is in compat.skills. Returns boolean. |
GetPlayerSkills(source) | Returns each skill in compat.skills with its attribute's condition (0-100), for example { Strength = 80, Stamina = 45, Running = 60 }. |
MaxAllSkills | Item function for ox_inventory. Using an item listed in compat.maxSkillsItems sets all five attributes to 100 %. |
exports.CuxialGym:AddSkillToPlayer(source, 'Strength', 2)The gym_max_power item uses MaxAllSkills; its block is in Installation. To use it with another item, add it to compat.maxSkillsItems and give it server = { export = 'cuxial_gym.MaxAllSkills' }.
