AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Restrictweapon error (https://forums.alliedmods.net/showthread.php?t=133788)

smgcz 07-28-2010 21:13

Restrictweapon error
 
Hello everyone, I have a great script written by Bugsy for Counter Strike: Condition Zero. Unfortunately, real life has Bugsy busy and I was wondering if any one could figure out what is causing the plugin to not work properly.

The error is this:

The plugin will give a player a score of -3 when the bomb explodes, it should not do this. The player can only get to -1 regardless of how many kills they get. The plugin is supposed to ignore bomb points, either with an explosion or bomb defuse. The plugin does ignore bomb defuse points, but not bomb explosion points.

Point of the plugin in a nutshell:

At 16 kills you can use an smg or less. At 20 kills only a pistol, except a deagle.

Thus the plugin has to remember the score for the map only so the appropriate gun is used. Also, the score needs to be remember only for the map so players do not leave and come back to the server in hopes of resetting their score.

I have checked the error logs and other plugins to see if there is a problem with other plugins.....no errors found.

When I turn of the restrictweapon.amxx plugin bomb explosion points and bomb defuse points occur as they normally would.

Here is the code and any help is greatly appreciated!

Code:


#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <celltrie>

#define OFFSET_CSDEATHS        444
#define OFFSET_CSMONEY        115

new const Version[] = "1.4";

enum RestrictLevel
{
    LEVEL_NONE,
    LEVEL_1,
    LEVEL_2
}

new const g_LevelRestriction[RestrictLevel] =
{
    0,

    ( 1 << CSW_MP5NAVY) | ( 1 << CSW_TMP ) |
    ( 1 << CSW_P90 ) | ( 1 << CSW_MAC10 ) |
    ( 1 << CSW_UMP45 ) | ( 1 << CSW_USP ) |
    ( 1 << CSW_GLOCK18 ) | ( 1 << CSW_DEAGLE ) |
    ( 1 << CSW_ELITE ) | ( 1 << CSW_FIVESEVEN ) |
    ( 1 << CSW_P228 ) | ( 1 << CSW_M3 ) |
    ( 1 << CSW_XM1014 ) | ( 1 << CSW_HEGRENADE ) |
    ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) |
    ( 1 << CSW_C4 ),

    ( 1 << CSW_USP )    | ( 1 << CSW_GLOCK18 ) |
    ( 1 << CSW_ELITE ) | ( 1 << CSW_FIVESEVEN ) |
    ( 1 << CSW_P228 ) | ( 1 << CSW_HEGRENADE ) |
    ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) |
    ( 1 << CSW_C4 )
}

new HamHook: g_HamAddPlayerItem;
new g_FMTouch;
new g_Restriction[33];
new iSaid[33];
new g_szAuthID[33][35];
new g_iFrags[33];
new g_iDeaths[33];
new g_iBot[33];
new g_TouchNotify[33];
new Float: g_fMsgDelay[33];
new g_Defusing;
new g_Planting;
new g_MaxPlayers;
new g_Enabled;
new g_MsgScoreInfo;
new g_MsgMoney
;
new Trie:g_iTrie;

#define WEAPONS    29
new const WEAPON_PRIORITY[WEAPONS] = {3, 5, 7, 8, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 27, 28, 30, 1, 10, 11, 16, 17, 26, 6, 4, 9, 25, 29};

new const g_WeaponPrice[33] =
{
    0,   
    600,
    0, 
    2750,
    300, 
    3000,
    0,
    1400,
    3500,
    300,
    1000, 
    750,
    1700,
    4200,
    2000,
    2250,
    500,
    400,
    4750,
    1500,
    5750,
    1700,
    3100,
    1250,
    5000,
    200,   
    650, 
    3500,
    2500,
    0,   
    2350,
    0,   
    0
};

new const g_WeaponNames[33][] =
{
    "",
    "p228",
    "",
    "scout",
    "hegrenade",
    "xm1014",
    "backpack",
    "mac10",
    "aug",
    "smokegrenade",
    "elite",
    "fiveseven",
    "ump45",
    "sg550",
    "galil",
    "famas",
    "usp",
    "glock18",
    "awp",
    "mp5",
    "m249",
    "m3",
    "m4a1",
    "tmp",
    "g3sg1",
    "flashbang",
    "deagle",
    "sg552",
    "ak47",
    "",
    "p90",
    "",
    ""
};

#define fm_set_user_frags(%1,%2)    set_pev(%1,pev_frags,float(%2))

public plugin_init()
{
    register_plugin( "Weapon Restrict" , Version , "bugsy" );

    register_logevent( "fwRoundStart" , 2 , "1=Round_Start" );
    register_event( "DeathMsg" , "fwDeathMsg" , "a" ); 
    register_event( "ScoreInfo" , "fwEvScoreInfo" , "a" );
   
    g_MsgScoreInfo = get_user_msgid ( "ScoreInfo" );
    g_MsgMoney = get_user_msgid( "Money" );
   
    g_MaxPlayers = get_maxplayers();
   
    //Enable our ham and fakemeta forwards to handle weapon pickup and purchasing of restricted weapons.
    EnablePlugin( 1 );

    //Check if map has bomb site, if so we enable bomb events
    if ( engfunc( EngFunc_FindEntityByString , -1 , "classname" , "func_bomb_target" ) )
    {
        // Bomb planting started event
        register_event( "BarTime" , "BombPlantStart" , "be" , "1=3" );
       
        // Bomb defusion started event
        register_event( "BarTime" , "BombDefuseStart" , "be" , "1=5" , "1=10" );

        // Bomb defused event
        register_logevent( "BombDefused" , 3 , "2=Defused_The_Bomb" );
       
        // Bomb exploded event
        register_logevent( "BombExploded" , 6 , "2=triggered" ,"1=TERRORIST" , "3=Target_Bombed" );
       
        // Bomb planting/defusion canceled event
        register_event( "BarTime" , "PlantDefuseCancelled" , "b" , "1=0" );
    }
}

public plugin_cfg()
{
    g_iTrie = TrieCreate();
   
    if ( g_iTrie == Invalid_Trie )
        set_fail_state( "Error creating Trie" );
}
   
public plugin_end()
{
    TrieDestroy( g_iTrie );
}

public client_putinserver(id)
{
    g_iBot[id] = is_user_bot(id);
   
    if ( g_Enabled && g_iBot[id] )
        EnablePlugin( 0 );

    if ( !g_iBot[id] )
    {
        static szSave[10];
        get_user_authid( id , g_szAuthID[id] , 34 );
   
        if ( TrieGetString( g_iTrie , g_szAuthID[id] , szSave , 9 ) )
        {
            new iSep = contain( szSave , ":" );
       
            if ( iSep > -1 )
            {
                g_iDeaths[id] = str_to_num( szSave[iSep+1] );
                szSave[iSep] = EOS;
                g_iFrags[id] = str_to_num( szSave );
            }
        } 
    }
}

public client_disconnect(id)
{
    g_Restriction[ id ] = 0;

    if ( g_iBot[id] )
    {
        for ( new i = 1 ; i <= g_MaxPlayers ; i++ )
            if ( ( i != id ) && is_user_connected( i ) && g_iBot[i] )
                return PLUGIN_CONTINUE;
   
        EnablePlugin( 1 );
    }
    else
    {
        if ( g_iFrags[id] || g_iDeaths[id] )
        {
            new szSave[10];
            formatex( szSave , 9 , "%d:%d" , g_iFrags[id] , g_iDeaths[id] );
           
            TrieSetString( g_iTrie , g_szAuthID[ id ] , szSave );
        }
    }
   
    return PLUGIN_CONTINUE;
}

EnablePlugin( iEnableVal )
{
    g_Enabled = iEnableVal;
   
    switch ( iEnableVal )
    {
        case 0:
        {
            DisableHamForward( g_HamAddPlayerItem );
            unregister_forward( FM_Touch , g_FMTouch );
        }
        case 1:
        {
            g_HamAddPlayerItem = RegisterHam( Ham_AddPlayerItem ,"player" ,"fw_AddPlayerItem" );
            g_FMTouch = register_forward( FM_Touch, "fw_Touch" );
        }
    }
}

public fwDeathMsg()
{
    if ( g_Enabled )
    {   
        new iKiller = read_data(1);
        new iVictim = read_data(2);
       
        //Suicide
        if ( iKiller == iVictim )
            fm_set_user_deaths( iKiller , get_user_deaths( iKiller ) - 1 );
       
        //TK
        if ( get_user_team( iKiller ) == get_user_team( iVictim ) )
            fm_set_user_frags( iKiller , get_user_frags( iKiller ) + 1 );   
    }       
}

