Problem With Anti-2Shot (Sawns) -
Airman123 - 20.04.2015
Hello, im using the following code in my server for anti 2-shot.
Using the "OnPlayerUpdate" func.
PHP код:
public OnPlayerUpdate(playerid)
{
// anti 2 shot
static
s_iState,
s_iSpecialAction
;
s_iState = GetPlayerState( playerid );
s_iSpecialAction = GetPlayerSpecialAction( playerid );
if ( s_iState == PLAYER_STATE_ONFOOT && ( s_iSpecialAction == SPECIAL_ACTION_NONE || s_iSpecialAction == SPECIAL_ACTION_DUCK ) )
{
static
s_iWeapon,
s_iAmmo
;
s_iWeapon = GetPlayerWeapon( playerid );
s_iAmmo = GetPlayerAmmo( playerid );
if ( g_cPreviousWeapon{ playerid } != s_iWeapon )
{
if ( g_cPreviousWeapon{ playerid } == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
static
s_iWeaponState
;
s_iWeaponState = GetPlayerWeaponState( playerid );
if ( ( s_iWeaponState == WEAPONSTATE_MORE_BULLETS || s_iWeaponState == WEAPONSTATE_LAST_BULLET ) && g_cFiredShots{ playerid } != 4 )
{
Bit_Let( g_abThisBitchDidntReload, playerid );
g_iReloadEvadeTime[ playerid ] = GetTickCount( );
}
}
g_cFiredShots{ playerid } = 0;
}
else if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abThisBitchDidntReload, playerid ) )
{
if ( GetTickCount( ) - g_iReloadEvadeTime[ playerid ] < PUNISH_THRESOLD )
{
new
Float:fVX,
Float:fVY,
Float:fVZ
;
GetPlayerVelocity( playerid, fVX, fVY, fVZ );
if ( floatabs( fVZ ) < 0.15 )
{
new string[256];
if(sWarns[playerid] == 0)
{
sWarns[playerid]++;
GameTextForPlayer(playerid, "~r~2 shots Detected!", 3500, 3);
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 80;
}
else
if(sWarns[playerid] == 1)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 140;
}
}
else
if(sWarns[playerid] == 2)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 240;
}
}
else
if(sWarns[playerid] == 3)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 520;
}
}
else
if(sWarns[playerid] == 4)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 720;
}
}
}
}
Bit_Vet( g_abThisBitchDidntReload, playerid );
}
}
g_cPreviousWeapon{ playerid } = s_iWeapon;
}
if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( g_iSawnoffAmmo[ playerid ] == -1 )
g_iSawnoffAmmo[ playerid ] = GetPlayerAmmo( playerid );
else
{
if ( GetPlayerWeaponState( playerid ) == WEAPONSTATE_RELOADING )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
}
else
{
if ( g_iSawnoffAmmo[ playerid ] != s_iAmmo )
{
if ( s_iAmmo < g_iSawnoffAmmo[ playerid ] )
{
Bit_Let( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } += g_iSawnoffAmmo[ playerid ] - s_iAmmo;
}
else
{
g_cFiredShots{ playerid } = 0;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
}
g_iSawnoffAmmo[ playerid ] = s_iAmmo;
}
}
}
}
else if ( g_iSawnoffAmmo[ playerid ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
g_iSawnoffAmmo[ playerid ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } = 0;
}
}
else if ( g_iSawnoffAmmo[ playerid ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
g_iSawnoffAmmo[ playerid ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } = 0;
}
return 1;
}
There is a problem in this code, it give the false warning for anti 2-shot whenever the player switches the sawns not to 2-shot but to use the other weap..
Like if someone shoots 3 bullets from sawns and then scrolls to other weap (it will give warning)
I want to make it like, when someone switches the sawns and then scroll back to sawns then it should give the warning, not when some one switches to other weapon.
Any help?
Re: Problem With Anti-2Shot (Sawns) -
Banana_Ghost - 21.04.2015
That appears to be slice's anti-2shot script he wrote a while ago. Try lowering the punishment threshold a bit.
#define PUNISH_THRESOLD (2500). I extensively tested this a few years ago and there were no flaws in it. While your at it, use this:
pawn Код:
public OnPlayerUpdate( iPlayer )
{
static
s_iState,
s_iSpecialAction
;
s_iState = GetPlayerState( iPlayer );
s_iSpecialAction = GetPlayerSpecialAction( iPlayer );
if ( s_iState == PLAYER_STATE_ONFOOT && ( s_iSpecialAction == SPECIAL_ACTION_NONE || s_iSpecialAction == SPECIAL_ACTION_DUCK ) )
{
static
s_iWeapon,
s_iAmmo
;
s_iWeapon = GetPlayerWeapon( iPlayer );
s_iAmmo = GetPlayerAmmo( iPlayer );
if ( g_cPreviousWeapon{ iPlayer } != s_iWeapon )
{
if ( g_cPreviousWeapon{ iPlayer } == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, iPlayer ) )
{
static
s_iWeaponState
;
s_iWeaponState = GetPlayerWeaponState( iPlayer );
if ( ( s_iWeaponState == WEAPONSTATE_MORE_BULLETS || s_iWeaponState == WEAPONSTATE_LAST_BULLET ) && g_cFiredShots{ iPlayer } != 4 )
{
Bit_Let( g_abThisBitchDidntReload, iPlayer );
g_iReloadEvadeTime[ iPlayer ] = GetTickCount( );
}
}
g_cFiredShots{ iPlayer } = 0;
}
else if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abThisBitchDidntReload, iPlayer ) )
{
if ( GetTickCount( ) - g_iReloadEvadeTime[ iPlayer ] < PUNISH_THRESOLD )
{
new
Float:fVX,
Float:fVY,
Float:fVZ
;
GetPlayerVelocity( iPlayer, fVX, fVY, fVZ );
if ( floatabs( fVZ ) < 0.15 )
{
new string[65 + MAX_PLAYER_NAME];
switch(sWarns[playerid])
{
case 0:
{
sWarns[playerid]++;
GameTextForPlayer(playerid, "~r~2 shot Detected!", 3500, 3);
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shot.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 80;
}
case 1:
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shot.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 140;
}
}
case 2:
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shot.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 240;
}
}
case 3:
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shot.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 520;
}
}
case 4:
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shot.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 720;
}
}
}
}
}
Bit_Vet( g_abThisBitchDidntReload, iPlayer );
}
}
g_cPreviousWeapon{ iPlayer } = s_iWeapon;
}
if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( g_iSawnoffAmmo[ iPlayer ] == -1 )
g_iSawnoffAmmo[ iPlayer ] = GetPlayerAmmo( iPlayer );
else
{
if ( GetPlayerWeaponState( iPlayer ) == WEAPONSTATE_RELOADING )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, iPlayer ) )
Bit_Vet( g_abIsSawnoffClipUsed, iPlayer );
}
else
{
if ( g_iSawnoffAmmo[ iPlayer ] != s_iAmmo )
{
if ( s_iAmmo < g_iSawnoffAmmo[ iPlayer ] )
{
Bit_Let( g_abIsSawnoffClipUsed, iPlayer );
g_cFiredShots{ iPlayer } += g_iSawnoffAmmo[ iPlayer ] - s_iAmmo;
}
else
{
g_cFiredShots{ iPlayer } = 0;
Bit_Vet( g_abIsSawnoffClipUsed, iPlayer );
}
g_iSawnoffAmmo[ iPlayer ] = s_iAmmo;
}
}
}
}
else if ( g_iSawnoffAmmo[ iPlayer ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, iPlayer ) )
{
g_iSawnoffAmmo[ iPlayer ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, iPlayer );
g_cFiredShots{ iPlayer } = 0;
}
}
else if ( g_iSawnoffAmmo[ iPlayer ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, iPlayer ) )
{
g_iSawnoffAmmo[ iPlayer ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, iPlayer );
g_cFiredShots{ iPlayer } = 0;
}
return 1;
}
switch and case statements are better than if statements (faster and neater), I also lowered your string size as 256 is not needed period.
Re: Problem With Anti-2Shot (Sawns) -
Airman123 - 23.04.2015
i'll check this out, thanks.
Re: Problem With Anti-2Shot (Sawns) -
ball - 23.04.2015
I made this script using callback OnPlayerWeaponShot, link:
https://sampforum.blast.hk/showthread.php?pid=3034954#pid3034954
Re: Problem With Anti-2Shot (Sawns) -
Airman123 - 24.04.2015
Thanks banana_ghost, that worked. + REP