AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Improve anti fast fire method and optimize ? (https://forums.alliedmods.net/showthread.php?t=221711)

faki 07-25-2013 10:37

here is some edits of original anti fire plugin:
Code:

#include <amxmodx>
#include <hamsandwich>
#include <amxmisc>
#include <engine>

#define PLUGIN "Anti FastFire"
#define VERSION "1.2"
#define AUTHOR "Darksnow"

new bool:g_IsAlive[ 33 ]

#define MAX_PLAYERS 32

new countBullets[MAX_PLAYERS+1]
new g_nCurWeapon[MAX_PLAYERS][2]
new g_MaxPlayers

new g_Classname1[] = "fastfire"

new cvar_af_active, cvar_af_max;

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_event( "CurWeapon", "Event_ShotFired",  "b" )
        cvar_af_active = register_cvar("amx_af","1")
        cvar_af_max = register_cvar("amx_af_max","16")

        RegisterHam(Ham_Spawn, "player", "spawn_player", 1)

        //fast fire task
        new Ent = create_entity("info_target")
        entity_set_string(Ent,EV_SZ_classname,g_Classname1)
        entity_set_float(Ent,EV_FL_nextthink,1.0)
        register_think(g_Classname1,"checkBulletCount")
        //end
}

public client_connect(id)
{
g_IsAlive[ id ] = false
}

public spawn_player(id)
{
if(is_user_alive(id))
{
g_IsAlive[id] = true
}
}

public Event_ShotFired( id )
{
        new weaponID = read_data( 2 )
        new wAmmo = read_data( 3 )

        g_MaxPlayers = get_maxplayers()
       
        if( g_nCurWeapon[id-1][0] != weaponID ) // User Changed Weapons..
        {
                g_nCurWeapon[id-1][0] = weaponID
                g_nCurWeapon[id-1][1] = wAmmo
                return PLUGIN_CONTINUE
        }
        if( g_nCurWeapon[id-1][1] < wAmmo ) // User Reloaded..
        {
                g_nCurWeapon[id-1][1] = wAmmo
                return PLUGIN_CONTINUE
        }
        if( g_nCurWeapon[id-1][1] == wAmmo ) // User did something else, but didn't shoot..
                return PLUGIN_CONTINUE
        g_nCurWeapon[id-1][1] = wAmmo
        g_nCurWeapon[id-1][0] = weaponID

        countBullets[id]++ //Counting the bullets, one by one, all day long :)

        return PLUGIN_CONTINUE


public checkBulletCount(Ent)
{
        if (get_pcvar_num(cvar_af_active) == 1)
        {
                for(new id=1;id<=g_MaxPlayers;id++)
                {
                        if(g_IsAlive[id])
                        {
                                if (countBullets[id] > get_pcvar_num(cvar_af_max))
                                {
                                        new Name[32], szIP[40];
                                        get_user_name(id,Name,31)
                                        get_user_ip ( id, szIP, charsmax(szIP) , 1 );
                                        client_print(id, print_chat,"[Anti FastFire] %s using FastFire type of cheat",Name)
                                        server_cmd("amx_ban ^"500^" ^"%s^" ^"Banned for cheating^"", szIP)
                                       
                                }
                        }
                        countBullets[id] = 0
                }
        }
        entity_set_float(Ent,EV_FL_nextthink,1.0)
}

Tell me how ot improve detection for fast fire and how more optimize the code.

Please, someone redit this code to works with Ham_Weapon_PrimaryAttack from register_event( "CurWeapon", "Event_ShotFired", "b" )
.

faki 07-25-2013 13:45

Re: Improve anti fast fire method and optimize ?
 
I do it by myself but i have question, here is the code:
Quote:

#include <amxmodx>
#include <hamsandwich>
#include <amxmisc>
#include <engine>

#define PLUGIN "Anti FastFire"
#define VERSION "1.2"
#define AUTHOR "Darksnow"

new bool:g_IsAlive[ 33 ]

#define MAX_PLAYERS 32

new countBullets[MAX_PLAYERS+1]
new g_nCurWeapon[MAX_PLAYERS][2]
new g_MaxPlayers

new g_Classname1[] = "fastfire"

new cvar_af_active, cvar_af_max;

public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)

