Anti ammo hack
#1

Howdy,

I have made an anti spawn ammo hack in my server, which basically kicks the player who spawn AMMO not weapon.
Like you already have the weapon but you spawn ammo for it.

So yeah, It's not working fine in the host at all, I'm using OnPlayerWeaponShot and it keeps kicking the players whenever they shot.

Here's my custom GivePlayerWeapon function:

PHP код:
new gPlayerAmmo[MAX_PLAYERS][12];
GivePlayerWeaponEx(playeridweaponidammo) {
    if(!
weaponid) return 0;
    
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = ammo;
    return 
GivePlayerWeapon(playeridweaponidammo);

Here's my OnPlayerWeaponShot:

PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    if(
weaponid != && weaponid != 46)
    {
        if(
GetPlayerAmmo(playerid) < gPlayerAmmo[playerid][GetWeaponSlot(weaponid)]) {
            
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = GetPlayerAmmo(playerid);
        }
        if(!
InEvent[playerid] && !InDerby[playerid] && !InTDM[playerid] && !InParkour[playerid] && !InSkydive[playerid] && !InDuel[playerid] && !Info[playerid][InDM] && !InShooter[playerid]) {
            if(
GetPlayerAmmo(playerid) > && GetPlayerAmmo(playerid) > gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] && GetPlayerVirtualWorld(playerid) == 0) {
                
RemovePlayerWeapon(playeridweaponid);
                
gPlayerWeapon[playerid][GetWeaponSlot(weaponid)] = false;
                
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = 0;
                
format(stringsizeof string"{FF0000}<!> {CC6699}%s has been kicked for ammo hack"GetName(playerid));
                
SendClientMessageToAll(redstring);
                return 
DelayKick(playerid);
            }
        }
    }
    return 
1;

Any help would be appreciated.
Thanks in advance.
Reply
#2

OPWS is inaccurate.
Reply
#3

I already know that .. I'm not decreasing/increasing anything with the weapon's ammo.
You ain't helping me actually.
Reply
#4

I believe it's something to do with GetPlayerAmmo as it returns the old ammo so you need to subtract 1 from GetPlayerAmmo to get the new ammo. Also you should create a variable for the ammo and weapon slot instead of repeating the functions and these weaponid checks are not necessary because OnPlayerWeaponShot is only called when you shoot a gun, but I suggest you to check if the weaponid is not the minigun because it's fire rate is so fast that it will kick you whenever you shoot it and I also suggest you to create a variable for warnings. Everytime player shoots and has cheated ammo add 1 to the warnings variable and when it reaches 3 kick the player for example, but when player hasn't cheated ammo then subtract 1 from the warnings variable if there's something to subtract. That's what I do because this will prevent false kicks most of the time.
Reply
#5

You should use GetPlayerWeaponData for this, it is more accurate than GetPlayerAmmo. That way you can check the ammo for a specific weapon, instead of getting the ammo for the current weapon (which could change even though OPWS is still calling for another weapon).

Also I would not do this in OnPlayerWeaponShot, weapon data is not synced with every shot. There is no need to check this as often as any gun actually shoots (best example would be minigun, or UZI).
Reply
#6

What about this way? using OnPlayerUpdate:

PHP код:
public OnPlayerUpdate(playerid) {
    new 
player_weapon GetPlayerWeapon(playerid);
    if(
player_weapon)
        
DetectAmmoCheats(playeridplayer_weapon);
    return 
1;
}
DetectAmmoCheats(playeridweaponid) {
    new 
weapon_idweapon_ammo;
    
GetPlayerWeaponData(playeridGetWeaponSlot(weaponid), weapon_idweapon_ammo);
    if(
Info[playerid][Logged] && !InEvent[playerid] && !InDerby[playerid] && !InTDM[playerid] && !InParkour[playerid] && !InSkydive[playerid] && !InDuel[playerid] && !Info[playerid][InDM] && !InShooter[playerid]) {
        if(
weapon_ammo && weapon_ammo gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] + 10 && GetPlayerVirtualWorld(playerid) == 0) {
            
RemovePlayerWeapon(playeridweaponid);
            
Info[playerid][Logged] = 0;
            
format(stringsizeof string"{FF0000}<!> {CC6699}%s has been kicked for ammo hack"GetName(playerid));
            
SendClientMessageToAll(redstring);
            return 
DelayKick(playerid);
        }
        else 
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = weapon_ammo;
    }
    return 
1;

I've tested it in localhost and as far as I can see it works flawless, debugged it and the values seems accurate.
Will it work the same in the VPS? with +20 players?
Reply
#7

My opinion, don't kick people. Send out admin warnings. It's better for a player to be banned by an administrator then a faulty anti cheat system. If you think your system doesn't perform well then that's a cause to not ban anyone based on the results provided.

https://sampforum.blast.hk/showthread.php?tid=30938&page=442

I asked about a similar system. This isn't fully tested but what seems like a plausible way of doing an anti ammo hack is:

PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
      if(
PlayerHasWeapon(playeridweaponid))
        
UpdatePlayerWeapon(playeridweaponid); 
      return 
1;

It would check if the player has the weapon scriptwise. There's room for an anti-weapon cheat in there as well.

When UpdatePlayerWeapons is called just --gPlayerAmmo.

Then if GetPlayerAmmo != gPlayerAmmo, possible cheat detected? This requires you update the variable on every instance of an ammo change (if the player gains more, et cetera...). I guess this is basically what you're doing. I don't see why it wouldn't work.
Reply
#8

I think checking if the current ammo > gPlayerAmmo is more accurate than checking if the current ammo != gPlayerAmmo, isn't it?
Also, kicking the player would be better, in case there are no admins online or they're AFK.

I'm going to test the last code I posted in the VPS and share here if it worked or not, if there is anything you guys would recommend me to do to improve the code, tell me please.
Reply
#9

OPU is even worse. Create your own shoot detection system.
Reply
#10

Try with this (server side: weapons, health, armour, damage):
ADM_Guard.inc
Reply
#11

I don't see where in your include prevent ammo hack, could you explain to me how this works exactly?
Reply
#12

If weaponid in slot is different than server side weapon -> kick
If server side ammo is 0 -> remove weapon (when player increase ammo for current weapon, not working)

e.g.
player weapon in slot 5 is:
0 - server side
31 - player game (added M4 by Weapon Hack)
0 != 31 -> kick
Reply
#13

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
when player increase ammo for current weapon, not working
Well, I'm searching for a way to prevent this hack, increasing ammo for the current weapon.
Reply
#14

Quote:
Originally Posted by oMa37
Посмотреть сообщение
Well, I'm searching for a way to prevent this hack, increasing ammo for the current weapon.
ammo:
15 - server side
350 - game

when server side ammo is 0 -> remove weapon -> set server side ammo 0, weaponid 0

next shot -> kick
Reply
#15

Anti Weapon Hack:
https://www.youtube.com/watch?v=vGGTEn1EQOQ
Reply
#16

I have improved it a little bit and removed some stuff that I already have in my gamemode, I will test it and share what happens here.
Thank you.
Reply
#17

Hello sir Oma37.

at the first do you assign weapons to players using the AddPlayerClass last 6 parameters?

if yes then you need to hook this function to give this weapons to the player in his gPlayerAmmo var too.

also the next mistake is gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = ammo;
when you give a weapon to player in samp if he already has it the ammo will increase, so you have to "increase" the ammo rather than setting its value.
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] += ammo;
Reply
#18

Quote:
Originally Posted by jlalt
Посмотреть сообщение
also the next mistake is gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] = ammo;
when you give a weapon to player in samp if he already has it the ammo will increase, so you have to "increase" the ammo rather than setting its value.
gPlayerAmmo[playerid][GetWeaponSlot(weaponid)] += ammo;
Ahh .. Yeah .. I didn't think about that lol.
Thank you for pointing that out for me, I will try the both methods. Yours and AbyssMorgan's method.
Reply
#19

Quote:
Originally Posted by Logic_
Посмотреть сообщение
OPWS is inaccurate.
What do you mean? Why is inaccurate?
Reply
#20

I still can't find out an effective way to get this done, I tried OnPlayerWeaponShot, OnPlayerUpdate, repeating timer, Abyss's include. I really can't find out anything working effectively, hackers are still able to increase the weapon's ammo.

This is my new code under OnPlayerWeaponShot:

PHP код:
        new slot GetWeaponSlot(weaponid);
        
gPlayerAmmo[playerid][slot]--;
        if(
GetPlayerAmmo(playerid) > && GetPlayerAmmo(playerid) > gPlayerAmmo[playerid][slot] + 15) {
            
RemovePlayerWeapon(playeridweaponid);
            
format(stringsizeof string"{FF0000}<!> {CC6699}%s has been kicked for ammo hack"GetName(playerid));
            
SendClientMessageToAll(redstring);
            return 
DelayKick(playerid);
        }
        else 
gPlayerAmmo[playerid][slot] = GetPlayerAmmo(playerid); 
My custom GivePlayerWeapon function:

PHP код:
GivePlayerWeaponEx(playeridweaponidammo) {
    new 
slot GetWeaponSlot(weaponid);
    
SetPlayerArmedWeapon(playeridweaponid);
    if(
GetWeaponSlot(GetPlayerWeapon(playerid)) == slot) {
        
gPlayerWeapon[playerid][slot] = true;
        
gPlayerAmmo[playerid][slot] += ammo;
    }
    else {
        
gPlayerWeapon[playerid][slot] = true;
        
gPlayerAmmo[playerid][slot] = ammo;
    }
    return 
GivePlayerWeapon(playeridweaponidammo);

These codes sometimes works sometimes not, mostly not.
Any idea how to make it effective enough to prevent ammo hack and false kicks?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)