Created
April 8, 2014 20:27
-
-
Save Southclaws/10186202 to your computer and use it in GitHub Desktop.
Increased fire rate cheat detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FILTERSCRIPT | |
#include <a_samp> | |
#include <ZCMD> | |
static | |
WeaponShotIntervals[17] = | |
{ | |
// Pistols | |
300, // 22 M9 WHEN DUAL: 185 | |
400, // 23 M9 SD | |
800, // 24 Desert Eagle | |
// Shotgun | |
1060, // 25 Shotgun | |
300, // 26 Sawnoff WHEN DUAL: 140 | |
320, // 27 Spas 12 | |
// Automatic | |
120, // 28 Mac 10 WHEN DUAL: 35 | |
100, // 29 MP5 | |
120, // 30 AK-47 | |
120, // 31 M16 | |
120, // 32 Tec 9 WHEN DUAL: 35 | |
// Rifle | |
1060, // 33 Rifle | |
1060, // 34 Sniper | |
// Heavy | |
0, // 35 RPG | |
0, // 36 Heatseeker | |
0, // 37 Flamer | |
20 // 38 Minigun | |
}, | |
PlayerSkillLevel[MAX_PLAYERS] = {999, ...}, | |
PlayerLastShotTick[MAX_PLAYERS]; | |
forward OnAntiCheatFireRate(playerid, weaponid, interval); | |
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) | |
{ | |
new | |
interval = GetTickCountDifference(PlayerLastShotTick[playerid], GetTickCount()), | |
weaponshotinterval = WeaponShotIntervals[weaponid - 22] - 20; | |
if(PlayerSkillLevel[playerid] == 999) | |
{ | |
switch(weaponid) | |
{ | |
case 22: weaponshotinterval = 185; | |
case 26: weaponshotinterval = 140; | |
case 28: weaponshotinterval = 35; | |
case 32: weaponshotinterval = 35; | |
} | |
} | |
if(interval < weaponshotinterval) | |
{ | |
CallLocalFunction("OnAntiCheatFireRate", "ddd", playerid, weaponid, interval); | |
return 0; | |
} | |
PlayerLastShotTick[playerid] = GetTickCount(); | |
#if defined ac_OnPlayerWeaponShot | |
return ac_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ); | |
#else | |
return 1; | |
#endif | |
} | |
#if defined _ALS_OnPlayerWeaponShot | |
#undef OnPlayerWeaponShot | |
#else | |
#define _ALS_OnPlayerWeaponShot | |
#endif | |
#define OnPlayerWeaponShot ac_OnPlayerWeaponShot | |
#if defined ac_OnPlayerWeaponShot | |
forward ac_OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ); | |
#endif | |
stock ac_SetPlayerSkillLevel(playerid, skill, level) | |
{ | |
PlayerSkillLevel[playerid] = level; | |
return SetPlayerSkillLevel(playerid, skill, level); | |
} | |
#if defined _ALS_SetPlayerSkillLevel | |
#undef SetPlayerSkillLevel | |
#else | |
#define _ALS_SetPlayerSkillLevel | |
#endif | |
#define SetPlayerSkillLevel ac_SetPlayerSkillLevel | |
/* | |
I forgot the original creator for this code but it's very useful. | |
Effectively abstracts the basic checking for tick count intervals with some | |
extra code that compensates for integer overflowing from GetTickCount if the | |
server machine has been on for over 2,147,483,647 milliseconds. | |
Permalink : https://github.com/Southclaw/ScavengeSurvive/blob/master/gamemodes/SS/utils/tickcountfix.pwn | |
Code also below for completion: | |
*/ | |
stock intdiffabs(tick1, tick2) | |
{ | |
if(tick1 > tick2) | |
{ | |
new value = (tick1 - tick2); | |
return value < 0 ? -value : value; | |
} | |
else | |
{ | |
new value = (tick1 - tick2); | |
return value < 0 ? -value : value; | |
} | |
} | |
stock GetTickCountDifference(a, b) | |
{ | |
if ((a < 0) && (b > 0)) | |
{ | |
new dist; | |
dist = intdiffabs(a, b); | |
if(dist > 2147483647) | |
return intdiffabs(a - 2147483647, b - 2147483647); | |
else | |
return dist; | |
} | |
return intdiffabs(a, b); | |
} | |
/* | |
Testing | |
*/ | |
public OnAntiCheatFireRate(playerid, weaponid, interval) | |
{ | |
SendClientMessageToAll(-1, "Fire rate cheat detected"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment