Skip to content

Exports & events

Cuxial Gym public API: server and client exports, events, hooks and state bags for other resources.

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.

lua
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.

lua
local stats = exports.cuxial_gym:GetStats(source)
if stats and stats.condition.strength >= 50 then
    -- strong enough to carry the crate
end

AddStatXp ​

Adds XP to an online player's overall level.

lua
local levels = exports.cuxial_gym:AddStatXp(source, nil, xp)
ParameterTypeDescription
sourcenumberPlayer server id.
secondanyIgnored. Pass nil.
xpnumberXP to add. Must be greater than 0.

Returns: number. Levels gained; 0 if nothing was added.

lua
exports.cuxial_gym:AddStatXp(source, nil, 150)

MaxCondition ​

Sets all five attributes of an online player to 100 %, without changing their level.

lua
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.

lua
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.

lua
local ok, reason = exports.cuxial_gym:GrantMembership(target, days)
ParameterTypeDescription
targetnumber | stringServer id or citizenid.
daysnumberDays, from 1 to 3650.

Returns: boolean and, on failure, a reason: 'not_ready', 'invalid_days' or 'player_not_found'.

lua
exports.cuxial_gym:GrantMembership(source, 30)

RevokeMembership ​

Removes a player's pass.

lua
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.

lua
local membership = exports.cuxial_gym:GetMembership(target)

Returns: { expiresAt, purchasedAt, secondsLeft } (dates in Unix seconds), or nil if there is no active pass.

lua
local m = exports.cuxial_gym:GetMembership(source)
if m then
    print(('%d gym hours left'):format(m.secondsLeft // 3600))
end

Client exports ​

ExportReturnsWhat it does
IsExercising()booleantrue while the local player is doing a set.
IsHelping()booleantrue while the local player is spotting someone.
OpenGymPanel()booleanOpens the gym panel on the nearest screen. false if none is nearby.
lua
if exports.cuxial_gym:IsExercising() then
    return -- don't open the phone mid-set
end

Server events ​

Fired on the server only. Listen with AddEventHandler.

EventParametersWhen
cuxial_gym:exerciseStartedsource, ctxA player starts a set.
cuxial_gym:exerciseFinishedsource, ctxA set ends, for any reason.
cuxial_gym:statLevelUpsource, dataA player gains an overall level. data is { level, gained }.

ctx fields:

FieldTypeDescription
exerciseIdstringExercise, as in data/exercises.lua.
eqIdstringEquipment from data/gym.lua.
bodyPartstringMain body part being trained.
maxRepsnumberRep limit of the set.
repsnumberReps done. Only on finish.
freeRepsnumberReps given by a spotter or by perks. Only on finish.
levelsnumberOverall levels gained. Only on finish.
durationMsnumberSet duration. Only on finish.
reasonstringWhy 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.
lua
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 ​

HookCalledReturn
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.

server/hooks.lua
lua
function hooks.canStartExercise(src, ctx)
    -- no training outside the main world
    if GetPlayerRoutingBucket(src) ~= 0 then
        return false
    end
    return true
end

Client ​

HookCalledReturn
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 bagValue
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.
gymEffortCurrent effort level, 1 to 4; nil at rest.
lua
local stats = Player(source).state.gymStats
if stats and stats.lungs >= 75 then
    -- long dive allowed
end

Compatibility 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.

ExportWhat 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 }.
MaxAllSkillsItem function for ox_inventory. Using an item listed in compat.maxSkillsItems sets all five attributes to 100 %.
lua
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' }.

© Cuxial