Resources: Difference between revisions

No edit summary
 
No edit summary
 
(13 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== What is a resource? ==
== What is a resource? ==
A resource is a folder that contains a file to identify information about the resource and the files associated with the resource, such as the script files. The meta file tells the server how to use the resource, such as what scripts the server runs and which scripts and files the client will have to download and run.  
Resources contain content for a server. This can include scripts, audio, images, game files, etc. You can reload, start, and stop resources, and you can have more than 1 resource running at the same time. Resources would usually contain a script for game modes or can also contain other tasks to help control/manage the server, add commands, provide separate content, etc.
A resources' content can be used in either a folder or zipped up in a [https://en.wikipedia.org/wiki/Tar_(computing) tar file].


You can reload, start, and stop resources, and you can have more than 1 resource running at the same time. Resources would usually contain a script for game modes or can also contain other tasks to help control/manage the server, add commands, provide separate content, etc.


Resources can be created with any of the supported languages: Lua, Squirrel, or JavaScript. These can be mixed in the same resource (although in different file types). You can have one file running Lua, another with JavaScript, and another with Squirrel, all working together in the same resource.
== Using resources ==
Place the resource in your server's "resources" folder. To make the resource automatically start when running the server, open the [[ServerConfiguration|server config]] (default is server.xml) in Notepad or your preferred code editor, and find the <code><resources></code> section. Add resources by inserting a new line containing the resource: <code><resource src="something" /></code>. This new line must be '''inside''' the resources section. Here's an example:
{{XMLCode|1=<resources>
<resource src="something"/>
<resource src="something-else" />
</resources>}}
 
You can also start, stop, restart and refresh resources without restarting the server. To do this, type one of the commands (start, stop, refresh, or restart) in the server console. Example: <code>start something</code>.  You can also use these commands in game, if your [[client.administrator|client.administrator]] is set to true (any running resource can set this).
 


== Creating a resource ==
== Creating a resource ==
To create a resource for the server you would simply create a new folder with the name of the resource.  
To create a resource for the server you would simply create a new folder with the name of the resource.  
Then to configure it you will need to create a file inside the resource folder named "meta.xml" (without the quotes) and open it in Notepad or your favorite code editor. We recommend [http://notepad-plus-plus.org/ Notepad++].
Then to configure it you will need to create a file inside the resource folder named "meta.xml" (without the quotes) and open it in Notepad or your favorite code editor. See the Meta File section below to learn how to use it.
 
Script files can be created with any of the supported languages: Lua, Squirrel, or JavaScript. These can be mixed in the same resource (although in different files). You can have one file running Lua, another with JavaScript, and another with Squirrel, all working together in the same resource.
 
 
== Example Directory Structure ==


Here is an example for the contents of the meta file:
Server.exe<br>
{{XMLCode|1=<meta>
Server.xml<br>
<info author="jack9267" type="script" version="1.0.0" description="Provides something awesome." />
resources/<br>
resources/resource1/<br>
resources/resource1/meta.xml<br>
resources/resource1/ResourceScript.js<br>
resources/resource2/<br>
resources/resource2/meta.xml<br>
resources/resource2/ResourceScript.js<br>
resources/resource2/ResourceScript.lua<br>
resources/resource2/ResourceScript.nut


<script src="server.lua" type="server" language="lua" />
</meta>}}


The info element would contain who made the script, the type of script and the version of the script.<br>
== Meta.xml File ==
You would have a script element for each script file you wish to load.<br>
This is used to provide some basic information and what scripts/files it provides.<br>
The type attribute refers to where the script will run, specify "server" for server code or "client" to have the script download and run on the client.<br>
'''All resources must have a meta.xml, or the resource won't load!'''
The language attribute tells the server which language to interpret the script. <br>GTA Connected supports Lua (language="lua"), JavaScript (language="javascript"), and Squirrel (language="squirrel")


== Resource Meta File ==
Example
Below is a list of all accepted meta.xml nodes.
{{XMLCode|1=<meta>
{{XMLCode|1=<meta>
<info author="" type="" version="" description="" />
<info author="" type="" version="" description="" />
Line 32: Line 49:
</meta>}}
</meta>}}


Some notes:
* All "src" attributes are a relative path to the file, with the resource's folder as the root. See the "Sandbox" section above for more info on that.
* The <code>info</code> node contains attributes that indicates who made the resource, it's type (custom description), custom version number, and a description of the resource<br>
* Every script file needs to have a <code><script></code> node, each with a "type" attribute that refers to what side the script will run on (server or client), a language attribute that tells the server/client which language the script file uses (see [[ScriptingLanguages|supported scripting languages]]), and a "src" attribute with the file name as a relative path (i.e. "example.js" or "foo/bar.js".
* Every custom file needs to have a <code><file></code> node, each with a "src" attribute for the file's path, and a "type" attribute indicating whether it's for the client or server.
* Any <code><dependency></code> node, with a "src" attribute with the other resource's name, will require the other resource to be loaded BEFORE this one.
== Client-side Files ==
Resources that contain client-side files are cached. If the built-in HTTP server is enabled, this will be used to distribute these files to clients when they connect or when the resource is updated and restarted. The default folder is "htdocs" in the GTAC server's main directory. You can also use your own HTTP server (like apache2 or nginx) as long as you add a virtual directory pointing to that "htdocs" folder in your GTAC server. Please note that this only applies to client-side files (used in ''<file>'' tag of the resource's meta.xml), not script files!


== Default resources ==
== Other Notes ==
You can check out the default resources for the server [https://github.com/jack9267/GTACResources/ here].
* The server will ignore any folders named with open and close square brackets, meaning they will not be loaded or cached as resources. This is useful if you want to group resources into subfolders for organization. Example name: [foobar]

Latest revision as of 06:01, 23 July 2025

What is a resource?

Resources contain content for a server. This can include scripts, audio, images, game files, etc. You can reload, start, and stop resources, and you can have more than 1 resource running at the same time. Resources would usually contain a script for game modes or can also contain other tasks to help control/manage the server, add commands, provide separate content, etc. A resources' content can be used in either a folder or zipped up in a tar file.


Using resources

Place the resource in your server's "resources" folder. To make the resource automatically start when running the server, open the server config (default is server.xml) in Notepad or your preferred code editor, and find the <resources> section. Add resources by inserting a new line containing the resource: <resource src="something" />. This new line must be inside the resources section. Here's an example:

<resources>
	<resource src="something"/>
	<resource src="something-else" />
</resources>

You can also start, stop, restart and refresh resources without restarting the server. To do this, type one of the commands (start, stop, refresh, or restart) in the server console. Example: start something. You can also use these commands in game, if your client.administrator is set to true (any running resource can set this).


Creating a resource

To create a resource for the server you would simply create a new folder with the name of the resource. Then to configure it you will need to create a file inside the resource folder named "meta.xml" (without the quotes) and open it in Notepad or your favorite code editor. See the Meta File section below to learn how to use it.

Script files can be created with any of the supported languages: Lua, Squirrel, or JavaScript. These can be mixed in the same resource (although in different files). You can have one file running Lua, another with JavaScript, and another with Squirrel, all working together in the same resource.


Example Directory Structure

Server.exe
Server.xml
resources/
resources/resource1/
resources/resource1/meta.xml
resources/resource1/ResourceScript.js
resources/resource2/
resources/resource2/meta.xml
resources/resource2/ResourceScript.js
resources/resource2/ResourceScript.lua
resources/resource2/ResourceScript.nut


Meta.xml File

This is used to provide some basic information and what scripts/files it provides.
All resources must have a meta.xml, or the resource won't load!

Example

<meta>
	<info author="" type="" version="" description="" />
	<script src="" type="" language="" />
	<dependency src="" />
	<map src="" type="" />
	<file url="" src="" type=""  />
</meta>

Some notes:

  • All "src" attributes are a relative path to the file, with the resource's folder as the root. See the "Sandbox" section above for more info on that.
  • The info node contains attributes that indicates who made the resource, it's type (custom description), custom version number, and a description of the resource
  • Every script file needs to have a <script> node, each with a "type" attribute that refers to what side the script will run on (server or client), a language attribute that tells the server/client which language the script file uses (see supported scripting languages), and a "src" attribute with the file name as a relative path (i.e. "example.js" or "foo/bar.js".
  • Every custom file needs to have a <file> node, each with a "src" attribute for the file's path, and a "type" attribute indicating whether it's for the client or server.
  • Any <dependency> node, with a "src" attribute with the other resource's name, will require the other resource to be loaded BEFORE this one.

Client-side Files

Resources that contain client-side files are cached. If the built-in HTTP server is enabled, this will be used to distribute these files to clients when they connect or when the resource is updated and restarted. The default folder is "htdocs" in the GTAC server's main directory. You can also use your own HTTP server (like apache2 or nginx) as long as you add a virtual directory pointing to that "htdocs" folder in your GTAC server. Please note that this only applies to client-side files (used in <file> tag of the resource's meta.xml), not script files!

Other Notes

  • The server will ignore any folders named with open and close square brackets, meaning they will not be loaded or cached as resources. This is useful if you want to group resources into subfolders for organization. Example name: [foobar]