Raised This Month: $32 Target: $400
 8% 

Awp plugin [ help me ]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dannythescripter
Junior Member
Join Date: Aug 2016
Old 08-18-2016 , 06:57   Awp plugin [ help me ]
Reply With Quote #1

Hello,

I want to apologize in advance for possible grammar mistakes in this text, it is because I am not from an natively English speaking country and I am still learning English at school.

I recently downloaded a script that restricts the AWP for teams, I wanted to edit it a little bit according to my needs, but error occurred.

When we went on the server with friend of mine to test the plugin, we had the same flags. The problem was, that we could not take the AWP from ground and my friend was not even enable to buy it (for me, buying worked).

Since I am really a big amateur in whole programming business, I will rather send you the whole script, which has just over 350 lines.

Code:
/*
 *
 * WillyumYum - Sniper Control
 * (c) 2004-2005
 *
 * Sniper Rifle Restriction
 * Based off of JustinHoMi's Awp Limit
 * and OLO's Awp Control.
 *
 * Special thanks to BAILOPAN
 * for some helpful 'flag' tips.
 *
 * Special thanks to AssKicR for
 * pointing out hardcoding issues
 *
 *
 */

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

#pragma semicolon                1      // force ; usage, just 'cause

#define INCLUDE_SCOUT            0      // Include scouts in sniper rifle

new g_szTitle[]   = "Sniper Rifle Control";
new g_szVersion[] = "1.2";
new g_szAuthor[]  = "WillyumYum";

new g_iSniperNum[1];                    // number of sniper rifles per team

new bool:g_bHasSniper[33];              // bool - true if player has a sniper rifle

new g_szWarn[]    = "Limit of sniper rifles in your team has been reached! Type /vip to buy an VIP, so you can by sniper rifle any time you want!";

new const SNIPERMODELS[4][] =
{
    #if ( INCLUDE_SCOUT )
    "models/w_scout.mdl",               // CSW_SCOUT
    #else
    "",
    #endif
    "models/w_sg550.mdl",               // CSW_SG550
    "models/w_awp.mdl",                 // CSW_AWP
    "models/w_g3sg1.mdl"                // CSW_G3SG1
};

// Map disabled - original code by Ryan

public bool:Map_Disabled() {

    new szDisabledFile[64];
    get_configsdir( szDisabledFile, 63 );
    format( szDisabledFile, 63, "%s/sc_disabled_maps.cfg", szDisabledFile );

    if ( file_exists( szDisabledFile ) )
    {
        new iLineNum, szData[64], iTextLen;

        while ( read_file( szDisabledFile, iLineNum, szData, 63, iTextLen ) )
        {
            new szMapName[64], szDisabledName[64];

            get_mapname( szMapName, 63 );
            new iLen = copyc( szDisabledName, 63, szData, '*' );

            if ( equali( szMapName, szDisabledName, iLen ) )
                return true;

            iLineNum++;
        }
    }

    return false;
}

