Class Definitions
Character class definition system for the Lilia framework.
Overview
The class system provides comprehensive functionality for defining character classes within the Lilia framework. Classes represent specific roles or professions that characters can assume within factions, creating a hierarchical structure where factions serve as parent containers for classes.
Faction-Class Relationship:
-
Factions are the main organizational units (Citizens, Police, Medical, etc.)
-
Classes are sub-divisions within factions (Officer, Detective, Captain within Police)
-
Each character belongs to exactly ONE faction and ONE class within that faction
-
Classes inherit all properties from their parent faction by default
-
CLASS settings overpower FACTION settings - any property defined in a class takes precedence over the same property in the parent faction.
Example Hierarchy:
Faction: Police Department
âââ Class: Police Officer (inherits police models, weapons, color)
âââ Class: Police Detective (inherits police properties, overrides with detective-specific items)
âââ Class: Police Captain (inherits police properties, overrides with command-specific permissions)
âââ Class: SWAT Officer (inherits police properties, overrides with tactical gear)
Classes are defined using the CLASS table structure, which includes properties for identification, visual representation, gameplay mechanics, and access control. The system includes callback methods that are automatically invoked during key character lifecycle events, enabling dynamic behavior and customization.
Classes can have player limits, whitelist requirements, specialized loadouts, and attribute modifications that affect gameplay. The system supports modifying player health, armor, movement speeds, model scale, weapons, and NPC relationships, providing a flexible foundation for role-based gameplay systems.
Access Control:
Classes use the isWhitelisted property to require whitelist access, and the OnCanBe callback
method to implement custom permission logic. The OnCanBe callback is called when a player attempts
to join a class and can check attributes, permissions, or any other conditions before allowing access.
In addition to the CLASS table properties, classes can also modify character variables such as classwhitelists to control which classes a character has access to.
name
đ Purpose
Sets the display name of the character class
â° When Called
During class definition
đĄ Example Usage
desc
đ Purpose
Sets the description of the character class
â° When Called
During class definition
đĄ Example Usage
faction
đ Purpose
Sets the faction ID this class belongs to
â° When Called
During class definition
đĄ Example Usage
limit
đ Purpose
Sets the maximum number of players allowed in this class
â° When Called
During class definition
đĄ Example Usage
model
đ Purpose
Sets the player model for this class
â° When Called
During class definition
đĄ Example Usage
isWhitelisted
đ Purpose
Sets whether this class requires whitelist access
â° When Called
During class definition
đĄ Example Usage
isDefault
đ Purpose
Sets whether this is the default class for the faction
â° When Called
During class definition
đĄ Example Usage
scoreboardHidden
đ Purpose
Hides this class from the scoreboard display
â° When Called
During class definition
đĄ Example Usage
pay
đ Purpose
Sets the salary amount for this class
â° When Called
During class definition
đĄ Example Usage
uniqueID
đ Purpose
Unique identifier for the class (INTERNAL - set automatically when registered)
â° When Called
Set automatically during class registration Note: This property is internal and should not be modified directly
đĄ Example Usage
-- This is set automatically when you register the class
lia.class.register("police_officer", {
name = "Police Officer",
-- uniqueID will be "police_officer"
})
index
đ Purpose
Numeric index of the class in the class list (set automatically)
â° When Called
Set automatically during class registration
đĄ Example Usage
-- This is set automatically when you register the class
lia.class.register("police_officer", {
name = "Police Officer",
-- index will be assigned based on registration order
})
Color
đ Purpose
Sets the team/class color for UI elements and identification
â° When Called
During class definition
đĄ Example Usage
health
đ Purpose
Sets the maximum health for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
armor
đ Purpose
Sets the armor value for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
weapons
đ Purpose
Sets weapons to give to players when they join this class
â° When Called
During class definition (applied when player spawns)
đĄ Example Usage
CLASS.weapons = {"weapon_pistol", "weapon_stunstick"} -- Table of weapons
CLASS.weapons = "weapon_crowbar" -- Single weapon string
scale
đ Purpose
Sets the model scale for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
runSpeed
đ Purpose
Sets the running speed for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
CLASS.runSpeed = 300 -- Absolute run speed
CLASS.runSpeedMultiplier = true
CLASS.runSpeed = 1.2 -- 20% faster than default
walkSpeed
đ Purpose
Sets the walking speed for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
CLASS.walkSpeed = 150 -- Absolute walk speed
CLASS.walkSpeedMultiplier = true
CLASS.walkSpeed = 1.1 -- 10% faster than default
jumpPower
đ Purpose
Sets the jump power for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
CLASS.jumpPower = 200 -- Absolute jump power
CLASS.jumpPowerMultiplier = true
CLASS.jumpPower = 1.3 -- 30% higher jump
NPCRelations
đ Purpose
Sets NPC relationship overrides for this class (inherits from faction)
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
CLASS.NPCRelations = {
["npc_metropolice"] = D_LI, -- Police are liked by metropolice
["npc_citizen"] = D_NU -- Neutral to citizens
}
bloodcolor
đ Purpose
Sets the blood color for players in this class
â° When Called
During class definition (applied when player joins class)
đĄ Example Usage
CLASS.bloodcolor = BLOOD_COLOR_RED -- Red blood
CLASS.bloodcolor = BLOOD_COLOR_YELLOW -- Yellow blood for aliens
runSpeedMultiplier
đ Purpose
Whether runSpeed should be treated as a multiplier instead of absolute value
â° When Called
During class definition (used with runSpeed property)
đĄ Example Usage
walkSpeedMultiplier
đ Purpose
Whether walkSpeed should be treated as a multiplier instead of absolute value
â° When Called
During class definition (used with walkSpeed property)
đĄ Example Usage
jumpPowerMultiplier
đ Purpose
Whether jumpPower should be treated as a multiplier instead of absolute value
â° When Called
During class definition (used with jumpPower property)
đĄ Example Usage
OnCanBe
đ Purpose
Check if a player can join this class
â° When Called
When a player attempts to join this class
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player trying to join |
âŠī¸ Returns
- true to allow, false to deny
đĄ Example Usage
function CLASS:OnCanBe(client)
local char = client:getChar()
if char then
-- Check character attributes
if char:getAttrib("str", 0) < 10 then
client:notify("You need at least 10 strength to join this class.")
return false
end
-- Check permissions (use framework permission system)
if not client:hasFlags("P") then -- Example permission flag
client:notify("You don't have permission to join this class.")
return false
end
-- Check custom conditions
if char:getData("banned_from_class", false) then
client:notify("You are banned from this class.")
return false
end
end
return true
end
OnSet
đ Purpose
Called when a player joins this class
â° When Called
When a player is assigned to this class
đ Realm
Server
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player joining the class |
đĄ Example Usage
OnTransferred
đ Purpose
Called when switching from another class to this class
â° When Called
When a player switches classes and this becomes the new class
đ Realm
Server
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player switching classes |
oldClass |
table | The previous class data |
đĄ Example Usage
function CLASS:OnTransferred(client, oldClass)
if oldClass then
client:notify("Switched from " .. oldClass.name .. " to " .. self.name)
end
end
OnSpawn
đ Purpose
Called when a player spawns with this class
â° When Called
When a player spawns with this class
đ Realm
Server
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player spawning |
đĄ Example Usage
function CLASS:OnSpawn(client)
client:Give("weapon_stunstick")
client:SetHealth(150)
client:SetArmor(50)
end
OnLeave
đ Purpose
Called when leaving this class
â° When Called
When a player leaves this class
đ Realm
Server
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
client |
Player | The player leaving |
đĄ Example Usage
Complete Examples
The following examples demonstrate how to use all the properties and methods together to create complete definitions.
Complete Class Example
Below is a comprehensive example showing how to define a complete class with all available properties and methods. This example creates a "Police Officer" class that demonstrates typical usage of the class system.
CLASS.name = "Police Officer"
CLASS.desc = "A law enforcement officer responsible for maintaining order"
CLASS.faction = FACTION_POLICE
CLASS.limit = 5 -- Maximum 5 players
CLASS.limit = 0 -- Unlimited players
CLASS.model = "models/player/barney.mdl"
CLASS.isWhitelisted = true -- Requires whitelist permission to join
CLASS.isDefault = true
CLASS.scoreboardHidden = true -- Class will not appear in scoreboard categories
CLASS.pay = 100 -- $100 salary
-- This is set automatically when you register the class
lia.class.register("police_officer", {
name = "Police Officer",
-- uniqueID will be "police_officer"
})
-- This is set automatically when you register the class
lia.class.register("police_officer", {
name = "Police Officer",
-- index will be assigned based on registration order
})
CLASS.Color = Color(0, 100, 255) -- Blue color for police
CLASS.health = 150 -- Police officers have 150 max health
CLASS.armor = 50 -- Police officers have 50 armor
CLASS.weapons = {"weapon_pistol", "weapon_stunstick"} -- Table of weapons
CLASS.weapons = "weapon_crowbar" -- Single weapon string
CLASS.scale = 1.1 -- Slightly larger model
CLASS.runSpeed = 300 -- Absolute run speed
CLASS.runSpeedMultiplier = true
CLASS.runSpeed = 1.2 -- 20% faster than default
CLASS.walkSpeed = 150 -- Absolute walk speed
CLASS.walkSpeedMultiplier = true
CLASS.walkSpeed = 1.1 -- 10% faster than default
CLASS.jumpPower = 200 -- Absolute jump power
CLASS.jumpPowerMultiplier = true
CLASS.jumpPower = 1.3 -- 30% higher jump
CLASS.NPCRelations = {
["npc_metropolice"] = D_LI, -- Police are liked by metropolice
["npc_citizen"] = D_NU -- Neutral to citizens
}
CLASS.bloodcolor = BLOOD_COLOR_RED -- Red blood
CLASS.bloodcolor = BLOOD_COLOR_YELLOW -- Yellow blood for aliens
CLASS.runSpeedMultiplier = true
CLASS.runSpeed = 1.2 -- 20% faster than default
CLASS.walkSpeedMultiplier = true
CLASS.walkSpeed = 1.1 -- 10% faster than default
CLASS.jumpPowerMultiplier = true
CLASS.jumpPower = 1.3 -- 30% higher jump
function CLASS:OnCanBe(client)
local char = client:getChar()
if char then
-- Check character attributes
if char:getAttrib("str", 0) < 10 then
client:notify("You need at least 10 strength to join this class.")
return false
end
-- Check permissions (use framework permission system)
if not client:hasFlags("P") then -- Example permission flag
client:notify("You don't have permission to join this class.")
return false
end
-- Check custom conditions
if char:getData("banned_from_class", false) then
client:notify("You are banned from this class.")
return false
end
end
return true
end
function CLASS:OnSet(client)
client:notify("Welcome to " .. self.name)
end
function CLASS:OnTransferred(client, oldClass)
if oldClass then
client:notify("Switched from " .. oldClass.name .. " to " .. self.name)
end
end
function CLASS:OnSpawn(client)
client:Give("weapon_stunstick")
client:SetHealth(150)
client:SetArmor(50)
end
function CLASS:OnLeave(client)
client:StripWeapon("weapon_stunstick")
end
CLASS.name = "Police Officer"
CLASS.desc = "A law enforcement officer responsible for maintaining order and protecting citizens"
CLASS.faction = FACTION_CITY
-- Access Control
CLASS.limit = 8 -- Maximum 8 officers
CLASS.isWhitelisted = true -- Requires whitelist
CLASS.isDefault = false -- Not the default class for the faction
-- Visual Properties
CLASS.model = "models/player/police.mdl"
CLASS.Color = Color(0, 100, 255) -- Blue color for police
CLASS.scale = 1.0 -- Normal model scale
CLASS.bloodcolor = BLOOD_COLOR_RED
-- Gameplay Properties
CLASS.health = 120 -- Higher health than default
CLASS.armor = 50 -- Standard police armor
CLASS.pay = 150 -- $150 salary per paycheck
-- Weapons (given when spawning)
CLASS.weapons = {
"weapon_pistol",
"weapon_stunstick",
"weapon_police_baton"
}
-- Movement Properties
CLASS.runSpeed = 280 -- Slightly slower than default for tactical movement
CLASS.walkSpeed = 150 -- Standard walking speed
CLASS.jumpPower = 200 -- Standard jump power
-- NPC Relationships (overrides faction settings)
CLASS.NPCRelations = {
["npc_metropolice"] = D_LI, -- Liked by metropolice
["npc_citizen"] = D_NU, -- Neutral to citizens
["npc_rebel"] = D_HT -- Hated by rebels
}
-- Callback Methods
function CLASS:OnCanBe(client)
local char = client:getChar()
if char then
-- Check if character has required attributes
if char:getAttrib("str", 0) < 10 then
client:notify("You need at least 10 strength to become a police officer.")
return false
end
-- Check if character has criminal record
if char:getData("criminal_record", false) then
client:notify("You cannot become a police officer with a criminal record.")
return false
end
-- Check for police-specific permissions
if not client:hasFlags("P") then
client:notify("You don't have permission to become a police officer.")
return false
end
end
return true
end
function CLASS:OnSet(client)
client:notify("Welcome to the City Police Department, Officer!")
-- Could add police radio equipment here
end
function CLASS:OnSpawn(client)
-- Set up police-specific spawn behavior
client:Give("weapon_police_radio")
client:Give("item_police_badge")
-- Apply police-specific effects
client:SetHealth(self.health)
client:SetArmor(self.armor)
end
function CLASS:OnTransferred(client, oldClass)
if oldClass then
client:notify("You have been transferred from " .. oldClass.name .. " to Police Officer.")
end
-- Update police database records
-- Could trigger promotion/demotion logic here
end
function CLASS:OnLeave(client)
-- Clean up police-specific items and effects
client:StripWeapon("weapon_police_radio")
client:StripWeapon("weapon_police_badge")
client:notify("You are no longer a police officer.")
end