-
Notifications
You must be signed in to change notification settings - Fork 2
Context API GameMode
dev2alert edited this page Feb 4, 2022
·
1 revision
Home ▸ Context API ▸ Game mode
In the context of the game mode, all SA-MP callback functions are available.
Example:
// index.ts
import {GameMode} from "@sa-mp/core";
import {Mode} from "./mode.gctx";
GameMode.Factory.create(Mode);
The factory has one parameter and this is a list of extensions, which is passed by the second argument when creating.
Example:
// mode.gctx.ts
import {GameMode, Player} from "@sa-mp/core";
import {Context, ImportService} from "@sa-mp/decorators";
import {ModeService} from "./mode.gsv";
@Context({
services: [ModeService]
})
export class Mode extends GameMode.Context {
@ImportService()
public readonly modeService: ModeService;
public onInit(): void {
console.log("[Mode] Init!");
console.log(`[Mode] 2 + 4 = ${this.modeService.plus(2, 4)};`);
}
public onExit(): void {
console.log("[Mode] Exit!");
}
public onPlayerConnect(player: Player): boolean {
player.send(`Hello, ${player}!`);
return true;
}
}
Example:
// mode.gsv.ts
import {GameMode} from "@sa-mp/core";
import {Service} from "@sa-mp/decorators";
@Service()
export class ModeService extends GameMode.Service {
public plus(a: number, b: number): number {
return a + b;
}
}
- Getting started [RU]
- Configuration [RU]
- Command line interface (CLI) [RU]
- Examples [RU]
- Player commands [RU]
- Keyboard [RU]
- Dialogs [RU]
- Groups [RU]
- Context API [RU]
- AMX API [RU]