23.01.2011, 18:06
(
Последний раз редактировалось Duxtray; 30.01.2011 в 14:24.
)
Hello! This is my first proper script.
Its an server-side anticheat (not ready at all)
Currently it has following features:
I would appreciate if you can test especially the airbreak detection.
UPDATES
29.1.2011 - Modified speedhack detection. Now detection is much more reliable due to completely different detection way
25.1.2011 - Added anti money hack
25.1.2011 - Added some commands for rcon admins (spectate, ban, kick)
24.1.2011 - Added anti speedhack and anti jetpack
INSTALLATION
(REQUIRES MAPANDREAS AND DINI)
1. Script below as filterscript
2. Save include script to pawno/include as antihax.inc
3. In your gamemode, put #include <antihax> AFTER #include <a_samp>
READ: I noticed that script bans player for airbreaking on grand larceny gamemode when player is at spawn looking at the city because player is airborne. To prevent things like this to happen, script now contains command SetAHXIgnoreForPlayer(playerid, state). Use it in your gamemode to prevent script scanning the player temporarily.
SetAHXIgnoreForPlayer(playerid, 1) = ignore player
SetAHXIgnoreForPlayer(playerid, 0) = do not ignore player
READ: Anti weapon cheat bans innocent players if AddPlayerClass with weapons is used without modifications.
To fix this, use SetAHXIgnoreForPlayer(playerid, 1) at first line of OnPlayerConnect callback.
Add SetAHXIgnoreForPlayer(playerid, 0) to OnPlayerSpawn callback AT LAST LINE.
OR just dont give any weapons with AddPlayerClass.
CALLBACKS AND FUNCTIONS
Callback AHXIsPlayerAdmin(playerid)
This gets called when AntiHax wants to know whether player should be treated as admin. Return true from this if player is admin, return false if not.
Function SetAHXIgnoreForPlayer(playerid, state)
Call this from your script if you want to disable all cheating checks for specific player temporarily.
For example use this to ignore player during spawning because otherwise AntiHax can ban player when he gets weapons from AddPlayerClass.
state 1 = disable checks
state 0 = enable checks again
antihax.pwn
antihax.inc
Its an server-side anticheat (not ready at all)
Currently it has following features:
- Nick name ban
- Server side weapons
- Anti money hack
- Basic anti health cheat
- Basic anti armour cheat
- Airbreak detection using MapAndreas height map
- Anti speedhack
- Anti jetpack
I would appreciate if you can test especially the airbreak detection.
UPDATES
29.1.2011 - Modified speedhack detection. Now detection is much more reliable due to completely different detection way
25.1.2011 - Added anti money hack
25.1.2011 - Added some commands for rcon admins (spectate, ban, kick)
24.1.2011 - Added anti speedhack and anti jetpack
INSTALLATION
(REQUIRES MAPANDREAS AND DINI)
1. Script below as filterscript
2. Save include script to pawno/include as antihax.inc
3. In your gamemode, put #include <antihax> AFTER #include <a_samp>
READ: I noticed that script bans player for airbreaking on grand larceny gamemode when player is at spawn looking at the city because player is airborne. To prevent things like this to happen, script now contains command SetAHXIgnoreForPlayer(playerid, state). Use it in your gamemode to prevent script scanning the player temporarily.
SetAHXIgnoreForPlayer(playerid, 1) = ignore player
SetAHXIgnoreForPlayer(playerid, 0) = do not ignore player
READ: Anti weapon cheat bans innocent players if AddPlayerClass with weapons is used without modifications.
To fix this, use SetAHXIgnoreForPlayer(playerid, 1) at first line of OnPlayerConnect callback.
Add SetAHXIgnoreForPlayer(playerid, 0) to OnPlayerSpawn callback AT LAST LINE.
OR just dont give any weapons with AddPlayerClass.
CALLBACKS AND FUNCTIONS
Callback AHXIsPlayerAdmin(playerid)
This gets called when AntiHax wants to know whether player should be treated as admin. Return true from this if player is admin, return false if not.
Function SetAHXIgnoreForPlayer(playerid, state)
Call this from your script if you want to disable all cheating checks for specific player temporarily.
For example use this to ignore player during spawning because otherwise AntiHax can ban player when he gets weapons from AddPlayerClass.
state 1 = disable checks
state 0 = enable checks again
antihax.pwn
pawn Код:
/**
/ AHX (AntiHax) Server-side anticheat for SA:MP - Early version
/ Copyright © 2011 Duxtray
/ YOU ARE ALLOWED TO USE THIS SCRIPT
/ YOU ARE NOT ALLOWED TO REMOVE OR CHANGE CREDITS OF THIS SCRIPT
/ YOU ARE NOT ALLOWED TO CHANGE SCRIPT'S NAME (ANTIHAX)
/ YOU ARE NOT ALLOWED TO TAKE ANY CHEAT DETECTION SYSTEM DIRECTLY FROM THIS SCRIPT AND CLAIM IT AS YOURS
**/
#include <a_samp>
#include <mapandreas>
#include <dini>
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#define AHX_FPM_STR "{FF0000}[AHX]: {00FF00}%s"
#define ahx_FPlayerMessage(%0,%1) new STRING[128]; \
format(STRING, 128, %1); \
ahx_PlayerMessage(%0, STRING)
#define ahx_FAddLogEntry(%0) new STRING[256]; \
format(STRING, 256, %0); \
ahx_AddLogEntry(STRING)
// PROTECTION SETTINGS
#define HEALTH true
// anti health hack
#define HEALTH_SCORE 3
// violation score from hack
//////////////////////////////
#define ARMOUR true
// anti armour hack
#define ARMOUR_SCORE 3
// violation score from hack
//////////////////////////////
#define JETPACK true
// dont allow jetpack usage
#define JETPACK_SCORE 3
// violation score from hack
//////////////////////////////
#define AIRBREAK true
// anti airbreak hack
#define AIRBREAK_SCORE 3
// violation score from hack
#define AIRBREAK_ITERS 3
// how many times hack has to be detected in row to result in action
#define AIRBREAK_TRESHOLD 5.0
// minimal difference in height between player and ground to activate airbreak check
//////////////////////////////
#define SPEEDHACK true
// speedhack detection
#define SPEEDHACK_SCORE 3
// violation score
#define SPEEDHACK_ITERS 3
// how many times hack has to be detected in row to result in action
#define SH_VEHICLE_SPEED_MAX 300.0
// maximum speed of vehicle before treating as speedhacker
#define SH_PLAYER_SPEED_MAX 50.0
// maximum speed of player on foot before treating as speedhacker
//////////////////////////////
#define MONEY true
// money hack detection
#define MONEY_SCORE 3
// violation score
//////////////////////////////
#define WEAPON true
// weapon hack detection
#define WEAPON_SCORE 3
// violation score
//////////////////////////////
// GENERAL SETTINGS
#define QUIET false
// dont show any reason in bans/kicks (increases effectivity? cheaters dont know which hack was detected)
#define DELAYED false
// delayed bans/kicks (increased effectivity?)
#define MIN_DELAY 30
// minimal delay in seconds
#define NICK_BAN true
// ban also nicknames
#define MAX_DELAY 45
// maximal delay in seconds
#define MAIN_TIMER 1
// time in seconds between main anticheat check
#define CLEAR_ITERS_TIMER 30
// time in seconds between clearing cheat verify iterations
#define ADMIN_IMMUNITY true
// whether rcon admins are immune for punishment
#define DEBUG false
// dont punish actually
// DONT TOUCH BELOW THIS LINE
#define C_RED (0xFF0000FF)
#define C_GREEN (0x00FF00FF)
#define C_BLUE (0x0000FFFF)
#define MESSAGE_PREFIX "[AHX]"
#define WARN_SCORE 1
#define KICK_SCORE 2
#define BAN_SCORE 3
#define NICK_BAN_FILE "ahx_nick_bans.txt"
#define LOG_FILE "ahx_log.txt"
enum Cheats
{
C_HEALTH = 0,
C_ARMOUR = 1,
C_JETPACK = 2,
C_AIRBREAK = 3,
C_SPEEDHACK = 4,
C_MONEY = 5,
C_WEAPON = 6
}
#define CHEAT_COUNT 7
enum sPos
{
Float:px,
Float:py,
Float:pz
}
// Global variables and declarations
new ahx_playerWarningScore[MAX_PLAYERS];
new ahx_skipPlayer[MAX_PLAYERS];
new ahx_playerAirbreakMode[MAX_PLAYERS];
new ahx_playerIP[MAX_PLAYERS][40];
new ahx_playerMoney[MAX_PLAYERS];
new ahx_ignoreCheatTime[MAX_PLAYERS][Cheats];
new ahx_cheatVerifyIters[MAX_PLAYERS][Cheats];
new ahx_playerWeapons[MAX_PLAYERS][47];
new ahx_playerOldPosition[MAX_PLAYERS][sPos];
forward ahx_MainTimer();
forward ahx_ClearItersTimer();
forward ahx_AirBreakTimer(playerid, opZ);
forward ahx_AirBreakNoclipTimer(playerid, opX, opY, opZ);
forward Float:ahx_GetHighestZFor2DCoord(Float:x, Float:y);
forward Float:ahx_GetLowestZFor2DCoord(Float:x, Float:y);
forward ahx_DelayedAction(playerid, playername[], reason[]);
forward Float:ahx_Distance2D(Float:x1, Float:y1, Float:x2, Float:y2, bool:sqrt = true);
forward Float:ahx_GetPlayerSpeed(playerid, bool:Z = true);
forward Float:ahx_GetSpeedBasedOn2DCoords(Float:oX, Float:oY, Float:nX, Float:nY, Float:time);
/* SA:MP CALLBACKS */
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" AntiHax - Anticheat by Duxtray loaded");
print("--------------------------------------\n");
ahx_AddLogEntry("AntiHax loaded");
MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
SetTimer("ahx_MainTimer",MAIN_TIMER * 1000,true);
SetTimer("ahx_ClearItersTimer",CLEAR_ITERS_TIMER * 1000,true);
if (!dini_Exists(NICK_BAN_FILE))
{
dini_Create(NICK_BAN_FILE);
}
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
new ip[40];
GetPlayerIp(playerid, ip, 16);
ahx_playerIP[playerid] = ip;
ahx_playerMoney[playerid] = 0;
if (NICK_BAN)
{
if (dini_Int(NICK_BAN_FILE, ahx_PlayerName(playerid)) == 1)
{
ahx_FAddLogEntry("Player %s banned for ban evading", ahx_PlayerName(playerid));
ahx_BanPlayerIpEx(playerid, "Ban evading");
}
}
for (new i = 0; i < 47; i++)
{
ahx_playerWeapons[playerid][i] = -1;
}
ahx_PlayerMessage(playerid, "This server is protected by AntiHax");
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
ahx_playerMoney[playerid] = 0;
if (reason == 2) { ahx_playerIP[playerid][0] = 0; return 1; /* own kick/ban */ }
if (ahx_playerWarningScore[playerid] >= BAN_SCORE)
{
ahx_FAddLogEntry("Player %s was in ban queue and disconnected, so IP was banned", ahx_PlayerName(playerid));
new message[100];
format(message, sizeof(message), "%s: Banned (-)", ahx_PlayerName(playerid));
ahx_PlayerMessageToEveryone(message);
print(message);
new bancmd[100];
format(bancmd, sizeof(bancmd), "banip %s", ahx_playerIP[playerid]);
SendRconCommand(bancmd);
ahx_playerWarningScore[playerid] = 0;
}
ahx_playerIP[playerid][0] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (!IsPlayerAdmin(playerid) && !ahx_IsPlayerAdmin(playerid)) return 1;
dcmd(ahxcmds, 7, cmdtext);
dcmd(ahxspectate, 11, cmdtext);
dcmd(ahxstopspectate, 15, cmdtext);
dcmd(ahxban, 6, cmdtext);
dcmd(ahxkick, 7, cmdtext);
dcmd(ahxunbannick, 12, cmdtext);
return 1;
}
// DCMDS
dcmd_ahxcmds(playerid, params[])
{
#pragma unused params
ahx_PlayerMessage(playerid, "Admin commands");
ahx_PlayerMessage(playerid, "----------------------");
ahx_PlayerMessage(playerid, "/ahxcmds Show this");
ahx_PlayerMessage(playerid, "/ahxspectate [ID] Spectate player");
ahx_PlayerMessage(playerid, "/ahxstopspectate Stop spectating current player");
ahx_PlayerMessage(playerid, "/ahxban [ID] Ban player");
ahx_PlayerMessage(playerid, "/ahxkick [ID] Kick player");
ahx_PlayerMessage(playerid, "/ahxunbannick [nick] Unban player nickname");
}
dcmd_ahxspectate(playerid, params[])
{
new id;
if (strlen(params))
{
id = strval(params);
if (!IsPlayerConnected(id)) { ahx_PlayerMessage(playerid, "No such player"); return; }
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, id);
ahx_PlayerMessage(playerid, "You are now spectating player");
} else { ahx_PlayerMessage(playerid, "Usage: /ahxspectate [ID]"); }
}
dcmd_ahxstopspectate(playerid, params[])
{
#pragma unused params
TogglePlayerSpectating(playerid, 0);
ahx_PlayerMessage(playerid, "You are no longer spectating player");
}
dcmd_ahxban(playerid, params[])
{
new id;
if (strlen(params))
{
id = strval(params);
if (!IsPlayerConnected(id)) { ahx_PlayerMessage(playerid, "No such player"); return; }
new message[100];
format(message, sizeof(message), "%s: Banned (Admin)", ahx_PlayerName(id));
ahx_PlayerMessageToEveryone(message);
if (NICK_BAN)
{
dini_IntSet(NICK_BAN_FILE, ahx_PlayerName(id), 1);
}
ahx_FAddLogEntry("Admin %s has banned player %s", ahx_PlayerName(playerid), ahx_PlayerName(id));
Ban(id);
ahx_PlayerMessage(playerid, "Player has been banned");
} else { ahx_PlayerMessage(playerid, "Usage: /ahxban [ID]"); }
}
dcmd_ahxkick(playerid, params[])
{
new id;
if (strlen(params))
{
id = strval(params);
if (!IsPlayerConnected(id)) { ahx_PlayerMessage(playerid, "No such player"); return; }
new message[100];
format(message, sizeof(message), "%s: Kicked (Admin)", ahx_PlayerName(id));
ahx_PlayerMessageToEveryone(message);
ahx_FAddLogEntry("Admin %s has kicked player %s", ahx_PlayerName(playerid), ahx_PlayerName(id));
Kick(id);
ahx_PlayerMessage(playerid, "Player has been kicked");
} else { ahx_PlayerMessage(playerid, "Usage: /ahxkick [ID]"); }
}
dcmd_ahxunbannick(playerid, params[])
{
if (strlen(params))
{
if (dini_Int(NICK_BAN_FILE, params) != 1)
{
ahx_PlayerMessage(playerid, "Specified nickname is not banned");
return;
}
dini_IntSet(NICK_BAN_FILE, params, 0);
ahx_PlayerMessage(playerid, "Nickname has been unbanned");
ahx_FAddLogEntry("Admin %s has unbanned nickname %s", ahx_PlayerName(playerid), params);
} else { ahx_PlayerMessage(playerid, "Usage: /ahxunbannick [nick]"); }
}
// AHX Overrides for native functions
forward ahx_Override_ResetPlayerMoney(playerid);
forward ahx_Override_GivePlayerMoney(playerid, amount);
forward ahx_Override_GetPlayerMoney(playerid);
forward ahx_Calls_SetAHXIgnoreForPlayer(playerid, status);
forward ahx_Override_GivePlayerWeapon(playerid, weaponid, ammo);
forward ahx_Override_ResetPlayerWeapons(playerid);
forward ahx_Override_SetPlayerAmmo(playerid, weaponid, ammo);
forward ahx_SyncPlayerWepsToServer(playerid);
public ahx_Override_ResetPlayerMoney(playerid)
{
if (IsPlayerConnected(playerid))
{
ahx_playerMoney[playerid] = 0;
ResetPlayerMoney(playerid);
ahx_ignoreCheatTime[playerid][C_MONEY] = tickcount();
return 1;
}
return 0;
}
public ahx_Override_GivePlayerMoney(playerid, amount)
{
if (IsPlayerConnected(playerid))
{
ahx_playerMoney[playerid] += amount;
GivePlayerMoney(playerid, amount);
ahx_ignoreCheatTime[playerid][C_MONEY] = tickcount();
return 1;
}
return 0;
}
public ahx_Calls_SetAHXIgnoreForPlayer(playerid, status)
{
if (IsPlayerConnected(playerid))
{
if (status == 1)
{
ahx_skipPlayer[playerid] = true;
return 1;
}
if (status == 0)
{
ahx_playerMoney[playerid] = GetPlayerMoney(playerid);
SetTimerEx("ahx_SyncPlayerWepsToServer", 2000, false, "i", playerid);
return 1;
}
return 0;
}
return 0;
}
/* ahx_SyncPlayerWepsToServer: Trust (??!?) the player and update server side weps list according to players weps */
public ahx_SyncPlayerWepsToServer(playerid)
{
for (new i = 0; i < 47; i++)
{
ahx_playerWeapons[playerid][i] = -1;
}
for (new x = 0; x < 13; x++)
{
new id, wammo;
GetPlayerWeaponData(playerid, x, id, wammo);
if (id != 0){
ahx_playerWeapons[playerid][id] = wammo;
}
}
ahx_skipPlayer[playerid] = false;
}
public ahx_Override_GetPlayerMoney(playerid)
{
return ahx_playerMoney[playerid];
}
public ahx_Override_GivePlayerWeapon(playerid, weaponid, ammo)
{
ahx_ignoreCheatTime[playerid][C_WEAPON] = tickcount();
GivePlayerWeapon(playerid, weaponid, ammo);
ahx_playerWeapons[playerid][weaponid] = ammo;
return;
}
public ahx_Override_ResetPlayerWeapons(playerid)
{
ResetPlayerWeapons(playerid);
ahx_ignoreCheatTime[playerid][C_WEAPON] = tickcount();
for (new i = 0; i < 47; i++)
{
ahx_playerWeapons[playerid][i] = -1;
}
return;
}
public ahx_Override_SetPlayerAmmo(playerid, weaponid, ammo)
{
ahx_ignoreCheatTime[playerid][C_WEAPON] = tickcount();
SetPlayerAmmo(playerid, weaponid, ammo);
ahx_playerWeapons[playerid][weaponid] = ammo;
return;
}
// AHX functions
public ahx_MainTimer()
{
for (new i = 0 ; i < MAX_PLAYERS ; i++)
{
if (!IsPlayerConnected(i)) continue;
if (ahx_skipPlayer[i]) continue;
if ((IsPlayerAdmin(i) || ahx_IsPlayerAdmin(i)) && ADMIN_IMMUNITY) continue;
new Float:npX, Float:npY, Float:npZ;
GetPlayerPos(i, npX, npY, npZ);
// HEALTH
if (HEALTH)
{
new Float:health;
GetPlayerHealth(i, health);
if (health > 100.0) { ahx_TakeAction(i, "Health hack", HEALTH_SCORE); }
}
// ARMOR
if (ARMOUR)
{
new Float:armour;
GetPlayerArmour(i, armour);
if (armour > 100.0) { ahx_TakeAction(i, "Armour hack", ARMOUR_SCORE); }
}
// JETPACK
if (JETPACK)
{
if(GetPlayerSpecialAction(i) == SPECIAL_ACTION_USEJETPACK)
{
ahx_TakeAction(i, "Jetpack", JETPACK_SCORE);
}
}
// AIRBREAK
if (AIRBREAK)
{
new Float:playerX, Float:playerY, Float:playerZ, Float:groundZ, Float:lgroundZ, Float:zDiff, Float:vX, Float:vY, Float:vZ;
GetPlayerPos(i, playerX, playerY, playerZ);
GetPlayerVelocity(i, vX, vY, vZ);
groundZ = ahx_GetHighestZFor2DCoord(playerX, playerY);
lgroundZ = ahx_GetLowestZFor2DCoord(playerX, playerY);
zDiff = playerZ-groundZ;
if (lgroundZ > 0.0 && playerZ < 0.0)
{
ahx_TakeAction(i,"Airbreak",AIRBREAK_SCORE);
}
if (zDiff > AIRBREAK_TRESHOLD)
{
if (GetPlayerState(i) != PLAYER_STATE_WASTED)
{ // dont proceed if dying
if (GetPlayerInterior(i) == 0)
{ // only proceed when at main world
if (IsPlayerInAnyVehicle(i))
{
ahx_playerAirbreakMode[i] = 1;
if (!ahx_IsVehicleAirVehicle(GetVehicleModel(GetPlayerVehicleID(i)))) {
// wont proceed if inside air vehicle
if (GetPlayerState(i) == PLAYER_STATE_DRIVER)
{ // dont ban passengers (innocent?)
ahx_AirBreakCheck(i);
}
}
} else {
// on foot and flying?
if(GetPlayerSpecialAction(i) != SPECIAL_ACTION_USEJETPACK)
{
ahx_playerAirbreakMode[i] = 0;
ahx_AirBreakCheck(i);
}
}
}
}
}
}
// SPEEDHACK
if (SPEEDHACK)
{
new Float:vPlayer, Float:vPlayer2;
vPlayer = ahx_GetPlayerSpeed(i, false);
vPlayer2 = ahx_GetSpeedBasedOn2DCoords(ahx_playerOldPosition[i][px], ahx_playerOldPosition[i][py], npX, npY, MAIN_TIMER);
if (IsPlayerInAnyVehicle(i))
{
if (vPlayer > SH_VEHICLE_SPEED_MAX || vPlayer2 > SH_VEHICLE_SPEED_MAX)
{
ahx_cheatVerifyIters[i][C_SPEEDHACK]++;
if (ahx_cheatVerifyIters[i][C_SPEEDHACK] >= SPEEDHACK_ITERS)
{
ahx_TakeAction(i, "Speedhack", SPEEDHACK_SCORE);
}
}
} else
{
if (vPlayer > SH_PLAYER_SPEED_MAX || vPlayer2 > SH_PLAYER_SPEED_MAX)
{
ahx_cheatVerifyIters[i][C_SPEEDHACK]++;
if (ahx_cheatVerifyIters[i][C_SPEEDHACK] >= SPEEDHACK_ITERS)
{
ahx_TakeAction(i, "Speedhack", SPEEDHACK_SCORE);
}
}
}
}
// MONEY HACK
if (MONEY)
{
if (ahx_HasTimePassed(ahx_ignoreCheatTime[i][C_MONEY], 1000))
{
if (ahx_playerMoney[i] < GetPlayerMoney(i))
{
new msg[100];
format(msg, sizeof(msg), "Money hack (Money: %i$, expected %i$)", GetPlayerMoney(i), ahx_playerMoney[i]);
ahx_TakeAction(i, msg, MONEY_SCORE);
ResetPlayerMoney(i);
GivePlayerMoney(i, ahx_playerMoney[i]);
}
if (ahx_playerMoney[i] > GetPlayerMoney(i))
{
ahx_playerMoney[i] = GetPlayerMoney(i);
}
}
}
// WEAPON HACK
if (WEAPON)
{
if (ahx_HasTimePassed(ahx_ignoreCheatTime[i][C_WEAPON],500)) {
for (new x = 0; x < 13; x++)
{
new id, wammo, cheating;
cheating = false;
GetPlayerWeaponData(i, x, id, wammo);
if (ahx_playerWeapons[i][id] == -1 && wammo != 0)
{
if (x != 0)
{
cheating = true;
ahx_TakeAction(i, "Weapon cheat", WEAPON_SCORE);
ResetPlayerWeapons(i);
for (new q = 0 ; q < 47; q++)
{
ahx_playerWeapons[i][q] = -1;
}
}
}
if (wammo > ahx_playerWeapons[i][id] && ahx_playerWeapons[i][id] >= 0 && wammo != 0 )
{
cheating = true;
ahx_TakeAction(i, "Weapon ammo cheat", WEAPON_SCORE);
ResetPlayerWeapons(i);
for (new q = 0 ; q < 47; q++)
{
ahx_playerWeapons[i][q] = -1;
}
}
if (!cheating)
{
ahx_playerWeapons[i][id] = wammo;
}
}
}
}
ahx_playerOldPosition[i][px] = npX;
ahx_playerOldPosition[i][py] = npY;
ahx_playerOldPosition[i][pz] = npZ;
}
}
public ahx_ClearItersTimer()
{
for (new i = 0 ; i < MAX_PLAYERS ; i++)
{
for (new x = 0 ; x < CHEAT_COUNT ; x++)
{
ahx_cheatVerifyIters[i][x] = 0;
}
}
}
/* ahx_AirBreakCheck: Airbreak protection*/
stock ahx_AirBreakCheck(playerid)
{
if (ahx_playerAirbreakMode[playerid] == 0)
{
new Float:vX, Float:vY, Float: vZ, Float:pX, Float:pY, Float:pZ;
GetPlayerVelocity(playerid, vX, vY, vZ);
GetPlayerPos(playerid, pX, pY, pZ);
SetTimerEx("ahx_AirBreakTimer",500,false,"if",playerid,pZ);
} else {
new Float:vX, Float:vY, Float: vZ, Float:pX, Float:pY, Float:pZ;
GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
GetVehiclePos(GetPlayerVehicleID(playerid), pX, pY, pZ);
SetTimerEx("ahx_AirBreakTimer",500,false,"if",playerid,pZ);
}
}
/* ahx_AirBreakTimer: Timer callback for airbrake protection */
public ahx_AirBreakTimer(playerid, opZ)
{
if (ahx_playerAirbreakMode[playerid] == 0)
{
new Float:vX, Float:vY, Float: vZ, Float:pX, Float:pY, Float:pZ;
GetPlayerVelocity(playerid, vX, vY, vZ);
GetPlayerPos(playerid, pX, pY, pZ);
if (vZ >= 0)
{
ahx_cheatVerifyIters[playerid][C_AIRBREAK]++;
if (ahx_cheatVerifyIters[playerid][C_AIRBREAK] >= AIRBREAK_ITERS)
{
ahx_TakeAction(playerid, "Airbreak", AIRBREAK_SCORE);
}
}
} else{
new Float:vX, Float:vY, Float: vZ, Float:pX, Float:pY, Float:pZ;
GetVehicleVelocity(GetPlayerVehicleID(playerid), vX, vY, vZ);
GetVehiclePos(GetPlayerVehicleID(playerid), pX, pY, pZ);
if (vZ >= 0)
{
ahx_cheatVerifyIters[playerid][C_AIRBREAK]++;
if (ahx_cheatVerifyIters[playerid][C_AIRBREAK] >= AIRBREAK_ITERS)
{
ahx_TakeAction(playerid, "Airbreak", AIRBREAK_SCORE);
}
}
}
}
/* ahx_IsVehicleAirVehicle: Is vehicle helicopter or airplane */
stock ahx_IsVehicleAirVehicle(vehid)
{
switch(vehid)
{
case 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 498, 563, 447, 469: return true;
}
return false;
}
/* ahx_TakeAction: Kicks/bans/warns player */
stock ahx_TakeAction(playerid, reason[], score)
{
if (IsPlayerConnected(playerid))
{
if (DEBUG)
{
ahx_FAddLogEntry("[DEBUG] Taken action against player %s, reason: %s, score: %i", ahx_PlayerName(playerid), reason, score);
new message[128];
format(message, sizeof(message), "Debug: Taken action against you (%s), score given: %i", reason, score);
ahx_PlayerMessage(playerid, message);
return;
}
ahx_playerWarningScore[playerid] += score;
if (QUIET)
{
reason[0] = '-';
reason[1] = 0;
}
if (DELAYED && ahx_playerWarningScore[playerid] > WARN_SCORE)
{
new rand = MIN_DELAY+random(MAX_DELAY-MIN_DELAY);
SetTimerEx("ahx_DelayedAction", rand*1000, false, "iss",playerid, ahx_PlayerName(playerid), reason);
ahx_skipPlayer[playerid] = true;
return;
}
if (ahx_playerWarningScore[playerid] >= BAN_SCORE)
{
new message[100];
format(message, sizeof(message), "You have been banned (%s)", reason);
ahx_PlayerMessage(playerid, message);
new gmessage[100];
format(gmessage, sizeof(gmessage), "%s (%i): Banned (%s)", ahx_PlayerName(playerid), playerid, reason);
ahx_PlayerMessageToEveryone(gmessage);
if (NICK_BAN)
{
dini_IntSet(NICK_BAN_FILE, ahx_PlayerName(playerid), 1);
}
ahx_FAddLogEntry("Banned player %s, reason: %s, score: %i", ahx_PlayerName(playerid), reason, score);
Ban(playerid);
ahx_playerWarningScore[playerid] = 0;
return;
}
if (ahx_playerWarningScore[playerid] >= KICK_SCORE)
{
new message[100];
format(message, sizeof(message), "You have been kicked (%s)", reason);
ahx_PlayerMessage(playerid, message);
new gmessage[100];
format(gmessage, sizeof(gmessage), "%s (%i): Kicked (%s)", ahx_PlayerName(playerid), playerid, reason);
ahx_PlayerMessageToEveryone(gmessage);
ahx_FAddLogEntry("Kicked player %s, reason: %s, score: %i", ahx_PlayerName(playerid), reason, score);
Kick(playerid);
return;
}
if (ahx_playerWarningScore[playerid] >= WARN_SCORE)
{
new message[100];
format(message, sizeof(message), "Warning! Do not violate rules (%s)", reason);
ahx_PlayerMessage(playerid, message);
ahx_FAddLogEntry("Warned player %s, reason: %s, score: %i", ahx_PlayerName(playerid), reason, score);
return;
}
}
}
public ahx_DelayedAction(playerid, playername[], reason[])
{
if (strcmp(playername, ahx_PlayerName(playerid)) != 0)
{ // cheater disconnected before this ?! lets not ban innocent people
return;
}
if (ahx_playerWarningScore[playerid] >= BAN_SCORE)
{
new message[100];
format(message, sizeof(message), "You have been banned (%s)", reason);
ahx_PlayerMessage(playerid, message);
new gmessage[100];
format(gmessage, sizeof(gmessage), "%s (%i): Banned (%s)", ahx_PlayerName(playerid), playerid, reason);
ahx_PlayerMessageToEveryone(gmessage);
if (NICK_BAN)
{
dini_IntSet(NICK_BAN_FILE, ahx_PlayerName(playerid), 1);
}
ahx_FAddLogEntry("[DELAYED] Banned player %s, reason: %s", ahx_PlayerName(playerid), reason);
Ban(playerid);
ahx_playerWarningScore[playerid] = 0;
return;
}
if (ahx_playerWarningScore[playerid] >= KICK_SCORE)
{
new message[100];
format(message, sizeof(message), "You have been kicked (%s)", reason);
ahx_PlayerMessage(playerid, message);
new gmessage[100];
format(gmessage, sizeof(gmessage), "%s (%i): Kicked (%s)", ahx_PlayerName(playerid), playerid, reason);
ahx_PlayerMessageToEveryone(gmessage);
ahx_FAddLogEntry("[DELAYED] Kicked player %s, reason: %s", ahx_PlayerName(playerid), reason);
Kick(playerid);
return;
}
if (ahx_playerWarningScore[playerid] >= WARN_SCORE)
{
new message[100];
format(message, sizeof(message), "Warning! Do not violate rules (%s)", reason);
ahx_FAddLogEntry("[DELAYED] Warned player %s, reason: %s", ahx_PlayerName(playerid), reason);
ahx_PlayerMessage(playerid, message);
return;
}
}
/* ahx_PlayerMessage: Send message to player */
stock ahx_PlayerMessage(playerid, message[])
{
if (IsPlayerConnected(playerid))
{
new msg[100];
format(msg, sizeof(msg), "{FF0000}%s: {00FF00}%s", MESSAGE_PREFIX, message);
SendClientMessage(playerid, C_GREEN, msg);
}
}
/* ahx_PlayerMessageToEveryone: Send message to all players */
stock ahx_PlayerMessageToEveryone(message[])
{
new msg[100];
format(msg, sizeof(msg), "{FF0000}%s: {00FF00}%s", MESSAGE_PREFIX, message);
SendClientMessageToAll(C_GREEN, msg);
}
/* ahx_BubbleSort: Sort array with bubble sort algorithm*/
stock ahx_BubbleSort(Float:array[], length)
{
new i,j;
for(i=0 ; i<length ; i++)
{
for(j=0 ; j<i ; j++)
{
if(array[i]>array[j])
{
new Float:temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
}
/* ahx_PlayerName: Get player name easily */
stock ahx_PlayerName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
/* ahx_GetHighestZFor2DCoord: Get Z coordinate for ground at specified point with MapAndreas but detect whether coordinate for ex. edge of roof */
stock Float:ahx_GetHighestZFor2DCoord(Float:x, Float:y)
{
new Float:coords[5], Float:temp;
MapAndreas_FindZ_For2DCoord(x,y,temp);
coords[0] = temp;
MapAndreas_FindZ_For2DCoord(x+3,y,temp);
coords[1] = temp;
MapAndreas_FindZ_For2DCoord(x,y+3,temp);
coords[2] = temp;
MapAndreas_FindZ_For2DCoord(x-3,y,temp);
coords[3] = temp;
MapAndreas_FindZ_For2DCoord(x,y-3,temp);
coords[4] = temp;
ahx_BubbleSort(coords,5);
new Float:result = coords[0];
return result;
}
/* ahx_GetLowestZFor2DCoord: Get Z coordinate for ground at specified point with MapAndreas but detect whether coordinate for ex. edge of roof */
stock Float:ahx_GetLowestZFor2DCoord(Float:x, Float:y)
{
new Float:coords[5], Float:temp;
MapAndreas_FindZ_For2DCoord(x,y,temp);
coords[0] = temp;
MapAndreas_FindZ_For2DCoord(x+3,y,temp);
coords[1] = temp;
MapAndreas_FindZ_For2DCoord(x,y+3,temp);
coords[2] = temp;
MapAndreas_FindZ_For2DCoord(x-3,y,temp);
coords[3] = temp;
MapAndreas_FindZ_For2DCoord(x,y-3,temp);
coords[4] = temp;
ahx_BubbleSort(coords,5);
new Float:result = coords[4];
return result;
}
/* ahx_Distance2D: Get distance between two 2D coordinates*/
stock Float:ahx_Distance2D(Float:x1, Float:y1, Float:x2, Float:y2, bool:sqrt = true)
{
x1 -= x2;
x1 *= x1;
y1 -= y2;
y1 *= y1;
x1 += y1;
return sqrt ? floatsqroot(x1) : x1;
}
/* ahx_GetPlayerSpeed: Get player speed in km/h */
stock Float:ahx_GetPlayerSpeed(playerid, bool:Z = true)
{
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
new Float:Speed;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), SpeedX, SpeedY, SpeedZ);
else GetPlayerVelocity(playerid, SpeedX, SpeedY, SpeedZ);
if(Z) Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatadd(floatpower(SpeedY, 2.0), floatpower(SpeedZ, 2.0))));
else Speed = floatsqroot(floatadd(floatpower(SpeedX, 2.0), floatpower(SpeedY, 2.0)));
Speed = floatround(Speed * 100 * 1.61);
return Speed;
}
/* ahx_GetSpeedBasedOn2DCoords: Calculates speed of object using two 2D coordinates and time passed between them */
stock Float:ahx_GetSpeedBasedOn2DCoords(Float:oX, Float:oY, Float:nX, Float:nY, Float:time)
{
new Float:dis2D, Float:unitsPerSecond;
dis2D = ahx_Distance2D(nX, nY, oX, oY);
unitsPerSecond = dis2D / time;
return unitsPerSecond * 3.6;
}
stock ahx_HasTimePassed(oldtick, time)
{
new cT;
cT = tickcount();
if ((cT - oldtick) > time)
{ return true; }
return false;
}
/* ahx_BanPlayerIpEx: Ban player (ip, no nick) with reason*/
stock ahx_BanPlayerIpEx(playerid, reason[])
{
new message[100];
format(message, sizeof(message), "You have been banned (%s)", reason);
ahx_PlayerMessage(playerid, message);
new gmessage[100];
format(gmessage, sizeof(gmessage), "%s: Banned (%s)", ahx_PlayerName(playerid), reason);
ahx_PlayerMessageToEveryone(gmessage);
Ban(playerid);
}
/* ahx_IsPlayerAdmin: Calls remote function AHXIsPlayerAdmin to ask from gamemode whether player is admin */
stock ahx_IsPlayerAdmin(playerid)
{
return CallRemoteFunction("AHXIsPlayerAdmin", "i", playerid);
}
/* ahx_AddLogEntry: Log string*/
stock ahx_AddLogEntry(msg[])
{
new Year, Month, Day;
getdate(Year, Month, Day);
new Hour, Minute, Second;
gettime(Hour, Minute, Second);
new File:log = fopen(LOG_FILE, io_append);
new entry[120];
format(entry, sizeof(entry), "%02d/%02d/%02d %02d:%02d:%02d : %s\r\n", Day, Month, Year, Hour, Minute, Second, msg);
fwrite(log, entry);
fclose(log);
}
pawn Код:
#include <a_samp>
#define GetPlayerMoney(%1) CallRemoteFunction("ahx_Override_GetPlayerMoney","i",%1)
#define GivePlayerMoney(%1,%2) CallRemoteFunction("ahx_Override_GivePlayerMoney","ii",%1,%2)
#define ResetPlayerMoney(%1) CallRemoteFunction("ahx_Override_ResetPlayerMoney","i",%1)
#define SetAHXIgnoreForPlayer(%1,%2) CallRemoteFunction("ahx_Calls_SetAHXIgnoreForPlayer","ii", %1, %2)
#define GivePlayerWeapon(%1,%2,%3) CallRemoteFunction("ahx_Override_GivePlayerWeapon","iii", %1, %2, %3)
#define ResetPlayerWeapons(%1) CallRemoteFunction("ahx_Override_ResetPlayerWeapons","i", %1)
#define SetPlayerAmmo(%1,%2,%3) CallRemoteFunction("ahx_Override_SetPlayerAmmo","iii", %1, %2, %3)