Skip to main content
Server owners choose which modules run. Your resource sees a module’s API, events, hooks, enums and statebags only when that module is enabled. This page shows how to depend on a module, or adapt when it is off.

What each module gives you

  • Events and Hooks are groups of UgCore.Enums.Events and UgCore.Enums.Hooks, such as UgCore.Enums.Events.Accounts.Changed.
  • Statebags are player statebags named ug-core:<Key>, such as ug-core:Job.
  • identity, players and permissions are required. They are always there.

When a namespace exists

Your resource learns which modules are enabled when ug-core replicates them, right before Ready. Until then, and for disabled modules, module namespaces raise a clear error: Module enums, such as UgCore.Enums.DeathState or UgCore.Enums.Events.Jobs, follow the same rule: they exist once the module is enabled and replicated.
Run module code from UgCore.Lifecycle.On('Ready', ...). It runs right away when ug-core is already ready, and again after you restart your resource.

Require a module

When your resource cannot work without a module, require it. Server owners get one clear error instead of a broken resource:
server.lua
List it in your README too, so owners know before they install your resource.

Adapt to an optional module

When a module only adds something, check it and fall back:
server.lua
Register events and hooks of optional modules only when they are enabled:
server.lua

On the client

Clients follow the same rules. The client lifecycle reaches Ready after the client files of every enabled module have loaded:
client.lua
For data that changes, such as the job or the death state, watch the statebag instead of polling. See Statebags.

Check list

Declare dependency 'ug-core' and ug_core_version in your manifest.
Use module namespaces, enums and events after Ready.
Call UgCore.Modules.Require for modules you cannot work without.
Check UgCore.Modules.IsEnabled for modules you can work without.
Handle every error code a function can return. Each module page lists them.