Skip to content

READYTOMASSACRE/rage-decorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • commandName string | string[] - The command(s) name, which will be added to mp.events.addCommand
  • params (optional) object
    • group (optional) string - A command group
    • desc (optional) string -A command description, supports templates: [{{cmdName}}, {{groupName}}]

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published