[Tutorial] Anti Ammo Hack
#1

Hello, Here is other tutorial to make anti infinite ammo hack it seems easy but it is a little bit tricky
Lets start with defines
PHP код:
new bAmmo[MAX_PLAYERS];
new 
bWeapon[MAX_PLAYERS];
new 
nAmmo[MAX_PLAYERS];
new 
nWeapon[MAX_PLAYERS];
new 
bool:pm[MAX_PLAYERS];
new 
bool:sm[MAX_PLAYERS];
new 
bool:checked[MAX_PLAYERS];
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) 
You will know each one of this but later :P

Now lets start
First our code will be under OnPlayerKeyStateChange and with some timers :3

Before start set these under OnPlayerConnect to make sure to not ban an innocent player
PHP код:
public OnPlayerConnect(playerid)
{
    
bAmmo[playerid] = 0;
    
bWeapon[playerid] = 0;
    
nAmmo[playerid] = 0;
    
nWeapon[playerid] = 0;
    
checked[playerid] = false;
    return 
1;

These set all our variables to 0 and false as you saw

Under OnKeySt..........
PHP код:
    if (PRESSED(KEY_FIRE))
    { 
Here we check if the player pressed the key fire (We defined PRESSED up !)

PHP код:
if(checked[playerid] == false && GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING && GetPlayerWeapon(playerid) != 24
Ok, Time for explain

if the (checked bool equal false) why ?
To disable the script to check the ammo twice and because of the timer mabye the ammo of the player will be the same after checking the second time so we must be sure that is it false.

if the (weapon state not equal reloading) why ?
Because when the player reloading the ammo doesn't change so it will ban the player

if the (weapon isn't equal Desert Eagle) why ?
I don't know but when i made the script i found the dersert eagle bugged so i made his timer bigger than the other weapons we will see later.

Note: All of this code to start getting the ammo not to check them and all to make sure not to ban an innocent player as i said.

Lets move for the second part:
PHP код:
bAmmo[playerid] = GetPlayerAmmo(playerid);
bWeapon[playerid] = GetPlayerWeapon(playerid);
if(
GetPlayerWeapon(playerid) < 16 || GetPlayerWeapon(playerid) == 19 || GetPlayerWeapon(playerid) == 20 || GetPlayerWeapon(playerid) == 21 || GetPlayerWeapon(playerid) > 38) return 0;
SetTimerEx("Acheck",1000,false,"i",playerid);
checked[playerid] = true;

Lets see:

now we stored the player ammo in the variable that we define before at the top to check it again (Will see -_-)
And we stored the player weapon in the other variable that we defind at the top to check it again (Same -_-)

if(GetPlayerWeapon(playerid) < 16 || GetPlayerWeapon(playerid) == 19 || GetPlayerWeapon(playerid) == 20 || GetPlayerWeapon(playerid) == 21 || GetPlayerWeapon(playerid) > 3 return 0;

These guns id are not defined in samp so there isn't any gun equal 19 or 20 or 21 and the weapons that under 16 don't shoot bullet and the weapon over 38 the same ( They isn't weapons anyway :P )

Now set a timer to check the ammo
And make the bool to true to prevent checking it again

And now for the Deser Eagle,
At the same callback under these
PHP код:
else if(checked[playerid] == false && GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING && GetPlayerWeapon(playerid) == 24)
{
bAmmo[playerid] = GetPlayerAmmo(playerid);
bWeapon[playerid] = GetPlayerWeapon(playerid);
if(
GetPlayerWeapon(playerid) < 16 || GetPlayerWeapon(playerid) == 19 || GetPlayerWeapon(playerid) == 20 || GetPlayerWeapon(playerid) == 21 || GetPlayerWeapon(playerid) > 38) return 0;
SetTimerEx("Acheck",4000,false,"i",playerid);
checked[playerid] = true;
}
}
return 
1;

Same as above but we increased the timer .

When the time work we will call a stock

PHP код:
forward Acheck(playerid);
public 
Acheck(playerid)
{
    
AmmoCheck(playerid);

Don't ask me why but it worked like this xD
I think no need for explaination here !

Then in the stock
PHP код:
stock AmmoCheck(playerid)
{
nAmmo[playerid] = GetPlayerAmmo(playerid);
nWeapon[playerid] = GetPlayerWeapon(playerid);
SetTimerEx("check",500,false,"i",playerid);
return 
1;

Now we will add the new ammo after the timer in another variable (The old one was bAmmo this is nAmmo)
And the weapon as same
And set a timer again

And don't ask me why it worked also like that :P

Now for the second timer
PHP код:
forward check(playerid);
public 
check(playerid)
{
checked[playerid] = false;
if(
bAmmo[playerid] == nAmmo[playerid] && bWeapon[playerid] == nWeapon[playerid] && GetPlayerWeaponState(playerid) != WEAPONSTATE_RELOADING)
{
new 
string[128];
new 
name[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
if(
pm[playerid] == false && sm[playerid] == false)
{
format(string,sizeof(string),"%s has banned for ammo hack",name); //You can change the messages as you like
SendClientMessageToAll(0xAA3333AA,string);
SendClientMessage(playerid0xAA3333AA,"You have banned from the server "); //The same here
}
SetTimerEx("ban",500,false,"i",playerid);
pm[playerid] = true;
sm[playerid] = true;
#pragma unused string1
}
return 
1;

Now for the big IF .....
This will check the old ammo that we stored before the timer and will check the old weapon the stored also before the timer if they are equal and the weapon state not equal reloading (I said why before !)
Then
Get player name and send him a message and a message for the server and pm and sm bool to avoid messages spam and the last timer to ban the player
PHP код:
forward ban(playerid);
public 
ban(playerid)
{
     
BanEx(playerid,"Infinite Ammo"); //You can add here your reasons
    
return 1;

Ok, End of the tutorial Hope you will like it,
Ahmed_Nezoo
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)