public menuSniper( id, key ) 
{
	if (get_user_flags(id) & ADMIN_USER)
	{ 
		if ( !get_cvar_num( "mp_sniper_control" ) )
		return PLUGIN_CONTINUE;
		new iTeam = get_user_team( id );
		if ( iTeam == 1 && ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_t" ) || g_bHasSniper[id] ) )       // TERRORIST
		return PLUGIN_CONTINUE;
		else
		if ( iTeam == 2 && ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_ct" ) || g_bHasSniper[id] ) )       // COUNTER-TERRORIST
		return PLUGIN_CONTINUE;
		if( iTeam == 1 && key == 1 )  // Allows T's tp buy ak-47, but blocks CT's from buying scout
		return PLUGIN_CONTINUE;
		else
		if( iTeam == 2 && key == 2 )  // Allows CT's to buy m4, but blocks T's from buying scout
		return PLUGIN_CONTINUE;
		engclient_cmd( id, "menuselect" ,"10");
		client_print( id, print_center , g_szWarn );
	}
	return PLUGIN_HANDLED;
}

public bool:check_primary( id ) {

    new iWeapons[32];
    new iTotalWeapons = 0;
    get_user_weapons( id, iWeapons, iTotalWeapons );

    for ( new i = 0; i < iTotalWeapons; i++ )
    {
        switch ( iWeapons[i] )
        {
            case CSW_M3:      return true;
            case CSW_XM1014:  return true;
            case CSW_MP5NAVY: return true;
            case CSW_TMP:     return true;
            case CSW_P90:     return true;
            case CSW_MAC10:   return true;
            case CSW_UMP45:   return true;
            case CSW_AK47:    return true;
            case CSW_SG552:   return true;
            case CSW_GALI:    return true;
            case CSW_FAMAS:   return true;
            case CSW_M4A1:    return true;
            case CSW_AUG:     return true;
            case CSW_SCOUT:   return true;
            case CSW_AWP:     return true;
            case CSW_G3SG1:   return true;
            case CSW_SG550:   return true;
            case CSW_M249:    return true;
        }
    }
    return false;
}

public bool:check_sniper( id ) {

    new iWeapons[32];
    new iTotalWeapons = 0;
    get_user_weapons( id, iWeapons, iTotalWeapons );

    for ( new i = 0; i < iTotalWeapons; i++ )
    {
        switch ( iWeapons[i] )
        {
            #if ( INCLUDE_SCOUT )
            case CSW_SCOUT:   return true;
            #else
            case CSW_SCOUT:   return false;
            #endif

            case CSW_AWP:     return true;
            case CSW_G3SG1:   return true;
            case CSW_SG550:   return true;
        }
    }
    return false;
}

public vexd_pfntouch(pToucher, pTouched) 
{
	if (get_user_flags(pTouched) & ADMIN_USER)
	{
		if ( !get_cvar_num( "mp_sniper_control" ) )
		return PLUGIN_CONTINUE;

		new iTouchId   = pToucher;
		new iPlayerId  = pTouched;

		if ( iPlayerId < 0 || iPlayerId > 32 || !is_user_alive( iPlayerId ) )
		return PLUGIN_CONTINUE;

		new szClassName[32];
		entity_get_string( iTouchId, EV_SZ_classname, szClassName, 31 );

		if ( equal( szClassName, "weaponbox" ) )        // a dropped or already 'fired' weapon
		{
				new szGunModel[32];
				entity_get_string( iTouchId, EV_SZ_model, szGunModel, 31 );

				new bool:bHasPrimaryWeapon = check_primary( iPlayerId );

				for ( new i = 0; i < 4; i++ )
				{
					if ( get_entity_flags( iTouchId ) & FL_ONGROUND && !bHasPrimaryWeapon && equal( szGunModel, SNIPERMODELS[i] ) )
					{
						set_entity_flags( iTouchId, FL_ONGROUND, 0 );
						new iTeam = get_user_team( iPlayerId );
						if ( iTeam == 1 )   // TERRORIST
						{
							if ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_t" ) )
							{
								set_entity_flags( iTouchId, FL_ONGROUND, 1 );
							}
							else
							{
								client_print( iPlayerId, print_center , g_szWarn );
							}
						}
						else
						if ( iTeam == 2 )   // COUNTER-TERRORIST
						{
							if ( g_iSniperNum[iTeam] < get_cvar_num( "sc_max_snipers_ct" ) )
							{
								set_entity_flags( iTouchId, FL_ONGROUND, 1 );
							}
							else
							{
								client_print( iPlayerId, print_center , g_szWarn );
							}
						}
						break;
					}
				}
		}
	}
	return PLUGIN_CONTINUE;
}

public cmdDrop( id ) {

    if ( !get_cvar_num( "mp_sniper_control" ) )
        return PLUGIN_CONTINUE;

    new iTeam = get_user_team( id );

    new iAmmo, iClip;
    new iWeap = get_user_weapon( id, iAmmo, iClip );

    if ( check_sniper( id ) && ( iWeap == CSW_AWP || iWeap == CSW_G3SG1 || iWeap == CSW_SG550 ) )
    {
        g_bHasSniper[id] = false;
        --g_iSniperNum[iTeam];

    }
    #if ( INCLUDE_SCOUT )

    else
    if( check_sniper( id ) && iWeap == CSW_SCOUT  )
    {
        g_bHasSniper[id] = false;
        --g_iSniperNum[iTeam];
    }

    #endif

    return PLUGIN_CONTINUE;
}

public evPickUp( id ) {

    if ( !get_cvar_num( "mp_sniper_control" ) )
        return PLUGIN_CONTINUE;

    new iTeam = get_user_team( id );

    if( check_sniper( id ) && !g_bHasSniper[id] )
    {
        g_bHasSniper[id] = true;
        ++g_iSniperNum[iTeam];
    }

    if ( g_bHasSniper[id] && !check_sniper( id ) )
    {
        // Has a primary weapon and HAD sniper, but bought new non-sniper rifle weapon ( no drop event )

        g_bHasSniper[id] = false;
        --g_iSniperNum[iTeam];
    }

    return PLUGIN_CONTINUE;
}

public evRestartRound() {

    if ( !get_cvar_num( "mp_sniper_control" ) )
        return PLUGIN_CONTINUE;

    g_iSniperNum[0] = 0;

    for(new a = 1; a < 33; ++a)
        g_bHasSniper[a] = false;

    return PLUGIN_CONTINUE;
}

public sc_remove_data( id ) {

    new iTeam = get_user_team( id );

    if ( g_bHasSniper[id] )
    {
        g_bHasSniper[id] = false;
        --g_iSniperNum[iTeam];
    }

    return PLUGIN_CONTINUE;
}

public client_disconnect( id ) {

    if ( !get_cvar_num( "mp_sniper_control" ) )
        return PLUGIN_CONTINUE;

    sc_remove_data( id );

    return PLUGIN_CONTINUE;
}

public evDeath() {

    new id = read_data(2);
    sc_remove_data( id );

    return PLUGIN_CONTINUE;
}

public plugin_init() {

    register_plugin( g_szTitle, g_szVersion, g_szAuthor );

    // set defaults ( for non 'sniper_control.cfg' users )

    register_cvar( "mp_sniper_control", "1" );
    register_cvar( "sc_max_snipers_t",  "2" );
    register_cvar( "sc_max_snipers_ct", "2" );

    // Standard Menus

    register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<4), "menuSniper" );        //  T: AWP, CT: Sig SG-550 Sniper
    register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<5), "menuSniper" );        // CT: AWP,  T: H&K G3/SG-1 Sniper Rifle


	// Block Aliases and Vgui menus - because steam sucks and uses aliases to buy rifles ?!?!?

    register_clcmd("awp",      "menuSniper");
    register_clcmd("magnum",   "menuSniper");
    register_clcmd("g3sg1",    "menuSniper");
    register_clcmd("d3au1",    "menuSniper");
    register_clcmd("sg550",    "menuSniper");
    register_clcmd("krieg550", "menuSniper");

    register_menucmd( -31 ,(1<<4), "menuSniper" );                                     //  T: AWP, CT: Sig SG-550 Sniper        - VGUI
    register_menucmd( -31 ,(1<<5), "menuSniper" );                                     // CT: AWP,  T: H&K G3/SG-1 Sniper Rifle - VGUI

    #if ( INCLUDE_SCOUT )

    register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<1), "menuSniper" );        // CT: Scout - Standard
    register_menucmd( register_menuid("BuyRifle" , 1 ), (1<<2), "menuSniper" );        //  T: Scout - Standard

    register_clcmd("scout",    "menuSniper");

    register_menucmd( -31 ,(1<<1), "menuSniper" );                                     // CT: Scout - VGUI
    register_menucmd( -31 ,(1<<2), "menuSniper" );                                     //  T: Scout - VGUI

    #endif

    register_event( "WeapPickup", "evPickUp",       "b"                         );        // 3 = Scout, 13 = SG-550, 18 = AWP, G3/SG-1
    register_clcmd( "drop",       "cmdDrop"                                     );
    register_event( "DeathMsg",   "evDeath",        "a"                         );
    register_event( "TextMsg",    "evRestartRound", "a", "2&Game_C", "2&Game_w" );

    if ( !Map_Disabled() )
    {
        new szConfigFile[64];
        get_configsdir( szConfigFile, 63 );
        format( szConfigFile, 63, "%s/sniper_control.cfg", szConfigFile );
        server_cmd( "exec %s", szConfigFile );                                                // load configuration settings
    }
    else
    {
        set_cvar_num( "mp_sniper_control", 0 );
    }

    return PLUGIN_CONTINUE;
}
And yet I forgot, I would also ask you to check one condition, which occurs in the script several times. The point is, that this sniper restriction needs to work only for those who have not activated the VIP. It is on this condition:


