rage-decorators
v1.1.4
Published
A useful lightweight library which helps to registry server-side events, commands via decorators for RageMP API
Downloads
5
Readme
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.addCommandparams
(optional) object
eventable()
Resolve any events which passed to classes with decorator eventable
event(eventName)
Parameters