Skip to main content

Resource

Quick Reference

NameTypeDescription
GetStateSharedReturns the state of the specified resource.
GetCurrentNameSharedReturns the name of the currently executing resource.
CallSharedCalls an exported function in the specified resource.
StartServerStart a resource.
StopServerStop a resource.
RestartServerRestart a resource.

Shared Functions

GetState

Returns the state of the specified resource.

string state = Resource.GetState(string resource)

info

Possible states are:
"unknown"
"started"
"loaded"
"stopped"

A resource inside a category folder is addressed by its full name, e.g. "gamemodes/freeroam". The same goes for every other function on this page.


GetCurrentName

Returns the name of the currently executing resource.

string resource = Resource.GetCurrentName()


Call

Calls an exported function in the specified resource and returns whatever that function returned.

any ... = Resource.Call(string resource, string function, list arguments)

warning

This raises a script error if the resource does not exist or if the function is not exported by it. Use GetState first if the target resource may not be running.

tip

The exports table is a shorter way to write the same call.

Example:

local res1, res2 = Resource.Call("myResource", "myFunction", { 8, 16 })

Server Functions

Start

Start a resource. The returned Boolean indicates whether the action was successful.

bool success = Resource.Start(string name)

info

Returns false if the name is invalid, the resource is already running, the folder resources/<name> does not exist, or the resource failed to load. The reason is written to the server log.


Stop

Stop a resource. The returned Boolean indicates whether the action was successful.

bool success = Resource.Stop(string name)

info

The resource does not stop immediately, but only at the next resource tick.

warning

Returns false if a resourceStop handler cancelled the stop.


Restart

Restart a resource. The returned Boolean indicates whether the action was successful.

bool success = Resource.Restart(string name)

info

The resource does not restart immediately, but only at the next resource tick. Restarting a resource that is not running simply starts it.

warning

Returns false if a resourceStop handler cancelled the restart.