Skip to main content
The Characters system manages player characters in Mythic Framework, including creation, selection, loading, and data persistence. Character data is accessed through the Fetch component using the DataStore pattern.
Critical: Do NOT use Characters:GetCharacter() - this method does not exist.Always use the Fetch component:

Overview

Multi-Character

Support for multiple characters per player

DataStore Pattern

In-memory state management with GetData/SetData

Auto-Save

MongoDB persistence with periodic saves

Fetch Component

Primary API for character access

Accessing Characters

Getting Active Character

The primary way to access character data is through the Fetch component. Pattern:
Example in Event Handler:

Character Data Access Methods

Once you have a character DataStore object, use these methods:

GetData

Retrieve character data. Signature:
Parameters: Common Character Fields:
  • SID (number) - State ID (primary key)
  • First (string) - First name
  • Last (string) - Last name
  • DOB (string) - Date of birth
  • Gender (number) - Gender code
  • Phone (string) - Phone number
  • Jobs (table) - Array of job objects (each with Id, WorkplaceId, GradeId, GradeLevel)
  • Cash (number) - Cash on hand
  • MetaData (table) - Additional character data
Examples:

SetData

Update character data. Signature:
Parameters:
Character SetData automatically syncs to client with Characters:Client:SetData event.
Examples:

Finding Characters

By Server Source

Get character by player server ID (most common). Example:
See: Core - Fetch: Source

By State ID (SID)

Find player by character State ID. Example:
See: Core - Fetch: SID

By Character Data Field

Find player by any character field (phone, name, etc). Example:
See: Core - Fetch: CharacterData

Offline Character Data

Get specific data from offline character (database query). Example:
GetOfflineData is synchronous and blocks the thread. Use sparingly and only when player is offline.
See: Core - Fetch: GetOfflineData

Common Patterns

Safe Character Access

Always validate player and character exist:

Cash Management

Adding/Removing Cash:
Remove Cash with Validation:
Checking Cash:
Bank balances are managed through the Banking component (Banking.Balance:Get/Deposit/Withdraw/Charge), not through character SetData. See the Banking API for bank operations.

Iterating All Online Characters


Getting Player Source from SID


Character Management Events

These events are triggered internally by the Characters system. You can listen to them but should not trigger them directly.

Character Selection

Event: Characters:Server:PlayerLoggedIn Triggered when player selects a character and spawns. Parameters:
  • source (number) - Player server ID
Example:

Character Logout

Event: Characters:Server:PlayerDropped Triggered when player disconnects. Parameters:
  • source (number) - Player server ID
Example:

Best Practices

✅ Correct:
❌ Wrong:
Character SID is the primary key for database queries:
Use GetData/SetData methods, not direct table access:

Complete Examples

Job Payment System


Shop Purchase System


Next Steps

Core - Fetch

Complete Fetch component documentation

Characters - Events

Character-related events

Characters - Data Structure

Character data schema

Inventory API

Inventory management
Critical Pattern: Always use Fetch:Source(source) to get the player, then player:GetData('Character') to get the character. This is the ONLY correct way to access character data.