-
Notifications
You must be signed in to change notification settings - Fork 2
Context API GameMode RU
dev2alert edited this page Jan 31, 2022
·
3 revisions
Главная ▸ Context API ▸ Игровой режим
В контексте игрового режима доступны все функции обратного вызова SA-MP.
Пример:
// index.ts
import {GameMode} from "@sa-mp/core";
import {Mode} from "./mode.gctx";
GameMode.Factory.create(Mode);
Фабрика имеет один параметр и это список расширений, который передаётся вторым аргументом при создании.
Пример:
// 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;
}
}
Пример:
// 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]