Skip to content
/ node-mtasa Public

Node.js library for interaction with Lua scripts running on MTA:SA server, via the built-in HTTP interface

License

Notifications You must be signed in to change notification settings

4O4/node-mtasa

Repository files navigation

Build Status Coverage Status MIT license

MTA:SA SDK for Node.js

Lightweight module to simplify integration of external apps with MTA:SA servers. Uses the standard HTTP call interface, which you can learn more about here.

Installation

npm install mtasa --save

Usage

Import the Client class:

TypeScript:

import { Client } from "mtasa";

JavaScript:

const Client = require('mtasa').Client;

Then create a new client instance and use it to make some remote calls:

// Setup a new client for local server
const mta = new Client("127.0.0.1", 22005, "root", "pass");

// Perform calls using async/await:
(async () => {
    try {
        // Call some procedure
        const result = await mta.resources.test_resource.testProcedure("some param");

        // Call a procedure (the alternative verbose API)
        const verboseCallResult = await mta.call("test_resource", "testProcedure", "some param", 1234);
    } catch (err) {
        console.error(`Ooops! Something went wrong ${err}`);
    }
})()

// Without async/await, plain old Promises:
mta.resources.test_resource.testProcedure()
    .then((result) => {
        console.log(result);
    })
    .catch((err) => {
        console.error(`Ooops! Something went wrong ${err}`);
    });

For more information on how to expose your MTA server APIs (like the testProcedure function from test_resource resource) over the web interface, refer to Resource Web Access wiki page.

Documentation

The source code has inline documentation, which is also included in typings (.d.ts) shipped with the module. This means that no matter if you write plain old JavaScript or TypeScript - as long as you use some decent editor with intellisense (like Visual Studio Code), you should get nice autocompletion and feedback with documentation. Just give it a try yourself - use one of the examples above, type new Client( at the very end and hit CTRL + Shift + Space if the popup didn't appear automatically already.

VSCode demo

You can also jump straight into the source code of the library and unit tests.

Project status

This library is totally usable but is perhaps still lacking some features, hence the 0.1.x version. I consider it stable for my own needs. Feel free to report bugs or feature requests here. PRs welcome too.

License

MIT

About

Node.js library for interaction with Lua scripts running on MTA:SA server, via the built-in HTTP interface

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published