public evCTWin( ) { GivePoint( "CT" );
public evTEWin( ) { GivePoint( "TERRORIST" );
public GivePoint( const sTeam[ ] )
{
static iPlayers[ 32 ], iPlrNum, iId;
get_players( iPlayers, iPlrNum, "ech", sTeam );
for ( new i; i < iPlrNum; ++i )
{
iId = iPlayers[ i ];
g_iUserData[ iId ][ iPoints ] += g_iRoundKills[ iId ];
if ( g_iUserData[ iId ][ iPoints ] >= g_iRangs[ g_iRang[ iId ] ][ iRangPoint ] )
{
++g_iRang[ iId ];
iChatSendCustomData( iId, 0, g_iRangs[ g_iRang[ iId ] - 1 ][ sRangName ] );
}
SaveDatas( iId, 2 );
}
arrayset( g_iRoundKills, 0, sizeof( g_iRoundKills ) );
}
public evDeath( )
{
new iKiller = read_data( 1 );
new iVictim = read_data( 2 );
new bool: bTK = get_user_team( iKiller ) == get_user_team( iVictim );
if ( ( iKiller != iVictim ) && !bTK )
{
++g_iUserData[ iKiller ][ iKills ];
++g_iUserData[ iVictim ][ iDeaths ];
++g_iRoundKills[ iKiller ];
SaveDatas( iKiller, 2 );
SaveDatas( iVictim, 2 );
}
}
public cmdHud( iId ) { ChatColor( iId, "%L", iId, "HUD", iId, ( g_bHud[ iId ] ^= true ) ? "ON" : "OFF" ); }
public cmdRang( iId )
{
static sCurRang[ 32 ], sNextRang[ 32 ], iLen = 0, sMotd[ 2048 ], iMotdLen = charsmax( sMotd );
copy( sCurRang, charsmax( sCurRang ), g_iRangs[ g_iRang[ iId ] - 1 ][ sRangName ] );
if ( g_iRang[ iId ] < ( MaxRang - 1 ) )
copy( sNextRang, charsmax( sNextRang ), g_iRangs[ g_iRang[ iId ] ][ sRangName ] );
show_motd( iId, sMotd, "Rangrendszer info" );
}
public fwClientUserInfoChanged( iId, iBuffer )
{
if ( !is_user_connected( iId ) ) return FMRES_IGNORED;
static sOldName[ 32 ], sNewName[ 32 ];
get_user_name( iId, sOldName, charsmax( sOldName ) );
engfunc( EngFunc_InfoKeyValue, iBuffer, "name", sNewName, charsmax( sNewName ) );
if ( equal( sNewName, sOldName ) ) return FMRES_IGNORED;
engfunc( EngFunc_SetClientKeyValue, iId, iBuffer, "name", sOldName );
client_cmd( iId, "name ^"%s^"; setinfo name ^"%s^"", sOldName, sOldName );
return FMRES_SUPERCEDE;
}
public OnlineTimeCounter( iId )
{
++g_iUserData[ iId ][ iOnlineTime ];
++g_iUserData[ iId ][ iOnlineTimeW ];
if ( g_bHud[ iId ] )
{
if ( !is_user_alive( iId ) )
{
set_hudmessage( 0, 255, 0, 0.01, 0.20, 0, 6.0, 0.9 );
new iTarget = entity_get_int( iId, EV_INT_iuser2 );
if ( iTarget != 0 )
{
show_hudmessage( iId, "%L^n%L^n%L^n%L^n%L^n%L^n%L", iId, "HUD1",
g_sUsername[ iTarget ], iId, "HUD2",
g_iUserData[ iTarget ][ iOnlineTime ] / 3600,( g_iUserData[ iTarget ][ iOnlineTime ] / 60 ) % 60, g_iUserData[ iTarget ][ iOnlineTime ] % 60, iId, "HUD3",
g_iUserData[ iTarget ][ iOnlineTimeW ] / 3600, ( g_iUserData[ iTarget ][ iOnlineTimeW ] / 60 ) % 60, g_iUserData[ iTarget ][ iOnlineTimeW ] % 60, iId, "HUD4",
g_iUserData[ iTarget ][ iKills ], iId, "HUD5", g_iUserData[ iTarget ][ iDeaths ], iId, "HUD6", g_iRangs[ g_iRang[ iTarget ] - 1 ][ sRangName ], g_iUserData[ iTarget ][ iPoints ], iId, "MOTD10" );
}
else
{
show_hudmessage( iId, "%L^n%L^n%L^n%L^n%L^n%L^n%L", iId, "HUD7", iId, "HUD2",
g_iUserData[ iId ][ iOnlineTime ] / 3600,(g_iUserData[ iId ][ iOnlineTime ] / 60 ) % 60, g_iUserData[ iId ][ iOnlineTime ] % 60, iId, "HUD3",
g_iUserData[ iId ][ iOnlineTimeW ] / 3600, (g_iUserData[ iId ][ iOnlineTimeW ] / 60 ) % 60, g_iUserData[ iId ][ iOnlineTimeW ] % 60, iId, "HUD4",
g_iUserData[ iId ][ iKills ], iId, "HUD5", g_iUserData[ iId ][ iDeaths ], iId, "HUD6", g_iRangs[ g_iRang[ iId ] - 1 ][ sRangName ], g_iUserData[ iId ][ iPoints ], iId, "MOTD10" );
}
}
}
}
public Save( iNum )
{
new sNewLine[ 16 ];
formatex( sNewLine, charsmax( sNewLine ), "^"%d^"", iNum );
write_file( "addons/amxmodx/configs/rangsys.ini", sNewLine, 0 );
}
public Load( )
{
new pFile = fopen( "addons/amxmodx/configs/rangsys.ini", "rt" );
if ( pFile )
{
new sLine[ 16 ], sTime[ 64 ], iNum;
fgets( pFile, sLine, charsmax( sLine ) );
trim( sLine );
remove_quotes( sLine );
iNum = str_to_num( sLine );
get_time( "%a", sTime, charsmax( sTime ) );
if ( equal( sTime, "Mon" ) )
{
if ( iNum == 0 )
{
for ( new i; i < 33; ++i ) g_iUserData[ i ][ iOnlineTimeW ] = 0;
Save( 1 );
}
}
else { if ( iNum == 1 ) Save( 0 ); }
fclose(pFile);
}
else Save( 0 );
}
public client_putinserver( iId )
{
if ( is_user_bot( iId ) || is_user_hltv( iId ) ) return;
g_iRoundKills[ iId ] = 0;
g_bHud[ iId ] = true;
g_iRang[ iId ] = 1;
arrayset( g_iUserData[ iId ], 0, sizeof( g_iUserData[ ] ) );
get_user_name( iId, g_sUsername[ iId ], charsmax( g_sUsername[ ] ) );
get_user_authid( iId, g_sAuthID[ iId ], charsmax( g_sAuthID[ ] ) );
iChatSendCustomData( iId, 0, g_iRangs[ 0 ][ sRangName ] );
LoadDatas( iId );
set_task( 1.0, "OnlineTimeCounter", iId, _, _, "b" );
}
public client_disconnect( iId ) { if ( task_exists( iId ) ) remove_task( iId ); SaveDatas( iId, 2 ); }
public plugin_end( ) { SQL_FreeHandle( g_iSqlTuple ); }
stock StrToTime( sTime[ ] )
{
static sYear[ 7 ], sMonth[ 5 ], sDay[ 5 ], sHour[ 5 ], sMin[ 5 ], iYear, iMonth, iDay, iHour, iMin;
parse( sTime, sYear, charsmax( sYear ), sMonth, charsmax( sMonth ), sDay, charsmax( sDay ), sHour, charsmax( sHour ), sMin, charsmax( sMin ) );
iYear = str_to_num( sYear );
iMonth = str_to_num( sMonth );
iDay = str_to_num( sDay );
iHour = str_to_num( sHour );
iMin = str_to_num( sMin );
iMonth = GetHoursInMonth( iMonth, iYear ) * 60;
iYear = ( ( ( iYear % 4 ) == 0 ) ? 366 : 365 ) * 24 * 60;
iDay *= 1440;
iHour *= 60;
return iMonth + iYear + iDay + iHour + iMin;
}
stock GetHoursInMonth( iMonth, iYear )
{
static iHour;
iHour = 0;
for ( new i = 1; i <= iMonth; ++i )
iHour += GetDaysInMonth( i, iYear ) * 24;
return iHour;
}
stock GetDaysInMonth( iMonth, iYear )
{
switch( iMonth )
{
case 1, 3, 5, 7, 8, 10, 12: return 31;
case 2: return ( ( iYear % 4 ) == 0 ) ? 29 : 28;
}
return 30;
}
stock ChatColor( iId, const sMessage[ ], any:... )
{
static iPlrNum, iPlayers[ 32 ], sMsg[ 256 ], iIdMsg, iMsgLen = charsmax( sMsg );
vformat( sMsg, iMsgLen, sMessage, 3 );
format( sMsg, iMsgLen, "!g[%s]!y %s", g_sPrefix, sMsg );
replace_all( sMsg, iMsgLen, "!g", "^4" );
replace_all( sMsg, iMsgLen, "!y", "^1" );
replace_all( sMsg, iMsgLen, "!t", "^3" );
if ( !iIdMsg ) iIdMsg = get_user_msgid( "SayText" );
if ( iId )
{
iPlayers[ 0 ] = iId;
iPlrNum = 1;
}
else get_players( iPlayers, iPlrNum, "ch" );
for ( new i, iPId; i < iPlrNum; ++i )
{
iPId = iPlayers[ i ];
if ( !is_user_connected( iPId ) ) continue;
message_begin( MSG_ONE, iIdMsg, _, iPId );
write_byte( iPId );
write_string( sMsg );
message_end( );
}
}