Skip to content
GAMPEONCreate
New project
Preview: this works today, but details can still change.

Resource and runtime

Information about the running resource and the side it runs on.

GetCurrentResourceName() --> string

Name 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() --> integer

Milliseconds 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(name) --> integer

Hash 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() --> boolean

True 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')
end

Compared to FiveM: Same as in FiveM.

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(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(resourceName, fileName, data, dataLength?) --> boolean

Write 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(resourceName) --> string

Check 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')
end

Compared to FiveM: Same as in FiveM, without the states starting and stopping.

GetNumResources() --> integer

Number of running resources on this side. Server and client.

Returns

  • integer: Count.
print(GetNumResources())

Compared to FiveM: FiveM also counts stopped resources.

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))
end

Compared to FiveM: Same as in FiveM.

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(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(resourceName, metadataKey) --> integer

How 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(resourceName) --> boolean

Start 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(resourceName) --> boolean

Stop 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.

Report a problem with this pageOther ways to give feedback