afk system
This commit is contained in:
45
ReallifeGamemode.Client/Player/antiafk.ts
Normal file
45
ReallifeGamemode.Client/Player/antiafk.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
1
ReallifeGamemode.Client/global.d.ts
vendored
1
ReallifeGamemode.Client/global.d.ts
vendored
@@ -4,6 +4,7 @@
|
||||
InMenu: boolean,
|
||||
InChat: boolean,
|
||||
LoggedIn: boolean,
|
||||
IsAfk: boolean,
|
||||
}
|
||||
|
||||
declare type AccountData = {
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user