I really give this function alot of attention since you can do many unique things inside it. (onPlayerActionChange)
I have done 5 anti cheats within this function, but now I am publishing the most simple one.
Key_WIN <- BindKey(true, 0x5B, 0, 0); // Better add this at onScriptLoad();
Evaders <- [];
class PlayerStats {
Knocked = false;
AFK = false;
}
function onPlayerActionChange(player, old, new) {
if(new == 42 || new == 43){
// 42 = Knocked | 43 = Standing up
for(local i = 0; i < GetPlayers(); i++) {
local pl = FindPlayer(i);
if(pl && pl.Pos.Distance(player.Pos) < 27 && player.Team != plr.Team) {
// Shotgun range is 24meters I guess, so adding +3 meters is better if player flew away when knocked (abit)
return stats[player.ID].Knocked = true;
}
}
}
else if(new != 43 && new != 42){return stats[player.ID].Knocked=false;}
}
function onKeyDown(player, key) {
if(key == Key_WIN){
if(stats[player.ID].Knocked){
stats[ player.ID ].AFK = true; // 0 delay with Keys
Evaders.append(player.UID);
Message("[#FFF000]"+player.Name+" [#FF0000]has been banned for [#FFA540]Death evasion");
player.Kick();
}
}
function onPlayerPart(player, reason){
if((player.Away || stats[ player.ID ].AFK) && (stats[ player.ID ].Knocked)) {
Message("[#FFF000]"+player.Name+" [#FF0000]has been banned for [#FFA540]Death evasion");
Evaders.append(player.UID);
}
}
function onPlayerJoin(player){
foreach(val in Evaders) {
if(val == player.UID) player.Kick();
}
else return;
/*
OR YOU CAN TRY THIS
if(Evaders.find(player.UID) != null) player.Kick();
I guess this is better than 1st method
*/
}
The idea is that KeyBind is WAY faster than player.Away (built-in), so player.Away might take upto 3 seconds to detect an AFK state
Appreciate it 8)