Understanding resource load order, dependencies, and management in Mythic Framework
Proper resource loading order is critical for Mythic Framework to function correctly. Resources have dependencies on each other, and loading them in the wrong order will cause failures.
Mythic Framework uses a component-based architecture where resources register components that other resources depend on. If a resource tries to use a component before it’s registered, it will fail.
Dependency Chain
Resources depend on components from other resources. Load dependencies first.
Component Registration
Components must be registered before other resources can fetch them.
Database Access
Core resources need database connection established early.
Event Handlers
Event handlers registered in load order - later resources can override earlier ones.
# Property and housingensure mythic-properties # Depends on: finance, charactersensure mythic-apartments # Depends on: propertiesensure mythic-doors # Access control system
# Start a resourcestart mythic-inventory# Stop a resourcestop mythic-inventory# Restart a resource (stop + start)restart mythic-inventory# Ensure a resource (start if not running)ensure mythic-inventory# Refresh resource (reload files without restart)refresh mythic-inventory
Restarting Core Resources: Restarting mythic-base or mythic-characters while server is live will likely crash dependent resources. Avoid unless necessary.
# List all resources and their statusstatus# List only running resourcesresmon# Show resource information# (Use in server console or F8 client console)
ensure mythic-inventory # Dependencyensure my-custom-shop # Your resource (after dependency)
4
Use RequestDependencies
Copy
exports['mythic-base']:RequestDependencies('MyShop', { 'Inventory', 'Finance'}, function(errors) if #errors == 0 then -- Register your component endend)
Error:attempt to index field 'ComponentName' (a nil value)Cause: Trying to use a component before it’s registeredSolution:
Check the resource that provides the component is loaded first
Verify it’s in resources.cfg before the resource using it
Use RequestDependencies to wait for component:
Copy
exports['mythic-base']:RequestDependencies('MyResource', { 'MissingComponent'}, function(errors) -- Component now availableend)
Database Connection Failed
Error:Database connection not establishedCause: Resource trying to access database before oxmysql/mythic-base loadedSolution:
Ensure oxmysql is first in resources.cfg
Ensure mythic-base is second
Wait for Core:Shared:Ready event:
Copy
AddEventHandler('Core:Shared:Ready', function() -- Database now available COMPONENTS.Database:findOne(...)end)
Resource Won't Start
Error:Failed to start resource mythic-xyzCauses:
Dependency not loaded
Syntax error in resource
Missing files
Solutions:
Check console for error messages
Verify all dependencies in fxmanifest.lua are loaded
Check resource files exist
Look for Lua syntax errors
Try refresh then ensure:
Copy
refresh mythic-xyzensure mythic-xyz
Circular Dependency
Error: Resources won’t load, waiting on each otherCause: Resource A depends on B, but B also depends on ASolution:
Restructure to remove circular dependency
Move shared functionality to a third resource
Use events instead of direct component calls
Delay initialization until both are loaded
Random Component Errors After Restart
Problem: Components work initially but fail after resource restartCause: Component registration not idempotent (doesn’t clean up old registrations)Solution:
Ensure RegisterComponent is called on every start
Don’t use persistent state in components without cleanup
Implement proper cleanup in onResourceStop:
Copy
AddEventHandler('onResourceStop', function(resourceName) if resourceName == GetCurrentResourceName() then -- Cleanup logic here endend)
Golden Rule: If you’re unsure about load order, put your resource last in resources.cfg. It’s safer to load after everything else than to load too early.