Skip to content

Commit

Permalink
feat: player fps getter
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Aug 29, 2022
1 parent b3812fa commit 9a32621
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/controllers/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { OnPlayerConnect, OnPlayerDisconnect } from "@/wrapper/callbacks";
import { IsPlayerNPC } from "@/wrapper/functions";
import {
GetPlayerDrunkLevel,
IsPlayerNPC,
SetPlayerDrunkLevel,
} from "@/wrapper/functions";

interface Settings {
locale: string;
Expand All @@ -10,14 +14,29 @@ export class BasePlayer {
public id: number;
public name: string = "";
public settings: Settings;
private lastDrunkLevel: number = 0;

constructor(id: number, settings: Settings) {
this.id = id;
this.settings = settings;
}

get isNpc() {
return IsPlayerNPC(this.id);
get isNpc(): boolean {
return Boolean(IsPlayerNPC(this.id));
}

get fps(): number {
const nowDrunkLevel = GetPlayerDrunkLevel(this.id);
if (nowDrunkLevel < 100) {
SetPlayerDrunkLevel(this.id, 2000);
} else {
if (this.lastDrunkLevel != nowDrunkLevel) {
const currFps = this.lastDrunkLevel - nowDrunkLevel;
this.lastDrunkLevel = nowDrunkLevel;
if (currFps > 0 && currFps < 256) return currFps - 1;
}
}
return 0;
}

get charset() {
Expand Down

0 comments on commit 9a32621

Please sign in to comment.