class Resource
package fivem.shared.core
Information about the running resource and its neighbours, plus the start/stop lifecycle hooks every resource ends up needing.
Resource.onStart(() -> Logger.info(null, "ready"));
Resource.onStop(() -> cleanUpSpawnedEntities());
if (Resource.isStarted("oxmysql")) enableDatabaseFeatures();
Works identically on client and server; the lifecycle events differ in name
between the two (onResourceStart vs onClientResourceStart) and this
papers over that difference.
Static methods
staticcurrent():String
The name of the resource this code is running in. Cached after the first call.
staticinlineinvoking():String
The resource that called into this one — set during an export or event
triggered from elsewhere, null otherwise. Useful for permission
checks on exports you don't want every resource calling.
staticinlineisStarted(resourceName:String):Bool
Whether resourceName is running. The usual way to soft-depend on another resource.
staticinlinemetadata(resourceName:String, key:String, index:Int = 0):String
Reads a value from a resource's fxmanifest.lua. index selects among
repeated keys — metadata(name, "client_script", 0) gives the first
declared client script.
staticinlinemetadataCount(resourceName:String, key:String):Int
How many values a repeated manifest key has.
staticonAnyStart(handler:(resourceName:String) ‑> Void):Void
Runs handler when any resource starts, passing its name.
staticonAnyStop(handler:(resourceName:String) ‑> Void):Void
Runs handler when any resource stops, passing its name.
staticonStart(handler:() ‑> Void):Void
Runs handler when this resource starts.
Registered handlers only fire for this resource, which is almost
always what you want — use onAnyStart if you need to react to others.
staticonStop(handler:() ‑> Void):Void
Runs handler when this resource stops — the place to delete spawned
entities, remove blips and clear NUI focus so a restart doesn't leak.