[code=php]
/*
Changelog:
2.2 - added the restriction system for players
2.1 - temporary solution for % and ;
2.0 - new random system
- code optimization
1.0 - first release
*/
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#define PLUGIN_NAME "Fast typing event"
#define PLUGIN_AUTHOR "floatman"
#define PLUGIN_VERSION "2.2"
#define FLAGS 9
// Timpul cat sa tina mesajul
#define HOLD_TIME 10.0 // 10 secunde
new g_Codename[ 20 ];
new g_On = 0;
new g_Time, g_Prize, g_RepTime;
new const g_Filename[] = "fastev_restrictedusers.ini";
new g_File[ 256 ];
new MsgSync;
public plugin_init()
{
register_plugin( PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR );
register_clcmd( "say", "cmdentered" );
register_clcmd( "say_team", "cmdentered" );
register_concmd( "amx_fevrestrict", "cmdRestrict", ADMIN_BAN, " < name > - restricts a player from taking part of the event." );
register_concmd( "amx_fevunrestrict", "cmdUnRestrict", ADMIN_BAN, " < name > - deleting the restriction of a player." );
register_dictionary( "fastevent.txt" );
register_cvar( "fevent_version", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY );
set_cvar_string( "fevent_version", PLUGIN_VERSION );
g_Time = register_cvar( "fastev_responsetime", "12.0" );
g_Prize = register_cvar( "fastev_moneyprize", "5000" );
g_RepTime = register_cvar( "fastev_repeattime", "120.0" );
MsgSync = CreateHudSyncObj ( );
}
public plugin_cfg()
{
set_task( get_pcvar_float( g_RepTime ), "create", _, _, _, "b" );
get_configsdir( g_File, charsmax( g_File ) );
formatex( g_File, charsmax( g_File ), "%s/%s", g_File, g_Filename );
if( !file_exists( g_File ) )
write_file( g_File, ";[FEVENT] Restricted users" );
}
public cmdRestrict( i_Index, iLevel, iCid )
{
if( !cmd_access( i_Index, iLevel, iCid, 2 ) )
return PLUGIN_HANDLED;
new szArg[ 32 ];
read_argv( 1, szArg, charsmax( szArg ) )
new iPlayer = cmd_target( i_Index, szArg, FLAGS );
if( !iPlayer )
return PLUGIN_HANDLED;
new szName[ 32 ];
get_user_name( iPlayer, szName, charsmax( szName ) );
new szReadData[ 256 ], szParsedName[ 32 ], iLine = 0, iLen, iDone = 0;
new bool:bIsOk = false;
while( read_file( g_File, iLine++, szReadData, charsmax( szReadData ), iLen ) )
{
parse( szReadData, szParsedName, charsmax( szParsedName ) )
if( szParsedName[ 0 ] == ';' )
{
for( new i = 0; i < sizeof szName; i++ )
{
for( new j = 1; j < sizeof szParsedName; j++ )
{
if( equali( szName[ i ], szParsedName[ j ] ) )
{
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "RESTRICTION_ADDED", szName );
bIsOk = true;
iDone = 1;
break;
}
break;
}
}
}
if( bIsOk == true )
{
formatex( szParsedName, charsmax( szParsedName ), "%s", szName );
write_file( g_File, szParsedName, iLine - 1 );
break;
}
if( equali( szName, szParsedName ) )
{
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "HAS_RESTRICTION", szName );
iDone = 1;
break;
}
}
if( iDone != 1 )
{
write_file( g_File, szName );
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "RESTRICTION_ADDED", szName );
}
return PLUGIN_HANDLED;
}
public cmdUnRestrict( i_Index, iLevel, iCid )
{
if( !cmd_access( i_Index, iLevel, iCid, 2 ) )
return PLUGIN_HANDLED;
new szArg[ 32 ];
read_argv( 1, szArg, charsmax( szArg ) )
new iPlayer = cmd_target( i_Index, szArg, FLAGS );
if( !iPlayer )
return PLUGIN_HANDLED;
new szName[ 32 ];
get_user_name( iPlayer, szName, charsmax( szName ) );
new szReadData[ 256 ], szParsedName[ 32 ], iLine = 0, iLen;
while( read_file( g_File, iLine++, szReadData, charsmax( szReadData ), iLen ) )
{
parse( szReadData, szParsedName, charsmax( szParsedName ) )
if( szParsedName[ 0 ] == ';' )
{
for( new i = 0; i < sizeof szName; i++ )
{
for( new j = 1; j < sizeof szParsedName; j++ )
{
if( equali( szName, szParsedName ) )
{
formatex( szParsedName, charsmax( szParsedName ), ";%s", szName );
write_file( g_File, szParsedName, iLine - 1 );
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "RESTRICTION_DELETED", szName );
return PLUGIN_HANDLED;
}
}
}
}
if( equali( szName, szParsedName ) )
{
break;
}
}
formatex( szParsedName, charsmax( szParsedName ), ";%s", szName );
write_file( g_File, szParsedName, iLine - 1 );
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "RESTRICTION_DELETED", szName );
return PLUGIN_HANDLED;
}
public create()
{
g_On = 1;
for( new j = 0; j < sizeof g_Codename - 1; j++ )
{
g_Codename[ j ] = random_num( '!', '~' );
if( g_Codename[ j ] == '%' || g_Codename[ j ] == ';' )
g_Codename[ j ] = ',';
}
new szMessage[ 192 ];
formatex( szMessage, charsmax( szMessage ), "[EVENT] %L ", LANG_PLAYER, "NEW_CODE", g_Codename );
set_hudmessage( 255, 0, 0, 0.07, 0.21, 0, 6.0, HOLD_TIME );
ShowSyncHudMsg ( 0, MsgSync, szMessage );
new Float:cleartime = get_pcvar_float( g_Time );
set_task( cleartime, "clear_vars" );
}
public clear_vars()
{
g_Codename[ 0 ] = EOS;
g_On = 0;
}
public cmdentered( i_Index )
{
if( g_On == 1 )
{
new szSaid[ 192 ];
read_args( szSaid, charsmax( szSaid ) );
remove_quotes( szSaid );
trim( szSaid );
if( equal( szSaid, g_Codename ) )
{
new szName[ 32 ];
get_user_name( i_Index, szName, charsmax( szName ) );
new szReadData[ 256 ], szParsedName[ 32 ], iLine = 0, iLen;
while( read_file( g_File, iLine++, szReadData, charsmax( szReadData ), iLen ) )
{
parse( szReadData, szParsedName, charsmax( szParsedName ) )
if( equal( szName, szParsedName ) )
{
client_print( i_Index, print_chat, "[FEVENT] %L", LANG_PLAYER, "CODE_NOTACCESS" );
return PLUGIN_HANDLED;
}
}
client_print( 0, print_chat, "[EVENT] %L", LANG_PLAYER, "ANNOUNCE_WINNER", szName, get_pcvar_num( g_Prize ) );
cs_set_user_money( i_Index, (cs_get_user_money(i_Index) + get_pcvar_num(g_Prize)) );
g_On = 0;
}
if( equali( szSaid, "" ) )
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
} [/code]