public GetWeaponIndex(szPartial[], iType)
{
    //Type1: Entire weapon name entered as param, check if g_WeaponNames is within
    //Type2: Partial weapon entered as param, check if found within g_WeaponNames
    if ( iType == 1 )
    {
        for( new i = 1 ; i < 33 ; i++ )
            if ( containi( szPartial , g_WeaponNames[i] ) != -1 )
                return i;
    }
    else
    {
        for( new i = 1 ; i < 33 ; i++ )
            if ( containi( g_WeaponNames[i] , szPartial ) != -1 )
                return i;   
    }
   
    return 0;
}

public CheckCurrentWeapons( id )
{
    static iWeapons[32];
    static iWeaponNum;
    static szWeapon[33];
   
    get_user_weapons( id , iWeapons , iWeaponNum );
   
    new iCurrent = get_user_weapon(id);
   
    for ( new i = 0 ; i < 32 ; i++ )
    {
        new iWeap = iWeapons[i];

        if ( !( 1 & ( g_Restriction[id] >> iWeap ) ) && user_has_weapon( id , iWeap ) )   
        {
            get_weaponname( iWeap , szWeapon , 32 );
            engclient_cmd( id , "drop" , szWeapon );

            //If player was holding restricted weapon, set weapon according to priority
            if ( iCurrent == iWeap )
                SetWeaponPriority( id );
        }
    }
}

public SetWeaponPriority(id)
{
    for ( new j = 0 ; j < WEAPONS ; ++j )
    {
        if ( user_has_weapon( id , WEAPON_PRIORITY[j] ) )
        {
            new wname[20] ;
            get_weaponname( WEAPON_PRIORITY[j] , wname , 19 ) ;
            engclient_cmd( id , wname );
            break;
        }
    }
}

public PrintMsg( id , szMessage[] )
{
    new Float:fGameTime = get_gametime();
   
    if ( (fGameTime >= g_fMsgDelay[id]) || (iSaid[id] <= 3) )
    {
        if ( fGameTime >= g_fMsgDelay[id] )
            iSaid[id] = 0;
           
        client_print( id , print_chat , "%s" , szMessage );
        iSaid[id]++;
       
        g_fMsgDelay[id] = fGameTime + 1.0;
    }
}

public ReimburseMoney( param[2] )
{
    new id = param[0];
    new iMoney = param[1];
    fm_set_user_money( id , clamp( ( get_pdata_int(id, OFFSET_CSMONEY) + iMoney ) , 0 , 16000 ) , 1 );
}

//Block weapon from being purchased and reimburse players money.
public fw_AddPlayerItem( iPlayer , iItem )
{
    if ( !g_Enabled || !g_Restriction[iPlayer])
        return HAM_IGNORED;

    static szClassname[32];
    pev( iItem , pev_classname , szClassname , 31 );
   
    new iWeaponIndex = GetWeaponIndex( szClassname , 1 );

    if( !iWeaponIndex )
        return HAM_IGNORED;
   
    if ( !( 1 & ( g_Restriction[iPlayer] >> iWeaponIndex ) ) )
    {   
        static szMsg[99];
        new iParam[2];
       
        iParam[0] = iPlayer;
        iParam[1] = g_WeaponPrice[iWeaponIndex];
        set_task( 0.15 , "ReimburseMoney" , _ , iParam , 2 );
       
        formatex( szMsg , 98 , "* The rules are use an smg at 16 kills & a pistol (no deagle) at 20 kills." );
        PrintMsg( iPlayer , szMsg );
       
        SetHamReturnInteger( 1 );
        return HAM_SUPERCEDE;
    }
   
    return HAM_IGNORED;
}

//Block weapon pickup when walked over. (When weapon has been dropped by a player)
public fw_Touch( iEnt , iPlayer )
{
    if ( !g_Enabled || !( 1 <= iPlayer <= g_MaxPlayers ) || !g_Restriction[iPlayer] || !pev_valid(iEnt ) || !( pev( iEnt , pev_flags ) & FL_ONGROUND ) )
        return FMRES_IGNORED;
       
    static szEntModel[32];
    static iWeaponIndex;
   
    pev( iEnt , pev_model , szEntModel , 31 );
    iWeaponIndex = GetWeaponIndex( szEntModel , 1 );
   
    if ( !( 1 & ( g_Restriction[ iPlayer ] >> iWeaponIndex ) ) )
    {       
        if ( g_TouchNotify[ iPlayer ] != iWeaponIndex )
        {
            client_print( iPlayer , print_chat , "* Your kills restrict you from this weapon this map, please use an smg at 16 kills & a pistol (no deagle) at 20 kills" );
            g_TouchNotify[ iPlayer ] = iWeaponIndex;
        }
       
        return FMRES_SUPERCEDE;
    }

    return FMRES_IGNORED;
}

public fwEvScoreInfo()
{
    if ( !g_Enabled )
        return PLUGIN_CONTINUE;
   
    new id = read_data( 1 );
    new iFrags = read_data( 2 );
    new iDeaths = read_data( 3 );
   
    //The server resets scores at mapchange so this will set the players score [if g_iFrags[] > 0].
    if ( is_user_connected( id ) && ( ( !iFrags && g_iFrags[ id ] ) || ( !iDeaths && g_iDeaths[ id ] ) ) )
    {
        fm_set_user_frags( id , g_iFrags[ id ] );
        fm_set_user_deaths( id , g_iDeaths[ id ] );
        return PLUGIN_CONTINUE;
    }
   
    g_iFrags[ id ] = iFrags;
    g_iDeaths[ id ] = iDeaths;
   
    return PLUGIN_CONTINUE;


public fwRoundStart()
{
    if ( !g_Enabled )
        return PLUGIN_CONTINUE;

    new iFrags;
    for ( new i = 1 ; i <= g_MaxPlayers ; i++ )
    {
        if ( is_user_connected(i) )
        {
            g_TouchNotify[i] = 0;
            iFrags = get_user_frags( i );

            if ( iFrags >= 20 )
            {
                g_Restriction[ i ] = g_LevelRestriction[ LEVEL_2 ];
                CheckCurrentWeapons( i );
            }
            else if ( iFrags >= 16 )
            {
                g_Restriction[ i ] = g_LevelRestriction[ LEVEL_1 ];
                CheckCurrentWeapons( i );
            }
        }
    }

    g_Defusing = 0;
    g_Planting = 0;
   
    return PLUGIN_CONTINUE;
}

public BombPlantStart(id)
{
    g_Planting = id;
}

public BombDefuseStart(id)
{
    g_Defusing = id;
}

public BombDefused()
{
    if ( g_Enabled )
        fm_set_user_frags( g_Defusing , get_user_frags( g_Defusing ) - 3 );
}

public BombExploded()
{   
    if ( g_Enabled )   
        fm_set_user_frags( g_Planting , get_user_frags( g_Defusing ) - 3 );
}

public PlantDefuseCancelled(id)
{
    if ( id == g_Defusing )
        g_Defusing = 0;
   
    if ( id == g_Planting )
        g_Planting = 0;
}

public fm_set_user_deaths(  id , i_NewDeaths )
{
    set_pdata_int ( id , OFFSET_CSDEATHS , i_NewDeaths );
   
    message_begin ( MSG_ALL, g_MsgScoreInfo );
    write_byte ( id );
    write_short ( get_user_frags ( id ) );
    write_short ( i_NewDeaths );
    write_short ( 0 );
    write_short ( get_user_team ( id ) );
    message_end ();
}

public fm_set_user_money(index, money, flash)
{
    set_pdata_int( index , OFFSET_CSMONEY , money );
   
    message_begin( MSG_ONE_UNRELIABLE , g_MsgMoney , _ , index );
    write_long( money );
    write_byte( flash ? 1 : 0 );
    message_end();
}


smgcz 07-28-2010 21:16

Re: Restrictweapon error
 
here are the plugins I am currently running:

Code:

; AMX Mod X plugins

; Admin Base - Always one has to be activated
admin.amxx        ; admin base (required for any admin-related)
;admin_sql.amxx        ; admin base - SQL version (comment admin.amxx)

; Basic
admincmd.amxx        ; basic admin console commands
adminhelp.amxx        ; help command for admin console commands
;adminslots.amxx        ; slot reservation
;multilingual.amxx    ; Multi-Lingual management

; Menus
menufront.amxx        ; front-end for admin menus
cmdmenu.amxx        ; command menu (speech, settings)
plmenu.amxx        ; players menu (kick, ban, client cmds.)
;telemenu.amxx        ; teleport menu (Fun Module required!)
mapsmenu.amxx        ; maps menu (vote, changelevel)
pluginmenu.amxx        ; Menus for commands/cvars organized by plugin

; Chat / Messages
adminchat.amxx        ; console chat commands
antiflood.amxx        ; prevent clients from chat-flooding the server
scrollmsg.amxx        ; displays a scrolling message
imessage.amxx        ; displays information messages
adminvote.amxx        ; vote commands

; Map related
nextmap.amxx        ; displays next map in mapcycle
;mapchooser.amxx        ; allows to vote for next map
timeleft.amxx        ; displays time left on map

; Configuration
pausecfg.amxx        ; allows to pause and unpause some plugins
statscfg.amxx        ; allows to manage stats plugins via menu and commands

; Enable to use AMX Mod plugins
;amxmod_compat.amxx    ; AMX Mod backwards compatibility layer


; Custom - Add 3rd party plugins here
restmenu.amxx        ; restrict weapons menu (added 2/10/10)
statsx.amxx        ; stats on death or round end (CSX Module required!)  (added 2/10/10)
miscstats.amxx        ; bunch of events announcement for Counter-Strike  (added 2/10/10)
stats_logging.amxx    ; weapons stats logging (CSX Module required!)  (added 2/10/10)
restrictweapons.amxx
admin_spec_esp.amxx    ;(added 2/10/10)
amx_bank.amxx        ;(added 2/10/10)
amx_gore_ultimate.amxx    ;(added 2/11/10)
adminlisten.amxx        ;(added 2/27/10)
teamflash_punish.amxx    ;(added 4/21/10)
ptb.amxx            ;(added 4/22/10)
amx_deagle5_knife.amxx    ;(added 6/2/10)
amx_adminvoice.amxx    ;(added 6/8/10)
mirror_damage.amxx    ;(added 6/24/10)
amx_chicken.amxx        ;(added 6/24/10)
roll_the_dice.amxx        ;(added 6/24/10)


Bugsy 07-28-2010 21:24

Re: Restrictweapon error
 
I didn't mean to leave you hanging, I will fix it for you.

smgcz 07-28-2010 22:13

Re: Restrictweapon error
 
Bugsy!! Your back! Woot! I wondered what happened to you! I know you had some real life things going on, but was not sure where you were. Glad to see back on the forums. :)

Bugsy 07-28-2010 22:21

Re: Restrictweapon error
 
Yea, I got married and had a nice long honeymoon in St Lucia. Im back to my daily grind, though.

Bugsy 07-28-2010 23:35

Re: Restrictweapon error
 
I just tested the plugin using regular CS 1.6 and it worked fine for me; I don't have CZ to test with. There may be an issue with hooking the bomb explode event on CZ.

Just a shot in the dark here but try replacing
PHP Code:

register_logevent"BombExploded" "2=triggered" ,"1=TERRORIST" "3=Target_Bombed" ); 

with
PHP Code:

register_event("23""BombExploded""a""1=17""6=-105""7=17"

From here: http://forums.alliedmods.net/showthread.php?t=40164

smgcz 07-29-2010 00:41

Re: Restrictweapon error
 
thank you Bugsy, I will try it out and let u know. :)

smgcz 07-29-2010 00:47

Re: Restrictweapon error
 
i put this in with the code ; i didnt see it in ur post but i assume it has to be there

Code:

register_event("23", "BombExploded", "a", "1=17", "6=-105", "7=17");

smgcz 07-29-2010 01:05

Re: Restrictweapon error
 
I made the changes you said and here is what happens.

When a player has 16 kills and the bomb explodes there score goes to -3

When a player has less than 16 kills there score goes up by 3 points.

Code:

{
        // Bomb planting started event
        register_event( "BarTime" , "BombPlantStart" , "be" , "1=3" );
       
        // Bomb defusion started event
        register_event( "BarTime" , "BombDefuseStart" , "be" , "1=5" , "1=10" );

        // Bomb defused event
        register_logevent( "BombDefused" , 3 , "2=Defused_The_Bomb" );
       
        // Bomb exploded event
        register_event("23", "BombExploded", "a", "1=17", "6=-105", "7=17");
       
        // Bomb planting/defusion canceled event
        register_event( "BarTime" , "PlantDefuseCancelled" , "b" , "1=0" );
    }

If u need a cz login bugsy let me know, I can send you one.

Bugsy 07-29-2010 08:50

Re: Restrictweapon error
 
I just noticed something that is likely the cause (if you've been using the above code). I checked the original copy I wrote in the other thread and the code is correct but in the one you posted above it is wrong.

http://forums.alliedmods.net/showpos...4&postcount=21

Replace
PHP Code:

public BombExploded()
{    
    
//Notice it is setting frags to the plant player with the defuser player (which doesn't exist) frags - 3.
    
if ( g_Enabled )    
        
fm_set_user_fragsg_Planting get_user_fragsg_Defusing ) - );


with
PHP Code:

public BombExploded()
{    
    if ( 
g_Enabled )    
        
fm_set_user_fragsg_Planting get_user_fragsg_Planting ) - );




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

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