08.01.2015, 19:11
It doesn't sync well when a player is firing from an MP5, i've tested every single weapon and this one turned out to have flaws.
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if( hittype != BULLET_HIT_TYPE_NONE ) // Bullet Crashing uses just this hittype
{
if( !( -1000.0 <= fX <= 1000.0 ) || !( -1000.0 <= fY <= 1000.0 ) || !( -1000.0 <= fZ <= 1000.0 ) ) // a valid offset, it's impossible that a offset bigger than 1000 is legit (also less than -1000.0 is impossible, not used by this hack, but still, let's check for it, just for the future, who knows what hacks will appear). The object with biggest offset is having ~700-800 radius.
{
Kick(playerid);
return 0; // let's desynchronize that bullet, so players won't crash
}
}
new beforeAmmo = PVar:playerid[WeaponAmmo][weaponid];
new leftAmmo = GetWeaponAmmo(playerid, weaponid) - 1;
if(PlayerHasWeapon(playerid, weaponid))
{
if(beforeAmmo - leftAmmo == 1)
{
if(!PVar:playerid[SpawnedWeapon][weaponid])
{
if(IsPrimaryWeapon(weaponid))
{
if(weaponid == PVar:playerid[Weapons][PRIME_WEP])
{
if(leftAmmo == 0)
{
PVar:playerid[Weapons][PRIME_WEP] = 0;
}
PVar:playerid[Weapons][PRIME_AMMO] = leftAmmo;
}
}
else if(IsSecondaryWeapon(weaponid))
{
if(weaponid == PVar:playerid[Weapons][SECOND_WEP])
{
if(leftAmmo == 0)
{
PVar:playerid[Weapons][SECOND_WEP] = 0;
}
PVar:playerid[Weapons][SECOND_AMMO] = leftAmmo;
}
}
}
if(leftAmmo == 0)
{
if(PVar:playerid[SpawnedWeapon][weaponid])
{
PVar:playerid[SpawnedWeapon][weaponid] = false;
RemovePlayerWeapon(playerid, weaponid);
}
}
PVar:playerid[WeaponAmmo][weaponid] = leftAmmo;
}
}
return 1;
}
GetWeaponAmmo(playerid, weaponid)
{
new weapon, ammo;
GetPlayerWeaponData(playerid, GetWeaponSlot(weaponid), weapon, ammo);
return ammo;
}
GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0,1: slot = 0;
case 2..9: slot = 1;
case 22..24: slot = 2;
case 25..27: slot = 3;
case 28,29,32: slot = 4;
case 30,31: slot = 5;
case 33,34: slot = 6;
case 35..38: slot = 7;
case 16..18,39: slot = 8;
case 41..43: slot = 9;
case 10..15: slot = 10;
case 44..46: slot = 11;
case 40: slot = 12;
default: slot = INVALID_WEAPON_SLOT_ID;
}
return slot;
}
GetWeaponAmmo(playerid, weaponid)
{
new weapon, ammo;
if(GetPlayerWeapon(playerid) == WEAPON_MP5)
{
return GetPlayerAmmo(playerid);
}
GetPlayerWeaponData(playerid, GetWeaponSlot(weaponid), weapon, ammo);
return ammo;
}