Skip to content

Instantly share code, notes, and snippets.

@Southclaws
Created April 8, 2014 20:26
Show Gist options
  • Save Southclaws/10186150 to your computer and use it in GitHub Desktop.
Save Southclaws/10186150 to your computer and use it in GitHub Desktop.
Infinite ammo / No-reload cheat detection
#define FILTERSCRIPT
#include <a_samp>
#include <ZCMD>
static
WeaponMagSizes[17] =
{
// Pistols
017, // 22 M9
017, // 23 M9 SD
007, // 24 Desert Eagle
// Shotgun
001, // 25 Shotgun
002, // 26 Sawnoff
007, // 27 Spas 12
// Automatic
050, // 28 Mac 10
030, // 29 MP5
030, // 30 AK-47
050, // 31 M16
050, // 32 Tec 9
// Rifle
001, // 33 Rifle
001, // 34 Sniper
// Heavy
001, // 35 RPG
001, // 36 Heatseeker
500, // 37 Flamer
500 // 38 Minigun
},
PlayerSkillLevel[MAX_PLAYERS] = {999, ...},
PlayerLastShotTick[MAX_PLAYERS],
PlayerShotCounter[MAX_PLAYERS];
forward OnAntiCheatNoReload(playerid, roundsfired);
public OnPlayerUpdate(playerid)
{
static lastweapon;
new currentweapon = GetPlayerWeapon(playerid);
if(lastweapon != currentweapon)
{
// Player reloaded by quick-switching
PlayerShotCounter[playerid] = 0;
lastweapon = currentweapon;
}
#if defined ac_OnPlayerUpdate
return ac_OnPlayerUpdate(playerid);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerUpdate
#undef OnPlayerUpdate
#else
#define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate ac_OnPlayerUpdate
#if defined ac_OnPlayerUpdate
forward ac_OnPlayerUpdate(playerid);
#endif
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(weaponid == 33 || weaponid == 34)
return 1;
new
magsize = WeaponMagSizes[weaponid - 22],
weaponstate = GetPlayerWeaponState(playerid);
PlayerShotCounter[playerid]++;
// Check if the player is using dual weapons
if(PlayerSkillLevel[playerid] == 999)
{
if(weaponid == 22 || weaponid == 26 || weaponid == 28 || weaponid == 32)
magsize *= 2;
}
// If the amount of fired shots exceeds the magazine size for the weapon
// the player is probably using an infinite ammo mod.
if(PlayerShotCounter[playerid] == magsize)
{
if(weaponstate != 1)
CallLocalFunction("OnAntiCheatNoReload", "ii", playerid, PlayerShotCounter[playerid]);
else
PlayerShotCounter[playerid] = 0;
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
/*
Testing commands
*/
CMD:w(playerid, params[])
{
new weaponid = strval(params);
GivePlayerWeapon(playerid, weaponid, 1000);
}
CMD:s(playerid, params[])
{
new skill = strval(params);
SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL_SILENCED, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_DESERT_EAGLE, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SHOTGUN, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SPAS12_SHOTGUN, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_MICRO_UZI, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_MP5, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_AK47, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_M4, skill);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SNIPERRIFLE, skill);
}
public OnAntiCheatNoReload(playerid, roundsfired)
{
SendClientMessageToAll(-1, "Cheat detected");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment