Anti weapon hack assistance
#1

So I basically made the stock for giving the weapons and I made a check.

Variable:
pawn Код:
new Weapons[MAX_PLAYERS][13], Ammo[MAX_PLAYERS][13];
Stock:
pawn Код:
stock GivePlayerWeaponEx(playerid, weaponid, ammo)
{
    Weapons[playerid][GetWeaponSlot(weaponid)] = weaponid;
    Ammo[playerid][GetWeaponSlot(weaponid)] = ammo;
    return GivePlayerWeapon(playerid, weaponid, ammo);
}
Check:
pawn Код:
if(GetPlayerWeapon(i) != 0 && GetPlayerAmmo(i) != 0)
            {
                new weaps[13][2];
                for(new s = 0; s <= 12; s++)
                {
                    GetPlayerWeaponData(i, s, weaps[i][0], weaps[i][1]);
                    if(Weapons[i][s] != weaps[i][0] && )
                    {
                        format(strtd,sizeof(strtd), "(SERVER): %s(%d) possible weapon hacks (%s).", PlayerInfo[i][Name], i, WeaponName(weaps[i][0]));
                        SendAdminMessage(strtd, 0xD10000AA, 1);
                    }
                    if(Ammo[i][s] < weaps[i][1])
                    {
                        format(strtd,sizeof(strtd), "(SERVER): %s(%d) possible ammo hacks (%d) of weap. (%s).", PlayerInfo[i][Name], i, weaps[i][1], WeaponName(weaps[i][0]));
                        SendAdminMessage(strtd, 0xD10000AA, 1);
                    }
                    printf("sweapon %d, weapon %d, sammo %d, ammo %d", Weapons[i][0], weaps[i][0], Ammo[i][s], weaps[i][1]);
                }
            }
However it's giving some false information in the printf message, every time the variable Weapons is 0, the ammo variable works but the Weapons doesn't.

Example, I gave myself desert eagle and this is the result:
sweapon = variable weapon, sammo = variable ammo and ignore the slot part, didn't use it for this case.

Код:
[10:17:30] sweapon 0, weapon 24, sammo 250, ammo 300, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 200, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 400, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 4, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot 
[10:17:30] sweapon 0, weapon 0, sammo 0, ammo 0, sslot , slot
So what's wrong, how should I fix it?
Reply
#2

didnt check all of the code but change this:
pawn Код:
printf("sweapon %d, weapon %d, sammo %d, ammo %d", Weapons[i][0], weaps[i][0], Ammo[i][s], weaps[i][1]);
to this:
pawn Код:
printf("sweapon %d, weapon %d, sammo %d, ammo %d", Weapons[i][s], weaps[i][0], Ammo[i][s], weaps[i][1]);
and also change this:
pawn Код:
GetPlayerWeaponData(i, s, weaps[i][0], weaps[i][1]); // i is playerid not slot id
to:
pawn Код:
GetPlayerWeaponData(i, s, weaps[s][0], weaps[s][1]);
Reply
#3

I managed to have it working by changing some stuff.

Stock:
pawn Код:
stock GivePlayerWeaponEx(playerid, weaponid, ammo)
{
    Weapons[playerid][GetWeaponSlot(weaponid)] = weaponid;
    Ammo[playerid][GetWeaponSlot(weaponid)] += ammo;
    return GivePlayerWeapon(playerid, weaponid, ammo);
}
Check:
pawn Код:
if(GetPlayerWeapon(i) != 0 && GetPlayerAmmo(i) != 0)
            {
                new weapon = GetPlayerWeapon(i), ammo = GetPlayerAmmo(i);
                if(Weapons[i][GetWeaponSlot(weapon)] != weapon || Ammo[i][GetWeaponSlot(weapon)] < ammo)
                {
                    format(strtd,sizeof(strtd), "(SERVER): %s(%d) weap unbalance. Server-side: %s(%d), Client-side: %s(%d).", PlayerInfo[i][Name], i, WeaponName(Weapons[i][GetWeaponSlot(weapon)]), Ammo[i][GetWeaponSlot(weapon)], WeaponName(weapon), ammo);
                    SendAdminMessage(strtd, 0xD10000AA, 1);
                }
                printf("sweapon %d, weapon %d, sammo %d, ammo %d", Weapons[i][GetWeaponSlot(weapon)], weapon, Ammo[i][GetWeaponSlot(weapon)], ammo);
            }
Looks fine now. Gonna test it more to see if I'm gonna find some bugs.
Reply
#4

Check what i have edited in my post,edit what i told you then you will be able to detect all guns once,not only the gun he is holding.
Reply
#5

Thanks for helping!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)