1.1.4 • Published 4 years ago

rage-decorators v1.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

rage-decorators

A useful lightweight library which helps to registry server-side/client-side events, commands via decorators for RageMP API

Installation

Via npm: $ npm i --save rage-decorators

Via yarn: $ yarn add rage-decorators

Examples

Ninja.ts command example

import { command, commandable } from 'rage-decorators'

@commandable()
class Ninja {
  constructor(
    private isHide: boolean = false,
    private readonly ninjaName: string = "Zorro"
    ) {
      this.hide = this.hide.bind(this)
  }

  @command("hide")
  hide(player: PlayerMp, cmdDesc: string, ...args: any[]): void {
      if (args.length) {
          player.outputChatBox(cmdDesc)
      } else {
          this.isHide = !this.isHide
          player.outputChatBox(`Now ninja is ${this.isHide ? "hided" : "not hided"}`)
      }
  }
  
  @command(["ninjaname", "name", "n"])
  // also we can define custom description, for example
  // @command(["ninjaname", "name", "n"], { desc: "Only ninja see it, usage /{{cmdName}}" })
  // also we can provide  group of commands
  // our commands will be /ninja [ninjaname|name|n]
  // @command(["ninjaname", "name", "n"], "ninja")
  // another syntax
  // @command(["ninjaname", "name", "n"], { group: "ninja" })
  name(player: PlayerMp, cmdDesc: string, ...args: any[]: void) {
    if (args.length) {
      player.outputChatBox(cmdDesc)
    } else {
      player.outputChatBox(`Ninja name ${this.ninjaName}`)
    }
  }
}

export { Ninja }

NinjaEvents.ts event example

import { event, eventable } from 'rage-decorators'

@eventable()
class NinjaEvents {
  @event("playerJoin")
  ninjaJoin(player: PlayerMp) {
    mp.players.forEach(currentPlayer => currentPlayer.outputChatBox(`Ninja ${player.name} has just joined.`))
  }
}

API

commandable()

Resolve any commands which passed to classes commandable

command(commandName, params)

Decorator for adding commands to RAGE API Parameters

eventable()

Resolve any events which passed to classes with decorator eventable

event(eventName)

Parameters

  • eventName string | string[] - event(s) name, which will be added to mp.events.add
1.1.1

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago