afk system

This commit is contained in:
hydrant
2021-04-13 20:32:20 +02:00
parent b981819b52
commit 62ac08e98d
7 changed files with 76 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
export default function antiAfk(globalData: IGlobalData) {
let lastPosition: Vector3Mp = mp.players.local.position;
let afkCounter: number = 0;
let afkStatus: boolean = false;
setInterval(checkAfkPosition, 1000 * 10);
function checkAfkPosition() {
if (!globalData.LoggedIn) {
return;
}
let lp = lastPosition;
let np = mp.players.local.position;
let distance = mp.game.gameplay.getDistanceBetweenCoords(lp.x, lp.y, lp.z, np.x, np.y, np.z, false);
if (distance <= 5) {
if (!afkStatus) {
afkCounter++;
}
} else {
afkCounter = 0;
if (afkStatus) {
afkStatus = false;
globalData.IsAfk = afkStatus;
setServerAfkStatus(afkStatus);
}
}
if (afkCounter >= 12) {
afkStatus = true;
globalData.IsAfk = afkStatus;
setServerAfkStatus(afkStatus);
}
lastPosition = np;
}
function setServerAfkStatus(status: boolean) {
mp.events.callRemote("CLIENT:SetAfkStatus", status);
}
}

View File

@@ -4,6 +4,7 @@
InMenu: boolean,
InChat: boolean,
LoggedIn: boolean,
IsAfk: boolean,
}
declare type AccountData = {

View File

@@ -14,6 +14,7 @@ let globalData: IGlobalData = {
HideGui: false,
InChat: false,
LoggedIn: false,
IsAfk: false,
get InMenu(): boolean {
return inMenu;
@@ -258,6 +259,9 @@ animationSync();
import antiCheat from './admin/anticheat';
antiCheat(globalData);
import antiAfk from './Player/antiafk';
antiAfk(globalData);
require('./Gui/policedepartment');
require('./Gui/helptext');