ix.class
Helper library for loading/getting class information.
Classes are temporary assignments for characters - analogous to a "job" in a faction. For example, you may have a police faction
in your schema, and have "police recruit" and "police chief" as different classes in your faction. Anyone can join a class in
their faction by default, but you can restrict this as you need with CLASS.CanSwitchTo.
Functions
ix.class.CanSwitchTo(client, class)
View source »Determines if a player is allowed to join a specific class.
Parameters
-
client
Player
Player to check
-
class
number
Index of the class
Returns
-
bool
Whether or not the player can switch to the class.
-
string
The reason why the player cannot switch (if applicable).
Example Usage
-- Check if a player can join class ID 2.
-- For our example, they can't- because they are in the wrong faction.
local canJoin, reason = ix.class.CanSwitchTo(player, 2)
if (!canJoin) then
print("Player cannot join class: "..reason)
end
> Player cannot join class: not correct team
ix.class.Get(identifier)
View source »Gets a class definition table by numeric identifier.
Parameters
-
identifier
number
Numeric class identifier.
Returns
Example Usage
-- Print the name of class ID 1
print(ix.class.Get(1).name)
> Citizen
ix.class.GetPlayers(class)
View source »Retrieves all players currently assigned to a specific class.
Parameters
-
class
number
Index of the class
Returns
-
table
Numerically indexed table of players in the class, or an empty table if none are found.
Example Usage
-- Print all players in class ID 1
for _, ply in ipairs(ix.class.GetPlayers(1)) do
print(ply:GetName())
end
> Player1
> Player2
> etc
ix.class.LoadFromDir(directory)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Loads classes from a directory.
Parameters
-
directory
string
The path to the class files.
Fields
class
View source »Class definition table returned by ix.class.Get.
-
class
table
Class definition table. Default keys:
index(number) - numeric class IDuniqueID(string) - stable identifier (e.g.citizen)name(string)description(string)- faction (number) - Faction ID this class belongs to
isDefault(boolean) - whether it is the default class for the factionlimit(number) - maximum number of players allowed in this class (0 for unlimited)- CanSwitchTo (function|nil) - optional callback to check if a player may switch