This is a simple framework for RAGE MP based on typescript and decorators.
npm i rager --save
Create a controller
import {MyService} from "./MyService";
import {MpController, MpCommand, CurrentPlayer, Player, MpEvent} from "rager";
@MpController()
export class Controller {
constructor(private service: MyService){}
@MpEvent('playerJoin')
startGame(@CurrentPlayer()player: Player){
player.health = 100;
}
@MpCommand('command1')
callCommand(@CurrentPlayer() player: Player){
this.service.editUserSession(player);
}
}
Create a service as needed, which will be injected into the controller (for this, you will have to set the dependency npm install typedi --save
import {Service} from "typedi";
import {Player} from 'rager'
@Service()
export class MyService {
editUserSession(player: Player){
player.clientSession.hello = Math.random();
}
}
Build
import {build} from 'rager'
import {Controller} from "./Controller";
build([Controller])
The function must be synchronous !!
export const MyDecoratorPlayer = createParamDecorator((player, args) => {
return player;
})