Code:
if (get_user_flags(id) & ADMIN_USER)
My question is, if it is written right and if it is on the right spot each snippet of code.

Guys, I would be MORE than happy, it would mean the world to me, if one of you was enable to solve my problem.
dannythescripter is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-18-2016 , 07:02   Re: Awp plugin [ help me ]
Reply With Quote #2

You want only VIP could use sniper rifles?
siriusmd99 is offline
dannythescripter
Junior Member
Join Date: Aug 2016
Old 08-18-2016 , 08:32   Re: Awp plugin [ help me ]
Reply With Quote #3

No, no!

I think, that I have explained it, if not, let me explain it again:

I want, so that NORMAL PLAYERS, are restricted to 1 AWP per ONE TEAM, so if this limit is exceeded, normal players would not be enable to buy AWP anymore. And if the limit is not exceeded, for example one Terrorist has AWP but Counter Terrorist not, other CT is enable to buy ONE peace of AWP.

But. I do not want this to be a thing for VIP players, VIP players would have no limit what so ever.
dannythescripter is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-18-2016 , 08:39   Re: Awp plugin [ help me ]
Reply With Quote #4

And what is the flag which you use for VIP?
ADMIN LEVEL H? (flag "t")?
siriusmd99 is offline
dannythescripter
Junior Member
Join Date: Aug 2016
Old 08-18-2016 , 10:31   Re: Awp plugin [ help me ]
Reply With Quote #5

