Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Plugin generated by AMXX-Studio */
- #include < amxmodx >
- #include < dhudmessage >
- #include < engine >
- #include < fakemeta >
- #include < amxmisc >
- #include < hamsandwich >
- #define MAX_SIZE 127
- enum _: Data_Trie
- {
- Trie: g_TrieName,
- Trie: g_TrieScore,
- Trie: g_TrieLaps,
- Trie: g_TrieScore_Length
- }
- new sBuffer[ 128 ], szProfile[ 128 ], szMap[ 64 ];
- new Trie: TrieData[ Data_Trie ], Array: g_iDeathrun;
- new Timer_Running[ 33 ], Float: Timer[ 33 ];
- native freeze_end();
- native vote_end();
- public plugin_init()
- {
- register_plugin( "Deathrun Top System", "1.0", "xDoctor" );
- RegisterHam( Ham_Spawn, "player", "CBase_PlayerSpawn_Post" );
- register_forward(FM_Touch, "fwd_Touch")
- g_iDeathrun = ArrayCreate( MAX_SIZE, 1 );
- TrieData[ g_TrieName ] = TrieCreate();
- TrieData[ g_TrieScore ] = TrieCreate();
- TrieData[ g_TrieLaps ] = TrieCreate();
- TrieData[ g_TrieScore_Length ] = TrieCreate();
- get_mapname( szMap, charsmax( szMap ) );
- LoadDeathrunTop();
- ArraySort( g_iDeathrun, "SortTop_Place" );
- set_task( 5.0, "Sort_TopRankings", _,_,_, "b" );
- set_task( 1.0, "TimerTask", 2000, "", 0, "ab" );
- register_clcmd( "say /top", "CmdPro_Tops" );
- }
- public Sort_TopRankings()
- {
- ArraySort( g_iDeathrun, "SortTop_Place" );
- SaveDeathrunTop();
- }
- public CBase_PlayerSpawn_Post( index )
- {
- if( !vote_end() )
- set_task( float( freeze_end() ), "ActivateTimer", index );
- else
- {
- Timer_Running[ index ] = true;
- Timer[ index ] = get_gametime();
- ColorChat( index, "Timer started.. #No waiting." );
- }
- }
- public TimerTask()
- {
- new g_iAlive[ 32 ], g_iDead[ 32 ], alivePlayer, deadPlayer;
- new minutes, seconds;
- get_players( g_iAlive, alivePlayer, "ach" );
- get_players( g_iDead, deadPlayer, "bch" );
- for( new i = 0; i < alivePlayer; i++ )
- {
- if( Timer_Running[ g_iAlive[ i ] ] )
- {
- new Float: Time = get_gametime() - Timer[ g_iAlive[ i ] ];
- minutes = floatround( Time, floatround_floor ) / 60
- seconds = floatround( Time- ( 60 * minutes ), floatround_floor )
- set_hudmessage( 0, 255, 255, -1.0, 0.85, 0, 0.0, 1.0, 2.0, 1.0 )
- show_hudmessage( g_iAlive[ i ], "Time: %02d:%02d", minutes, seconds );
- }
- }
- for( new i = 0; i < deadPlayer; i++ )
- {
- new specmode = pev( g_iDead[ i ], pev_iuser1 );
- if( specmode == 2 || specmode == 4 )
- {
- new target = pev( g_iDead[ i ], pev_iuser2 );
- if( target != g_iDead[ i ] )
- {
- if( Timer_Running[ g_iAlive[ i ] ] )
- {
- new Float: Time = get_gametime() - Timer[ g_iAlive[ i ] ];
- minutes = floatround( Time, floatround_floor ) / 60
- seconds = floatround( Time - ( 60 * minutes ), floatround_floor )
- set_hudmessage( 0, 255, 255, -1.0, 0.10, 4, 0.0, 1.0, 0.0, 0.1 )
- show_hudmessage( g_iDead[ i ], "Player %s, Timer: %02d:%02d", GetUserName( target ), minutes, seconds );
- }
- }
- }
- }
- }
- public fwd_Touch( ent, id )
- {
- new szEntClass_Name[ 32 ], szEntClass_Id[ 32 ], Score[ 32 ];
- pev( ent, pev_targetname, szEntClass_Name, charsmax( szEntClass_Name ) )
- pev( id, pev_targetname, szEntClass_Id, charsmax( szEntClass_Id ) )
- if( equal( szEntClass_Name, "aaa" ) || equal( szEntClass_Id, "aaa" ) )
- {
- //if( Timer_Running[ id ] )
- {
- new minutes, seconds, ms;
- new Float: Time = get_gametime() - Timer[ id ];
- minutes = floatround( Time, floatround_floor ) / 60;
- seconds = floatround( Time - ( 60 * minutes ), floatround_floor )
- ms = floatround( ( Time - ( minutes * 60.0 + seconds ) ) * 100.0, floatround_floor )
- formatex( Score, sizeof Score-1, "%02d:%02d:%02d", minutes, seconds, ms );
- ColorChat( 0, "'^3%s^1' have ^4finished^1 the run in ^3%s^1 after ^3%s^1.", GetUserName( id ), szMap, Score );
- new bool: Found, FoundId;
- Found = false;
- new SteamID2[ 32 ], PlayerID[ 32] ;
- get_user_authid( id, PlayerID, charsmax( PlayerID ) );
- for( new i = 0; i < ArraySize( g_iDeathrun ); i++ )
- {
- ArrayGetString( g_iDeathrun, i, SteamID2, sizeof SteamID2-1 );
- if( equal( SteamID2, PlayerID ) )
- {
- Found = true;
- FoundId = i;
- }
- }
- if( Found )
- {
- new Name[ 32 ], SteamID[ 32 ], Laps, TimeLength;
- formatex( Name, charsmax( Name ), "%s", GetUserName( id ) );
- formatex( SteamID, charsmax( SteamID ), "%s", szAuth( id ) );
- for( new i = 0; i < ArraySize( g_iDeathrun ); i++ )
- {
- ArrayGetString( g_iDeathrun, i, SteamID, sizeof SteamID-1 );
- if( equal( SteamID, PlayerID ) )
- {
- TrieGetCell( TrieData[ g_TrieLaps ], SteamID, Laps );
- TrieSetString( TrieData[ g_TrieName ], SteamID, Name );
- TrieSetCell( TrieData[ g_TrieLaps ], SteamID, Laps+1 );
- TrieGetCell( TrieData[ g_TrieScore_Length ], SteamID, TimeLength );
- ColorChat( id, "finish : %.2f, before: %.2f", Time, TimeLength );
- if( TimeLength > Time )
- {
- TrieSetString( TrieData[ g_TrieScore ], SteamID, Score );
- TrieSetCell( TrieData[ g_TrieScore_Length ], SteamID, Time );
- break;
- }
- }
- }
- SaveDeathrunTop();
- Sort_TopRankings();
- }
- else
- {
- new Name[ 32 ], SteamID[ 32 ], Rank;
- formatex( SteamID, charsmax( SteamID ), "%s", szAuth( id ) );
- formatex( Name, charsmax( Name ), "%s", GetUserName( id ) );
- ArrayPushString( g_iDeathrun, SteamID );
- TrieSetString( TrieData[ g_TrieName ], SteamID, Name );
- TrieSetString( TrieData[ g_TrieScore ], SteamID, Score );
- TrieSetCell( TrieData[ g_TrieScore_Length ], SteamID, Time );
- TrieSetCell( TrieData[ g_TrieLaps ], SteamID, 1 );
- SaveDeathrunTop();
- Sort_TopRankings();
- new SteamID2[ 32 ], PlayerID[ 32 ];
- get_user_authid( id, PlayerID, charsmax( PlayerID ) );
- for( new i = 0; i < ArraySize( g_iDeathrun ); i++ )
- {
- ArrayGetString( g_iDeathrun, i, SteamID2, sizeof SteamID2-1 );
- if( equal( SteamID2, PlayerID ) )
- {
- ColorChat( 0, "Found !" );
- Rank = i;
- }
- }
- ColorChat( 0, "Player '^3%s^1' is now rank ^3#%i^1 out of ^3#%i^1.", GetUserName( id ), Rank, ArraySize( g_iDeathrun ) );
- }
- }
- SaveDeathrunTop();
- Sort_TopRankings();
- Timer[ id ] = get_gametime() - 10.0;
- set_pev(ent, pev_solid, SOLID_NOT)
- set_task( 0.5, "Remove_NOT", ent );
- return 1;
- }
- return 0;
- }
- public Remove_NOT( ent )
- set_pev(ent, pev_solid, SOLID_BBOX)
- public SortTop_Place( Array: g_iArray, Position, OtherPosition )
- {
- new SteamID[ 35 ], SteamID2[ 35 ];
- new Length_Player, Length_OtherPlayer;
- ArrayGetString( g_iArray, Position, SteamID, sizeof SteamID-1 );
- ArrayGetString( g_iArray, OtherPosition, SteamID2, sizeof SteamID2-1 );
- TrieGetCell( TrieData[ g_TrieScore_Length ], SteamID, Length_Player );
- TrieGetCell( TrieData[ g_TrieScore_Length ], SteamID2, Length_OtherPlayer );
- if( Length_Player > Length_OtherPlayer )
- return 1;
- if( Length_Player < Length_OtherPlayer )
- return -1;
- return 0;
- }
- public LoadDeathrunTop()
- {
- formatex( szProfile, charsmax( szProfile ), "addons/amxmodx/data/deathrun_top/top_%s.ini", szMap );
- new f = fopen( szProfile, "r" );
- if( !f ) return;
- new szData[ 555 ], TopRank_Name[ 32 ], TopRank_Score[ 32 ];
- new SteamID[ 32 ], TopRank_Length[ 16 ], TopRank_Laps[ 16 ];
- while( !feof( f ) )
- {
- fgets( f, szData, charsmax( szData ) );
- if( !strlen( szData ) )
- continue;
- replace_all( szData, charsmax( szData ), "#", " " );
- parse( szData, SteamID, 31, TopRank_Name, 31, TopRank_Score, 31, TopRank_Length, 15, TopRank_Laps, 15 );
- ArrayPushString( g_iDeathrun, SteamID );
- TrieSetString( TrieData[ g_TrieName ], SteamID, TopRank_Name );
- TrieSetString( TrieData[ g_TrieScore ], SteamID, TopRank_Score );
- TrieSetCell( TrieData[ g_TrieScore_Length ], SteamID, str_to_float( TopRank_Length ) );
- TrieSetCell( TrieData[ g_TrieLaps ], SteamID, str_to_num( TopRank_Laps ) );
- }
- fclose( f );
- }
- public SaveDeathrunTop()
- {
- formatex( szProfile, charsmax( szProfile ), "addons/amxmodx/data/deathrun_top/top_%s.ini", szMap );
- new f = fopen( szProfile, "w+" );
- if( !f ) return;
- new SteamID[ 32 ], TopRank_Name[ 32 ];
- new TopRank_Score[ 32 ], TopRank_Length, TopRank_Laps;
- for( new i = 0; i < ArraySize( g_iDeathrun ); i++ )
- {
- ArrayGetString( g_iDeathrun, i, SteamID, sizeof SteamID-1 );
- TrieGetString( TrieData[ g_TrieName ], SteamID, TopRank_Name, sizeof TopRank_Name-1 );
- TrieGetString( TrieData[ g_TrieScore ], SteamID, TopRank_Score, sizeof TopRank_Score-1 );
- TrieGetCell( TrieData[ g_TrieScore_Length ], SteamID, TopRank_Length );
- TrieGetCell( TrieData[ g_TrieLaps ], SteamID, TopRank_Laps );
- formatex( sBuffer, charsmax( sBuffer ), "^"%s^" ^"%s^" ^"%s^" ^"%.2f^" %i^n", SteamID, TopRank_Name, TopRank_Score, TopRank_Length, TopRank_Laps );
- fprintf( f, sBuffer );
- }
- //ColorChat( 0, "Save to file: %s", sBuffer );
- fclose( f );
- }
- public CmdPro_Tops( index )
- {
- if( ArraySize( g_iDeathrun ) <= 0 )
- return ColorChat( index, "Sorry no records have been found in ^3%s^1.", szMap );
- new motd[ 2048 ], len;
- len = formatex( motd[ len ], charsmax( motd ) - len, "<meta charset=UTF-8> <style> body { background:#242424; margin:20px; font-family:Tahoma } th { background:#2F3034; color:#BDB670; text-align:left; } table { padding:4px; background:#4A4945 font-size:10px; color:#FFF; } h2,h3 { color:#D2D1CF } #c{ background:#3B3C37 } img { height:12px; background:#99CC00; margin:0 3px; } #r { height:12px; background:#999900 } #clr { background:none; color:#FFF; font-size:20px } </style>" );
- len += formatex( motd[ len ], charsmax( motd ) - len, "<body><h2> Top 10 Player's <h2><table width=100%% border=5 align=center cellpadding=2 cellspacing=0>" );
- len += formatex( motd[ len ], charsmax( motd ) - len, "<tr><th>#<th style=^"width: 250px^">Player<th style=^"width: 250px^">Score<th style=^"width: 125px^">Laps</tr>" );
- for( new i = 0; i < min( 10, ArraySize( g_iDeathrun ) ); i++ )
- {
- new SteamID[ 32 ], Name[ 32 ], Score[ 32 ], Laps;
- ArrayGetString( g_iDeathrun, i, SteamID, sizeof SteamID-1 );
- TrieGetString( TrieData[ g_TrieName ], SteamID, Name, sizeof Name-1 );
- TrieGetString( TrieData[ g_TrieScore ], SteamID, Score, sizeof Score-1 );
- TrieGetCell( TrieData[ g_TrieLaps ], SteamID, Laps );
- if( i > ArraySize( g_iDeathrun ) )
- len += formatex( motd[ len ], charsmax( motd ) - len, "<tr bgcolor=%s style=^"color:%s^"><td>%d<td>%s<td>%s<td>%s</tr>", !( i % 2 ) ? "#242424" : "#282828", "#FFFFFF", i+1, "Unknown Name", "00:00:00", "0" );
- else
- len += formatex( motd[ len ], charsmax( motd ) - len, "<tr bgcolor=%s style=^"color:#FFFFFF^"><td>%d<td>%s<td>%s<td>%i</tr>", !( i % 2 ) ? "#242424" : "#282828", i+1, Name, Score, Laps );
- }
- show_motd( index, motd, "Top Map Players MOTD by xDoctor." );
- return 1;
- }
- stock GetUserName( const Index )
- {
- new szName[ 32 ];
- get_user_name( Index, szName, charsmax( szName ) );
- return szName;
- }
- stock ColorChat(const id, const string[], {Float, Sql, Resul,_}:...)
- {
- new msg[191], players[32], count = 1
- static len
- len = formatex(msg, charsmax(msg), "^1[ ^3#Flag-IL Top ^1] " )
- vformat(msg[len], charsmax(msg) - len, string, 3)
- if(id) players[0] = id
- else get_players(players,count,"ch")
- for (new i = 0; i < count; i++)
- {
- if(is_user_connected(players[i]))
- {
- message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"),_, players[i])
- write_byte(players[i])
- write_string(msg)
- message_end()
- }
- }
- return 1;
- }
- stock frozen_account( index )
- {
- new iFlags = pev( index, pev_flags );
- return iFlags & FL_FROZEN ? 1 : 0;
- }
- stock set_user_freeze( const index, const freeze )
- {
- new iFlags = pev( index, pev_flags );
- set_pev( index, pev_flags, freeze ? iFlags | FL_FROZEN : iFlags & ~FL_FROZEN );
- return freeze;
- }
- stock szAuth( const index )
- {
- static Auth[ 35 ];
- get_user_authid( index, Auth, charsmax( Auth ) );
- return Auth;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement