Anticheat
Detect speed hacks, teleports and impossible movement in the gamemode.
Knight's core reports raw positions and does not judge them. Anticheat is gamemode policy built on player::update and player::enter_vehicle.
A speed and teleport check
knight
let MAX_SPEED = 60.0; // units per second
let TELEPORT_JUMP = 300.0; // single-sample jump
let lastX = {};
let lastY = {};
let lastZ = {};
let lastT = {};
let strikes = {};
player::update(int playerid, float x, float y, float z) {
let px = lastX[playerid];
if (px == null) {
lastX[playerid] = x; lastY[playerid] = y; lastZ[playerid] = z;
lastT[playerid] = GetTickCount();
return;
}
let dt = (GetTickCount() - lastT[playerid]) / 1000.0;
if (dt <= 0.0) { return; }
let dx = x - lastX[playerid];
let dy = y - lastY[playerid];
let dz = z - lastZ[playerid];
let dist = sqrt(dx * dx + dy * dy); // horizontal only
lastX[playerid] = x; lastY[playerid] = y; lastZ[playerid] = z;
lastT[playerid] = GetTickCount();
if (dz > 100.0) { return; } // jumping/falling
if (dist > TELEPORT_JUMP) {
strikes[playerid] = strikes[playerid] + 1;
if (strikes[playerid] >= 3) {
KickPlayer(playerid, "teleport detected");
}
return;
}
if (dist / dt > MAX_SPEED) {
SendClientMessage(playerid, "Slow down!");
}
};
Warning
Never kick on a single sample. Network jitter, respawns and vehicle exits produce legitimate jumps. Use a strike window and reset baselines on spawn and vehicle events.
Reset the baseline on respawn and vehicle changes
knight
function resetBaseline(int playerid) {
lastX[playerid] = null;
lastY[playerid] = null;
lastZ[playerid] = null;
lastT[playerid] = null;
}
player::spawn(int playerid) { resetBaseline(playerid); };
player::enter_vehicle(int playerid, int vehicleid, bool passenger) { resetBaseline(playerid); };
player::exit_vehicle(int playerid, int vehicleid) { resetBaseline(playerid); };
Other signals
player::weapon_shot— weapon id and hit coordinates, useful for damage validation.player::unoccupied_sync— raw vehicle health changes for vehicle damage exploits.player::aim— camera/aim data for silent-aim heuristics.GetPlayerPingandGetPlayerVersion— identify suspicious clients.