Javascript plugin

NewK

  • VC:MP Beta Tester
  • Posts: 113
Javascript plugin
«  »Last edited
VCMP bindings for javascript based on the already existing java plugin.

Download

There are no 32bit linux versions available because there's no V8 java bindings available for 32bit linux.

All javascript code runs on V8 v5.9.1. I'll look into possibly upgrading to a newer version in the future but right now this is not a priority. I've included a sample script that's set up with an IRC bot that connects to a LUnet channel and that echoes what people type ingame and what people type on IRC. This script uses SQLite for player registration and has the /login command the /register command and the /stats command. If you'd like to use MySQL instead of SQLite on this sample script, all you need to change is how you create the DB connection. Everything else is the exact same. The SQL module shares the same API for both SQLite and MySQL, function names are all the same. So if you ever need to migrate your server from SQLite to MySQL or MySQL to SQLite, all you'll need to change is how you create the connection. You can see an example on line 35 of the main.js file. If you use that connection instead of the one on line 32, you won't need to change anything else on the script, you just need to create your MySQL schema and create the same players table like the one on the SQLite db.

If you'd like to start fresh with an empty script, you can remove this script by deleting the "commands" folder inside the "src" folder, deleting the "sampleServer.db" SQLite database and deleting all the code inside "main.js". Just don't delete the node_modules folder because you'll need this to use the available modules.

Installation instructions
  • Download one of the three versions specified above
  • Download and Install JDK8
  • Edit javaplugin.properties file with the instructions specified there. After you edited that file make sure to delete the instructions
  • Download the VCMP server and place it on the root directory where the javaplugin.properties file is

A few notes
  • All javascript code must be inside the "src" folder
  • The entry script file must be named "main.js" and must be placed on the root of "src"
  • The load() function is equivalent to squirrel's dofile() function and can be used to load other .js files
  • require() is used to import modules you want to use, the available modules are inside the node_modules folder (the only reason I decided to keep this folder with the same name of the nodejs's node_modules folder was to help text editors (sublime, visual studio code, atom, etc...) give you better autocomplete suggestions when importing the modules
If you want to use javascript classes you need to enable javascript's "strict mode" on your classes with "use strict". For example:
Code: [Select]
"use strict"
class Rectangle {
    constructor(height, width) {
      this.height = height;
      this.width = width;
    }
  }
This is a limitation of version 5.9.1 of V8.

In the next following days I'll be creating documentation for the plugin. If you have any questions feel free to ask here. If you have problems create a new topic on the support board seeing as support is not allowed on this board.
Re: Javascript plugin
« Reply #1,  »Last edited
Documentation here. It's still not finished but it's a starting point.

EDIT: A server crashing bug was fixed on the java plugin that this plugin relies on. I've updated the 3 links above to include it. Make sure to either re-download it or just download the plugin from here and put it on your plugins folder