cvar_af_active = register_cvar("amx_af","1")
cvar_af_max = register_cvar("amx_af_max","16")

RegisterHam(Ham_Spawn, "player", "spawn_player", 1)


new const weaponIdentifiers[][] =
{
"weapon_glock18",
"weapon_elite",
"weapon_p228",
"weapon_usp",
"weapon_deagle",
"weapon_fiveseven",
"weapon_m3",
"weapon_xm1014",
"weapon_mp5navy",
"weapon_tmp",
"weapon_p90",
"weapon_mac10",
"weapon_ump45",
"weapon_famas",
"weapon_sg552",
"weapon_ak47",
"weapon_m4a1",
"weapon_aug",
"weapon_scout",
"weapon_awp",
"weapon_g3sg1",
"weapon_sg550",
"weapon_galil",
"weapon_m249"
}

for( new i = 0; i < sizeof weaponIdentifiers; i++ )
{
RegisterHam( Ham_Weapon_PrimaryAttack, weaponIdentifiers[ i ], "Weps_PrimaryAttack_Pre", false );
}

//fast fire task
new Ent = create_entity("info_target")
entity_set_string(Ent,EV_SZ_classname,g_Class name1)
entity_set_float(Ent,EV_FL_nextthink,1.0)
register_think(g_Classname1,"checkBulletCount ")
//end

g_MaxPlayers = get_maxplayers();
}

public client_connect(id)
{
g_IsAlive[ id ] = false
}

public spawn_player(id)
{
if(is_user_alive(id))
{
g_IsAlive[id] = true
}
}

public Weps_PrimaryAttack_Pre( const weapon )
{

new weaponID = read_data( 2 )
new wAmmo = read_data( 3 )

for(new id=1;id<=g_MaxPlayers;id++) {


if( g_nCurWeapon[id-1][0] != weaponID ) // User Changed Weapons..
{
g_nCurWeapon[id-1][0] = weaponID
g_nCurWeapon[id-1][1] = wAmmo
return PLUGIN_CONTINUE
}
if( g_nCurWeapon[id-1][1] < wAmmo ) // User Reloaded..
{
g_nCurWeapon[id-1][1] = wAmmo
return PLUGIN_CONTINUE
}
if( g_nCurWeapon[id-1][1] == wAmmo ) // User did something else, but didn't shoot..
return PLUGIN_CONTINUE
g_nCurWeapon[id-1][1] = wAmmo
g_nCurWeapon[id-1][0] = weaponID

countBullets[id]++ //Counting the bullets, one by one, all day long :)
}
return PLUGIN_CONTINUE

}

public checkBulletCount(Ent)
{
if (get_pcvar_num(cvar_af_active) == 1)
{
for(new id=1;id<=g_MaxPlayers;id++)
{
if(g_IsAlive[id])
{
if (countBullets[id] > get_pcvar_num(cvar_af_max))
{
new Name[32], szIP[40];
get_user_name(id,Name,31)
get_user_ip ( id, szIP, charsmax(szIP) , 1 );
client_print(id, print_chat,"[Anti FastFire] %s using FastFire type of cheat",Name)
server_cmd("amx_ban ^"500^" ^"%s^" ^"Banned for cheating^"", szIP)

}
}
countBullets[id] = 0
}
}
entity_set_float(Ent,EV_FL_nextthink,1.0)
}
in the bold text i have marked some code, do this code need some corrections or optimizations ?

avril-lavigne 07-25-2013 17:23

Re: Improve anti fast fire method and optimize ?
 
look at VEN`s toturial how to catch shot event


All times are GMT -4. The time now is 06:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.