Skip to content

Commit

Permalink
feat: added some game mode and player functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 9, 2022
1 parent f8b4439 commit dec5513
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
28 changes: 22 additions & 6 deletions src/controllers/gamemode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AddPlayerClassEx,
AllowAdminTeleport,
AllowInteriorWeapons,
CreateExplosion,
DisableInteriorEnterExits,
DisableNameTagLOS,
EnableStuntBonusForAll,
Expand All @@ -18,6 +19,7 @@ import {
LimitGlobalChatRadius,
LimitPlayerMarkerRadius,
SendRconCommand,
SetDeathDropAmount,
SetGameModeText,
SetGravity,
SetNameTagDrawDistance,
Expand Down Expand Up @@ -61,16 +63,14 @@ export abstract class BaseGameMode extends AbstractGM {
OnGameModeInit((): void => {
if (this.initialized)
return logger.error(
new Error("[BaseGameMode]: Cannot be initialized more than once")
"[BaseGameMode]: Cannot be initialized more than once"
);
this.initialized = true;
this.onInit();
});
OnGameModeExit((): void => {
if (!this.initialized)
return logger.error(
new Error("[BaseGameMode]: Cannot unload more than once")
);
return logger.error("[BaseGameMode]: Cannot unload more than once");
this.initialized = false;
this.onExit();
});
Expand Down Expand Up @@ -107,14 +107,14 @@ export abstract class BaseGameMode extends AbstractGM {
public static setNameTagDrawDistance = SetNameTagDrawDistance;
public static setWeather(weather: number): number {
if (weather < 0 || weather > 255) {
logger.warn("[BaseGameMode]: The valid weather value is only 0 to 255");
logger.error("[BaseGameMode]: The valid weather value is only 0 to 255");
return 0;
}
return SetWeather(weather);
}
public static setWorldTime(hour: number): number {
if (hour < 0 || hour > 23) {
logger.warn("[BaseGameMode]: The valid hour value is only 0 to 23");
logger.error("[BaseGameMode]: The valid hour value is only 0 to 23");
return 0;
}
return SetWorldTime(hour);
Expand All @@ -123,4 +123,20 @@ export abstract class BaseGameMode extends AbstractGM {
public static sendRconCommand = SendRconCommand;
public static addPlayerClass = AddPlayerClass;
public static addPlayerClassEx = AddPlayerClassEx;
public static createExplosion(
X: number,
Y: number,
Z: number,
type: number,
Radius: number
): number {
if (type < 0 || type > 13) {
logger.error(
"[BaseGameMode]: The valid explosion type value is only 0 to 13"
);
return 0;
}
return CreateExplosion(X, Y, Z, type, Radius);
}
public static setDeathDropAmount = SetDeathDropAmount;
}
26 changes: 25 additions & 1 deletion src/controllers/player/basePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ import {
PlayCrimeReportForPlayer,
InterpolateCameraPos,
InterpolateCameraLookAt,
CreateExplosionForPlayer,
GetMaxPlayers,
IsPlayerConnected,
} from "@/wrapper/functions";
import logger from "@/logger";
import { BaseGameMode } from "../gamemode";
Expand Down Expand Up @@ -147,8 +150,8 @@ export abstract class BasePlayer {
return this._isNpc;
}

// should be called at one second intervals
// first call will return 0;
// should be called at one second intervals, implemented internally by throttling
public getFps(): number {
const nowDrunkLevel = this.getDrunkLevel();
if (nowDrunkLevel < 100) {
Expand Down Expand Up @@ -505,6 +508,9 @@ export abstract class BasePlayer {
public static getPoolSize(): number {
return GetPlayerPoolSize();
}
public static getMaxPlayers(): number {
return GetMaxPlayers();
}
public playCrimeReport<P extends BasePlayer>(
suspect: P,
crimeId: number
Expand Down Expand Up @@ -559,4 +565,22 @@ export abstract class BasePlayer {
cut
);
}
public createExplosion(
X: number,
Y: number,
Z: number,
type: number,
Radius: number
): number {
if (type < 0 || type > 13) {
logger.error(
"[BasePlayer]: The valid explosion type value is only 0 to 13"
);
return 0;
}
return CreateExplosionForPlayer(this.id, X, Y, Z, type, Radius);
}
public static isConnected<P extends BasePlayer>(player: P) {
return IsPlayerConnected(player.id);
}
}
4 changes: 2 additions & 2 deletions src/wrapper/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,8 @@ export const InterpolateCameraLookAt = (
);
};

export const IsPlayerConnected = (playerid: number): number => {
return samp.callNative("IsPlayerConnected", "i", playerid);
export const IsPlayerConnected = (playerid: number): boolean => {
return Boolean(samp.callNative("IsPlayerConnected", "i", playerid));
};

export const IsPlayerInVehicle = (
Expand Down

0 comments on commit dec5513

Please sign in to comment.