Skip to main content
Components are self-contained units of functionality that encapsulate related methods and data. They register with the framework via RegisterComponent, expose a public API, and can depend on or extend other components.

Component Structure

A typical component looks like this:
All public methods use function(self, ...) and are called with colon syntax: Component:Method(args). The self parameter is automatic with : calls.

Core Components

Provided by mythic-base, these are the essential components every resource depends on:

Callbacks

Client-server callback system (request-response)

Logger

Centralized logging with levels and Discord webhooks

Database

MongoDB and MySQL database operations

Middleware

Event middleware for pre/post processing

Fetch

Player and character data access

DataStore

Key-value persistent data storage
Usage:

Feature Components

Registered by feature resources (mythic-inventory, mythic-jobs, etc.) to expose their APIs:
Components use namespacing with dots to organize related functionality:

Creating Components

Basic Component

Component with Dependencies

Use RequestDependencies to ensure required components are loaded first:

The RetrieveComponents Pattern

Most resources use a standard pattern where RetrieveComponents() pulls all needed components into local variables:
After RetrieveComponents(), you use the local variables directly instead of X everywhere.

Component Patterns

Service Pattern

Stateless components that provide services:

Manager Pattern

Components that manage a collection of entities:

Extending Components

Use ExtendComponent to add functionality to an existing component without modifying the original resource:
ExtendComponent cannot modify protected components (_protected = true). It will fail with a warning.

Component Communication

Direct Method Calls

Event-Based Communication

Best Practices

Each component should have one clear purpose:
Never assume components are available immediately:
Always handle errors gracefully:
Prevent accidental overrides of critical components:

Next Steps

Proxy Pattern

Deep dive into RegisterComponent, FetchComponent, etc.

Event System

Complement components with events and callbacks

Resource Structure

How to organize resources using components

API Reference

Complete API documentation