|
Member
|

09-01-2010
, 21:59
Re: Restrictweapon error
|
#3
|
that change seems to have fixed the -1 error. Thanks Bugsy
One last question is there a way to set the message you get to only show up once per weapon or per second. When you have 16 kills or more the message pops up "* Your kills restrict you from this weapon this map, please use an smg at 16 kills & a pistol (no deagle) at 20 kills" ).
What happens is a player gets 16 or more kills and stands on a restricted weapon, like an M4 or ak47. Then, it floods their screen and then they get kicked for "reliable channel overflow" Is there a way to make the message only show once every second or once per weapon?
let me know.
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_event("23", "BombExploded", "a", "1=17", "6=-105", "7=17");
// 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_Planting ) - 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();
}
|
|