Problem With Anti-2Shot (Sawns)
#1

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 GetPlayerStateplayerid );
    
s_iSpecialAction GetPlayerSpecialActionplayerid );
    if ( 
s_iState == PLAYER_STATE_ONFOOT && ( s_iSpecialAction == SPECIAL_ACTION_NONE || s_iSpecialAction == SPECIAL_ACTION_DUCK ) )
    {
        static
            
s_iWeapon,
            
s_iAmmo
        
;
        
s_iWeapon GetPlayerWeaponplayerid );
        
s_iAmmo GetPlayerAmmoplayerid );
        if ( 
g_cPreviousWeaponplayerid } != s_iWeapon )
        {
            if ( 
g_cPreviousWeaponplayerid } == WEAPON_SAWEDOFF )
            {
                if ( 
Bit_Getg_abIsSawnoffClipUsedplayerid ) )
                {
                    static
                        
s_iWeaponState
                    
;
                    
s_iWeaponState GetPlayerWeaponStateplayerid );
                    if ( ( 
s_iWeaponState == WEAPONSTATE_MORE_BULLETS || s_iWeaponState == WEAPONSTATE_LAST_BULLET ) && g_cFiredShotsplayerid } != )
                    {
                        
Bit_Letg_abThisBitchDidntReloadplayerid );
                        
g_iReloadEvadeTimeplayerid ] = GetTickCount( );
                    }
                }
                
g_cFiredShotsplayerid } = 0;
            }
            else if ( 
s_iWeapon == WEAPON_SAWEDOFF )
            {
                if ( 
Bit_Getg_abThisBitchDidntReloadplayerid ) )
                {
                    if ( 
GetTickCount( ) - g_iReloadEvadeTimeplayerid ] < PUNISH_THRESOLD )
                    {
                        new
                            
Float:fVX,
                            
Float:fVY,
                            
Float:fVZ
                        
;
                        
GetPlayerVelocityplayeridfVXfVYfVZ );
                        if ( 
floatabsfVZ ) < 0.15 )
                        {
                        new 
string[256];
                        if(
sWarns[playerid] == 0)
                        {
                        
sWarns[playerid]++;
                        
GameTextForPlayer(playerid"~r~2 shots Detected!"35003);
                        
format(stringsizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots."PlayerInfo[playerid][pName],playerid);
                        
SendClientMessageToAdmins(COLOR_ADMINstring);
                        
PlayerInfo[playerid][pWarnTime] = 80;
                        }
                        else
                        if(
sWarns[playerid] == 1)
                        {
                         if(
PlayerInfo[playerid][pWarnTime] < 1)
                        {
                        
sWarns[playerid]++;
                        
format(stringsizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots."PlayerInfo[playerid][pName],playerid);
                        
SendClientMessageToAdmins(COLOR_ADMINstring);
                        
PlayerInfo[playerid][pWarnTime] = 140;
                        }
                        }
                        else
                        if(
sWarns[playerid] == 2)
                        {
                        if(
PlayerInfo[playerid][pWarnTime] < 1)
                        {
                        
sWarns[playerid]++;
                        
format(stringsizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots."PlayerInfo[playerid][pName],playerid);
                        
SendClientMessageToAdmins(COLOR_ADMINstring);
                        
PlayerInfo[playerid][pWarnTime] = 240;
                        }
                        }
                          else
                        if(
sWarns[playerid] == 3)
                        {
                        if(
PlayerInfo[playerid][pWarnTime] < 1)
                        {
                        
sWarns[playerid]++;
                        
format(stringsizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots."PlayerInfo[playerid][pName],playerid);
                        
SendClientMessageToAdmins(COLOR_ADMINstring);
                        
PlayerInfo[playerid][pWarnTime] = 520;
                        }
                        }
                          else
                        if(
sWarns[playerid] == 4)
                        {
                        if(
PlayerInfo[playerid][pWarnTime] < 1)
                        {
                        
format(stringsizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots."PlayerInfo[playerid][pName],playerid);
                        
SendClientMessageToAdmins(COLOR_ADMINstring);
                        
PlayerInfo[playerid][pWarnTime] = 720;
                        }
                        }
                        }
                    }
                    
Bit_Vetg_abThisBitchDidntReloadplayerid );
                }
            }
            
g_cPreviousWeaponplayerid } = s_iWeapon;
        }
        if ( 
s_iWeapon == WEAPON_SAWEDOFF )
        {
            if ( 
g_iSawnoffAmmoplayerid ] == -)
                
g_iSawnoffAmmoplayerid ] = GetPlayerAmmoplayerid );
            else
            {
                if ( 
GetPlayerWeaponStateplayerid ) == WEAPONSTATE_RELOADING )
                {
                    if ( 
Bit_Getg_abIsSawnoffClipUsedplayerid ) )
                        
Bit_Vetg_abIsSawnoffClipUsedplayerid );
                }
                else
                {
                    if ( 
g_iSawnoffAmmoplayerid ] != s_iAmmo )
                    {
                        if ( 
s_iAmmo g_iSawnoffAmmoplayerid ] )
                        {
                            
Bit_Letg_abIsSawnoffClipUsedplayerid );
                            
g_cFiredShotsplayerid } += g_iSawnoffAmmoplayerid ] - s_iAmmo;
                        }
                        else
                        {
                            
g_cFiredShotsplayerid } = 0;
                            
Bit_Vetg_abIsSawnoffClipUsedplayerid );
                        }
                        
g_iSawnoffAmmoplayerid ] = s_iAmmo;
                    }
                }
            }
        }
        else if ( 
g_iSawnoffAmmoplayerid ] != -|| Bit_Getg_abIsSawnoffClipUsedplayerid ) )
        {
            
g_iSawnoffAmmoplayerid ] = -1;
            
Bit_Vetg_abIsSawnoffClipUsedplayerid );
            
g_cFiredShotsplayerid } = 0;
        }
    }
    else if ( 
g_iSawnoffAmmoplayerid ] != -|| Bit_Getg_abIsSawnoffClipUsedplayerid ) )
    {
        
g_iSawnoffAmmoplayerid ] = -1;
        
Bit_Vetg_abIsSawnoffClipUsedplayerid );
        
g_cFiredShotsplayerid } = 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?
Reply
#2

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.
Reply
#3

i'll check this out, thanks.
Reply
#4

I made this script using callback OnPlayerWeaponShot, link: https://sampforum.blast.hk/showthread.php?pid=3034954#pid3034954
Reply
#5

Thanks banana_ghost, that worked. + REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)