SA-MP Forums Archive
[FilterScript] Anti-2shot - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] Anti-2shot (/showthread.php?tid=186926)



Anti-2shot - Slice - 31.10.2010

hey,
This will effectively freeze any player that doesn't shoot the whole sawnoff clip. No silly timers or simple methods.
The player that gets punished will get froze, in milliseconds, whatever FREEZE_TIME is set to; however, the player will still take damage.

Needs y_bit.inc from YSI.

pawn Код:
#include <a_samp>
#include <YSI/y_bit.inc>

#define FREEZE_TIME       (650) // The time a player will get froze after evading reload and switching back.
#define PUNISH_THRESOLD  (2500) // If the player doesn't switch back the weapon in <PUNISH_THRESOLD> ms, ignore it.
#define iPlayer  playerid

#pragma tabsize 0

new
    BitArray:g_abIsSawnoffClipUsed< MAX_PLAYERS >,
    BitArray:g_abThisBitchDidntReload< MAX_PLAYERS >,
             g_iReloadEvadeTime[ MAX_PLAYERS ],
             g_iSawnoffAmmo[ MAX_PLAYERS ],
             g_cFiredShots[ MAX_PLAYERS char ],
             g_cPreviousWeapon[ MAX_PLAYERS char ]
;

public OnPlayerSpawn( iPlayer )
{
    g_iSawnoffAmmo[ iPlayer ] = -1;
    g_cFiredShots{ iPlayer } = 0;
    g_cPreviousWeapon{ iPlayer } = 0;
   
    Bit_Vet( g_abIsSawnoffClipUsed, iPlayer );
    Bit_Vet( g_abThisBitchDidntReload, iPlayer );
}

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 )
                        {
                            ClearAnimations( iPlayer, 1 );
                           
                            ApplyAnimation( playerid, "PED", "XPRESSscratch", 0.0, 1, 0, 0, 0, FREEZE_TIME, 1 );
                        }
                    }
                   
                    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;
}



Re: Anti-2shot - Hiddos - 31.10.2010

Uhh yeah, I completely understood that code .

Might try and use this hehe


Re: Anti-2shot - Slice - 31.10.2010

Quote:
Originally Posted by Hiddos
Посмотреть сообщение
Uhh yeah, I completely understood that code .

Might try and use this hehe
Please do so! I've made some simple tests to see if players are trying to abuse the animation being set.


Re: Anti-2shot - HyperZ - 31.10.2010

Great job.


Re: Anti-2shot - MrDeath537 - 31.10.2010

Good job Slice .

You're a nice scripter!


Re: Anti-2shot - Mauzen - 01.11.2010

Nice idea, simple implementation.
This is another great example of a well-written piece of code, short but with a great function.
I like your script, keep on


Re: Anti-2shot - iJets - 01.11.2010

already tested it its good


Re: Anti-2shot - MyLife - 01.11.2010

I can't load YSI inc.


Re: Anti-2shot - Slice - 01.11.2010

Quote:
Originally Posted by MyLife
Посмотреть сообщение
I can't load YSI inc.
Download YSI and put it in your "include" folder.

http://www.y-less.com/YSI/YSI_1.0.zip


Re: Anti-2shot - MyLife - 01.11.2010

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Download YSI and put it in your "include" folder.

http://www.y-less.com/YSI/YSI_1.0.zip
Thank you.