Sundays211 / VirtueRS3

MIT License
11 stars 13 forks source link

VirtueRS3

VirtueRS3 is a RS3 emulation framework originally developed for the 823 protocol, then progressively updated to 865. It aims to ease the development, testing, and integration of content by using the Java 8 Nashorn engine for content scripts, interacting with the engine via a series of APIs.

Running

To run the framework, place an 865 cache in the folder repostiory/cache_865/ then run ./gradlew run in the root folder (or gradlew.bat run in Windows). This will download Gradle and all the libraries needed to run the server (if you don't already have them) before starting.

Contributing

To contribute to the project, fork it to your own repository using the link at the top of the screen, commit your changes, then create a pull request to have it merged back into the main branch. Anyone is free to contribute, whether they're changing one line of one file or contributing an entire skill system.

Script System

All content scripts are located under scr/main/javascripts/. The CommonJS module structure is used to organise scripts into modules which declare dependencies on other modules using require(<relative path to module>).

NOTE: you must use the relative path to the module when requiring modules, which usually involves stepping up one or more levels first. For example, if your module was in the folder /skill/mining and you wanted to import the /core/var/bit module, you would need to use var varbit = require('../../core/var/bit');

Dynamically Reloading Modules

Scripts are built and loaded automatically when you start the server.

To avoid restarting the server every time you change a script, you can run ./gradlew watchScripts in a separate terminal window/tab to automatically rebuild the bundle any time a file.

You must also use the ::scripts command in-game (while logged into an Admin account) to cause the server to load the updated module.

Note: The ::reload <module> command has not yet been updated to work with the new build script. For now, you must use ::scripts to reload all modules instead.

Creating and Registering Modules

Each module must contain an index.js file which exports at least an init() function. When the module is loaded, the global-bootstrap.js file will call it's init() function with the scriptManager argument, which can be used to bind events as outlined in the next section.

To register a module, it's relative path from the root script directory must be declared in the getAllModules() function in global-bootstrap.js. This allows the module to be loaded both when the server is launched and when the ::reload <module> command is used (<module> is the name provided in the getAllModules() function).

Registering Events

Registering event requires the following line to be used within the init function: scriptManager.bind(eventType, binding, listener);, where:

Core Modules

There are a handful of core modules you can require in your module to perform useful functions. Doing so is preferable to interacting directly with the game engine. For a list of core modules, see the Core Modules wiki page

Terminology

VirtueRS3 generally uses the actual names for variables, where known. Some of the most common ones are listed below:

Changing player rights

One of the most common requests in any RSPS is granting an account administrative rights. There are two ways of doing this in VirtueRS3: the manual method, and the command method.

Manual method

This method is required for the first account you set as administrator (and to revoke admin rights).

  1. Create the account you wish to give admin rights to, using the account creation process in-game
  2. Shut down the server (if the server is running, changes will be overwritten).
  3. Open the character index file (located in /repository/character/index.xml).
  4. Look for the XML "account" element containing the "display" for your desired account
  5. Change the "type" element from 0 to 2 (2 being ADMINISTRATOR)
  6. Save the index and restart the server

Command method

This method should be used for all other accounts, beyond the first admin, since it's a lot easier to do.

  1. Log into the game with an Administrative account.
  2. Either type the command "playertype" into the developer console or type "::playertype" into the chatbox
  3. Type the display name of the account you wish to change the type of
  4. Select the desired account type