Jump to content

Command&Event decorators [server-side/client-side] 1.1.4

   (1 review)

2 Screenshots

About This File

There is a server-side/client-side snippet which helps to registry any commands to Rage API with the simple interface by using decorators.

Install via npm/yarn:

$ npm i --save rage-decorators
// or
$ yarn add rage-decorators

Docs and examples: https://github.com/READYTOMASSACRE/rage-decorators#readme

Install (older version):


Скрытый текст

1. Install the reflect-metadata package.

$ npm i --save reflect-metadata
// or
$ yarn add reflect-metadata

2. Move the decorator.ts (or decorator.js, if you're using javascript instead typescript) file to your project folder


3. Import/require decorators in your file


Скрытый текст

import { commandable, command } from './decorators'

// first we should flag our class is resolvable by decorator commanadble (for registy any commands in class)
class Foo {

  // then we flag class method as a command
  // added command "/helloworld"
  print(player: PlayerMp) {
    player.outputChatBox("hello world!")


4. Make an instance class in other place in your project


Скрытый текст

// we should add reflect-metadata first before decorators
// because they are using Reflect API in runtime
import 'reflect-metadata'

import { Foo } from './Foo'

// all commands in class Foo are created
const foo = new Foo()


5. Make sure you import/require reflect-metadata before decorators in your entry script


If you're using typescript, make sure there two options (experimentalDecorators, emitDecoratorMetadata) are true in your tsconfig.json:

    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true

Interface command decorator

 * Decorator for adding commands to RAGE API
 * @param {string | string[]} cmd - command(s) name, which will be added to mp.events.addCommand
 * @param {string | { group?: string, desc?: string }} params - additional params, add to group or add to description
 * Supports templates in the desc param:
 *  @template cmdName - name of command
 *  @template groupName - name of group (if added in the additional params)
 * @example desc parameter template:
 * `Usage: /{{cmdName}} id`
 * `Usage: /{{groupName}} {{cmdName}} id`
 * decorator usage:
 * command("foo")
 * command(["bar", "baz"])
 * command("foo", "foogroup")
 * command("bar", { group: "foogroup", desc: "Custom description"})
export const command = (cmd: string | string[], params?: string | { group?: string, desc?: string }): MethodDecorator

Interface event decorator

 * Decorator for adding events into RAGE API
 * @param {string | string[]} eventName - event(s) name, which will be added to mp.events.add
 * @example
 * decorator usage:
 * event("playerJoin")
 * event(["playerDeath", "playerQuit"])
export const event = (eventName: string | string[]): MethodDecorator

Forum discussion:


What's New in Version 1.1.4   See changelog



1.1.4 update README.md, package.json

1.1.3 update package.json

1.1.1 Added comments, new version into package.json

1.1.0 Added support client-side

  • Like 1

User Feedback

Create an account or sign in to leave a review

You need to be a member in order to leave a review

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...