- Documentation
- Resources
Category
Resources
All Lua functions and events in the Resources category, on the server and the client.
Server functions 35
abortAborts a running HTTP request. In the current server version it cannot be aborted yet: the function returnsRemote Request falsewith a warning, and the request ends by itself after thefetchRemotetimeout.addAdds a config file (Resource Config <config src type>) to themeta.xmlof a resource – your own, or one this script created withcreateResource. Adding the same file twice changes nothing.addAdds a map file (Resource Map <map src dimension>) to themeta.xmlof a resource – your own, or one this script created withcreateResource. The map loads the next time the resource starts.callCalls a function exposed by another server over HTTP (arguments go as JSON in a POST request). In the current server version the function does not send the request and returnsRemote false; usefetchRemotewithtoJSONinstead.copyCopies a resource under a new name. In the current server version the function is not wired up yet and returnsResource falsewith a warning.createCreates a new empty resource (a folder withResource meta.xml) inresources/, optionally in a category such as[maps]. The name may contain letters, digits,_and-; if such a resource already exists it returnsfalse. The script that created the resource may then write files in it with a":name/file"path (fileCreate,xmlCreateFile), add entries withaddResourceMap/addResourceConfigand delete it withdeleteResource. Start the new resource withstartResource; on the next server start it starts by itself.deleteDeletes a stopped resource from disk together with its folder. A script may delete only a resource it created itself withResource createResource.fetchSends an HTTP or HTTPS request and passes the response to a callback without blocking the server. WithRemote postDatait makes a POST request, without it a GET. The function gets the response body and a code:0= success, the HTTP status number on a server error,-1when there is no connection or it timed out.getReturns the state of an HTTP request: the address, progress and size. In the current server version it returnsRemote Request Info false.getReturns the running HTTP requests (of every resource or one). In the current server version the list is empty.Remote Requests getReturns the rights a resource asks for inResource ACLRequests meta.xml(aclrequestsin<info>). Each entry is a table with the right name and its state.getOpens a resource's XML config file (e.g.Resource Config <config src="settings.xml"/>frommeta.xml) and returns its root node. Read it with thexml*functions and close it withxmlUnloadFileat the end.getReturns the root of the elements a resource creates while running. In Trilogy Hub it is the same element asResource Dynamic Element Root getResourceRootElement.getReturns the handle of the resource with the given name (the folder name inResource From Name resources/), also when the resource is not running. Pass the handle tostartResource,getResourceState,calland other resource functions.getThe root of a resource's GUI elements. The GUI only exists on players' clients, so on the server the function always returnsResource GUIElement false.getReturns an attribute value fromResource Info <info>in the resource'smeta.xml, e.g.name,author,version,type,description.getReturns when the resource last started (seconds since 1970) orResource Last Start Time 0. In the current server version it always returns0.getReturns why a resource failed to start. An empty string = no error. In the current server version it always returns an empty string; load errors show up in the server console.Resource Load Failure Reason getReturns how many milliseconds the last resource load took. In the current server version it returnsResource Load Time false.getReturns the element of a map loaded from the resource'sResource Map Root Element .mapfile; its children are the objects, vehicles and other elements from that map.getReturns the resource name from its handle.Resource Name getReturns the subfolder the resource sits in insideResource Organizational Path resources/(e.g.[gamemodes]). An empty string when it sits directly inresources/.getReturns the resource's root element. Everything the resource creates is its child, and events attached to this root only concern this resource. Without an argument it returns the current resource's root (the same asResource Root Element resourceRoot).getReturns every resource in theResources resources/folder, running and stopped.getReturns the resource state:Resource State "running"when it runs or"loaded"when it is on disk but stopped. It also works on the client: there it only knows the resources running for the player, so it returns"running"orfalse.isChecks whether a resource is packed in a ZIP archive. Trilogy Hub resources are plain folders, so it always returnsResource Archived false.isChecks whether a resource hasResource Protected protected="true"in<info>inmeta.xml(a resource other scripts should not stop).refreshScans theResources resources/folder for new and changed resources. In the current server version the function is not wired up yet and returnsfalsewith a warning.removeDeletes a file from the resource folder (works likeResource File fileDeleteon a path in the resource).renameRenames a stopped resource. In the current server version the function is not wired up yet and returnsResource falsewith a warning.restartStops and immediately starts a resource, e.g. after its files changed.Resource setWrites an attribute intoResource Info <info>in the resource'smeta.xml. In the current server version the function is not wired up yet and returnsfalsewith a warning.startStarts a stopped resource. It loads its scripts, maps and files, and players download it.Resource stopStops a running resource. Its elements, timers, commands and key binds go away.Resource updateGrants or revokes a right a resource asked for. It creates the ACL listResource ACLRequest resource.name, adds it to theResourcesgroup and sets the right in it. WithbyWhoit writes to the server log who did it.
Shared functions 2
callCalls a function exported by another resource (<export function="name"/>in itsmeta.xml) and returns its results.exports.resource:function(...)does the same. If the resource does not exist or is not running, a clear message appears in the console.getReturns the names of functions a resource exports inResource Exported Functions meta.xml(<export function="..."/>). In the current server version the list is empty.
Server events 6
onWhile the server runs, a new resource folder appeared (Resource Load State Change unloaded->loaded) or disappeared (loaded->unloaded).onA resource is about to start. You can hold the start.Resource Pre Start onA resource started. Attached toResource Start resourceRootit only arrives for your own resource, torootfor every resource.onA resource changed state:Resource State Change loaded->starting->running->stopping->loaded.onA resource is stopping. A good place to save data.Resource Stop onA resource setting changed (Setting Change setor the admin panel).
Client events 4
onA download fromClient File Download Complete downloadFilefinished (a<file download="false">file). It always arrives asynchronously, also when the file was already downloaded.onA resource started in the player's game (client scripts are loaded). Attached toClient Resource Start resourceRootit only arrives for your own resource.onA resource is stopping in the player's game.Client Resource Stop onFile download progress (a resource start orClient Transfer Box Progress Change downloadFile), at most about 10 times per second. Useful for your own download bar.