Resource and runtime
Information about the running resource and the side it runs on.
GetCurrentResourceName
Section titled “GetCurrentResourceName”GetCurrentResourceName() --> stringName of the resource this script belongs to. Server and client.
Returns
string: Folder name of the resource.
print('Started ' .. GetCurrentResourceName())Compared to FiveM: Same as in FiveM.
GetGameTimer
Section titled “GetGameTimer”GetGameTimer() --> integerMilliseconds since the runtime started. Use it to measure time. Server and client.
Returns
integer: Milliseconds.
local started = GetGameTimer()Wait(250)print(GetGameTimer() - started)Compared to FiveM: Same as in FiveM.
GetHashKey
Section titled “GetHashKey”GetHashKey(name) --> integerHash of a name, for example of a model name. Same numbers as in FiveM. Server and client.
Jenkins one-at-a-time hash of the lower-case text as a signed 32-bit number. Functions that take a model accept the hash or the name itself.
| Parameter | Type | Description |
|---|---|---|
name |
string |
Text to hash, for example “prop_cube”. Upper and lower case give the same hash. |
Returns
integer: Hash between -2147483648 and 2147483647.
local model = GetHashKey('prop_cube')print(IsModelValid(model))Compared to FiveM: Same as in FiveM. Backtick hashes (prop_cube) are not supported, use GetHashKey.
IsDuplicityVersion
Section titled “IsDuplicityVersion”IsDuplicityVersion() --> booleanTrue on the server, false on the client. Server and client.
Useful in shared scripts that run on both sides.
Returns
boolean: true on the server.
if IsDuplicityVersion() then print('running on the server')endCompared to FiveM: Same as in FiveM.
GetInvokingResource
Section titled “GetInvokingResource”GetInvokingResource() --> string?Name of the resource that called the current export or triggered the current local event. Server and client.
Returns
string?: Resource name, or nil inside network events, threads and timers.
exports('Pay', function(amount) print(GetInvokingResource() .. ' wants to pay ' .. amount)end)Compared to FiveM: Same as in FiveM.
LoadResourceFile
Section titled “LoadResourceFile”LoadResourceFile(resourceName, fileName) --> string?Read a file from a resource folder. Server and client.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource, for example GetCurrentResourceName(). |
fileName |
string |
Path inside the resource, for example “data/items.json”. |
Returns
string?: File content, or nil if the file does not exist.
local items = json.decode(LoadResourceFile(GetCurrentResourceName(), 'data/items.json'))Compared to FiveM: Same as in FiveM. Paths cannot leave the resource folder. Files up to 16 MB.
SaveResourceFile
Section titled “SaveResourceFile”SaveResourceFile(resourceName, fileName, data, dataLength?) --> booleanWrite a file into the own resource folder. Server only.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Must be the own resource. |
fileName |
string |
Path inside the resource. The folder must exist. |
data |
string |
Content. |
dataLength (optional) |
integer |
Number of bytes to write, or -1 for all. |
Returns
boolean: true if written.
SaveResourceFile(GetCurrentResourceName(), 'data/state.json', json.encode(state), -1)Compared to FiveM: FiveM allows writing into any resource; GAMPEON only into the own one.
GetResourceState
Section titled “GetResourceState”GetResourceState(resourceName) --> stringCheck if a resource runs. Server and client.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
Returns
string: “started”, “stopped” (known but not running) or “missing”.
if GetResourceState('gp_inventory') ~= 'started' then print('inventory missing')endCompared to FiveM: Same as in FiveM, without the states starting and stopping.
GetNumResources
Section titled “GetNumResources”GetNumResources() --> integerNumber of running resources on this side. Server and client.
Returns
integer: Count.
print(GetNumResources())Compared to FiveM: FiveM also counts stopped resources.
GetResourceByFindIndex
Section titled “GetResourceByFindIndex”GetResourceByFindIndex(findIndex) --> string?Name of the running resource at an index, for loops over all resources. Server and client.
| Parameter | Type | Description |
|---|---|---|
findIndex |
integer |
0 to GetNumResources() - 1. |
Returns
string?: Resource name.
for i = 0, GetNumResources() - 1 do print(GetResourceByFindIndex(i))endCompared to FiveM: Same as in FiveM.
GetResourcePath
Section titled “GetResourcePath”GetResourcePath(resourceName) --> string?Folder of a resource on the server. Server only.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
Returns
string?: Path, or nil if unknown.
print(GetResourcePath(GetCurrentResourceName()))Compared to FiveM: Same as in FiveM.
GetResourceMetadata
Section titled “GetResourceMetadata”GetResourceMetadata(resourceName, metadataKey, index?) --> string?Read a value from the manifest of a running resource. Server and client.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
metadataKey |
string |
Directive, for example “version”, “author” or “ui_page”. |
index (optional) |
integer |
0 for the first value. |
Returns
string?: The value, or nil.
local version = GetResourceMetadata(GetCurrentResourceName(), 'version', 0)Compared to FiveM: Same as in FiveM.
GetNumResourceMetadata
Section titled “GetNumResourceMetadata”GetNumResourceMetadata(resourceName, metadataKey) --> integerHow many values a manifest directive has. Server and client.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
metadataKey |
string |
Directive. |
Returns
integer: Count.
print(GetNumResourceMetadata('myres', 'dependency'))Compared to FiveM: Same as in FiveM.
StartResource
Section titled “StartResource”StartResource(resourceName) --> booleanStart a resource and its dependencies. Server only.
Needs the permission command.start for the calling resource: add_ace resource.<name> command.start allow.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
Returns
boolean: true if it runs afterwards.
Compared to FiveM: Same as in FiveM.
StopResource
Section titled “StopResource”StopResource(resourceName) --> booleanStop a resource and everything that depends on it. Server only.
Needs the permission command.stop for the calling resource.
| Parameter | Type | Description |
|---|---|---|
resourceName |
string |
Resource name. |
Returns
boolean: true if it was running.
Compared to FiveM: Same as in FiveM.