Yes.
dannythescripter is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-19-2016 , 08:04   Re: Awp plugin [ help me ]
Reply With Quote #6

Quote:
Originally Posted by dannythescripter View Post
Yes.
I can avoid this plugin because i see it's old and badly coded.
And i can make new plugin which will have only buy and awp. its ok?
siriusmd99 is offline
dannythescripter
Junior Member
Join Date: Aug 2016
Old 08-19-2016 , 10:49   Re: Awp plugin [ help me ]
Reply With Quote #7

Well, but I would need these features.

Quote:
I want, so that NORMAL PLAYERS, are restricted to 1 AWP per ONE TEAM, so if this limit is exceeded, normal players would not be enable to buy AWP anymore. And if the limit is not exceeded, for example one Terrorist has AWP but Counter Terrorist not, other CT is enable to buy ONE peace of AWP.

But. I do not want this to be a thing for VIP players, VIP players would have no limit what so ever.
dannythescripter is offline
dannythescripter
Junior Member
Join Date: Aug 2016
Old 08-23-2016 , 15:14   Re: Awp plugin [ help me ]
Reply With Quote #8

Is someone actually going to help me?
dannythescripter is offline
ish12321
Veteran Member
Join Date: May 2016
Old 08-24-2016 , 14:57   Re: Awp plugin [ help me ]
Reply With Quote #9

Check this outPLUGIN.sma

Last edited by ish12321; 08-24-2016 at 15:02.
ish12321 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:09.


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