Senior Member
|
11-10-2011
, 14:06
Re: Structure HUD [HELP]
|
#77
|
Quote:
Originally Posted by fysiks
I would do something like this (you need to add the word "random" without the quotes to your maps.ini or mapcycle.txt).
PHP Code:
#include <amxmodx> #include <amxmisc>
const VoteMaps = 10; //Number of maps in each vote const VoteTime = 30; //Number of seconds to allow people to vote const TaskMapHUD = 1092; //Task-ID for map vote HUD
enum _:MapInfo { MapIndex, MapVotes }
new g_iVoteMenu; new g_iVoteMapCount; new g_iMapVotes[ VoteMaps ][ MapInfo ]; new g_szVoteMaps[ VoteMaps ][ 33 ]; new g_iNumPlayers; new g_iVoteCount; new g_iSyncHUDObj[ 2 ];
public plugin_init() { register_plugin( "Vote Map" , "0.1" , "bugsy" ); g_iSyncHUDObj[ 0 ] = CreateHudSyncObj(); g_iSyncHUDObj[ 1 ] = CreateHudSyncObj(); register_concmd( "say votemap" , "VoteMap" ); }
public VoteMap( id ) { if ( task_exists( TaskMapHUD ) ) { client_print( id , print_chat , "* There is already a vote taking place so cannot start vote." ); return PLUGIN_HANDLED; } new szFile[ 64 ] , iPlayers[ 32 ]; get_players( iPlayers , g_iNumPlayers ); if ( !g_iNumPlayers ) return PLUGIN_HANDLED; g_iVoteCount = 0; g_iVoteMenu = menu_create( "Vote for Map" , "VoteHandler" ); copy( szFile[ get_configsdir( szFile , charsmax( szFile ) ) ] , charsmax( szFile ) , "/maps.ini" ); if( file_exists( szFile ) ) LoadMapFile( szFile ); if ( !g_iVoteMapCount ) { copy( szFile , charsmax( szFile ) , "mapcycle.txt" ); LoadMapFile( szFile ); } menu_setprop( g_iVoteMenu , MPROP_EXIT , MEXIT_ALL ); for ( new i = 0 ; i < g_iNumPlayers ; i++ ) menu_display( iPlayers[ i ] , g_iVoteMenu ); UpdateHUD(); set_task( 1.0 , "UpdateHUD" , TaskMapHUD , _ , _ , "a" , VoteTime + 1 ); return PLUGIN_HANDLED; }
LoadMapFile( const szFile[] ) { new szText[ 256 ] , iFile; iFile = fopen( szFile , "rt" ); g_iVoteMapCount = 0; while( ( g_iVoteMapCount < VoteMaps ) && !feof( iFile ) && fgets( iFile , szText , charsmax( szText ) ) ) { trim( szText ); if( ( ( szText[ 0 ] == '^0' ) || ( szText[ 0 ] == '/' ) || ( szText[ 0 ] == ';' ) ) || (!is_map_valid( szText ) && !equali(szText, "random")) ) continue;
copy( g_szVoteMaps[ g_iVoteMapCount ] , charsmax( g_szVoteMaps[] ) , szText );
g_iMapVotes[ g_iVoteMapCount ][ MapIndex ] = g_iVoteMapCount++;
menu_additem( g_iVoteMenu , szText ) } fclose( iFile ); }
public VoteHandler( id , menu , item ) { if ( item == MENU_EXIT ) return PLUGIN_HANDLED; static szName[ 33 ]; get_user_name( id , szName , charsmax( szName ) ); g_iMapVotes[ item ][ MapVotes ]++; g_iVoteCount++; client_print( 0 , print_chat , "* %s voted for %s" , szName , g_szVoteMaps[ item ] ); return PLUGIN_HANDLED; }
public UpdateHUD() { static iDisplayCount = -1; if ( ++iDisplayCount == VoteTime ) { SelectMap(); } else { static szHUD[ VoteMaps * 40 ] , iPos , iPos2; static g_iMapVotesTemp[ VoteMaps ][ MapInfo ]; iPos = copy( szHUD , charsmax( szHUD ) , "Map Votes:" ); szHUD[ iPos++ ] = EOS; iPos2 = iPos; if ( g_iVoteCount ) { g_iMapVotesTemp = g_iMapVotes; SortCustom2D( g_iMapVotesTemp , VoteMaps , "SortMaps" ); for ( new i = 0 ; i < g_iVoteMapCount ; i++ ) if ( g_iMapVotesTemp[ i ][ MapVotes ] ) iPos += formatex( szHUD[ iPos ] , charsmax( szHUD ) - iPos , "%s - %d vote%s^n" , g_szVoteMaps[ g_iMapVotesTemp[ i ][ MapIndex ] ] , g_iMapVotesTemp[ i ][ MapVotes ] , ( g_iMapVotesTemp[ i ][ MapVotes ] != 1 ) ? "s" : "" ); } else { iPos += copy( szHUD[ iPos ] , charsmax( szHUD ) - iPos , "<No Votes>^n" ); } iPos += formatex( szHUD[ iPos ] , charsmax( szHUD ) - iPos , "^n%d second%s remaining" , VoteTime - iDisplayCount , ( VoteTime - iDisplayCount ) != 1 ? "s" : "" ); set_hudmessage( 0 , 255 , 0 , 0.58 , 0.12 , 0 , 6.0 , 1.1 ); ShowSyncHudMsg( 0 , g_iSyncHUDObj[ 0 ] , szHUD ); set_hudmessage( 255 , 255 , 255 , 0.58 , 0.20 , 0 , 6.0 , 1.1 ); ShowSyncHudMsg( 0 , g_iSyncHUDObj[ 1 ] , szHUD[ iPos2 ] ); } }
SelectMap() { new iMostVotes , iWinner = -1;
menu_destroy( g_iVoteMenu ); message_begin( MSG_ALL , SVC_INTERMISSION ); message_end(); for ( new i = 0 ; i < g_iVoteMapCount ; i++ ) { if ( g_iMapVotes[ i ][ MapVotes ] > iMostVotes ) { iMostVotes = g_iMapVotes[ i ][ MapVotes ]; iWinner = i; } } if ( iWinner == -1 ) { iWinner = random( g_iVoteMapCount ); client_print( 0 , print_chat , "* No votes were made so %s was selected randomly as next map." , g_szVoteMaps[ iWinner ] ); } else if( equali(g_szVoteMaps[ iWinner ], "random") ) { iWinner = random( g_iVoteMapCount ); client_print( 0 , print_chat , "* %s has received %d vote%s so %s will be the next map!" , g_szVoteMaps[ iWinner ] , iMostVotes , ( iMostVotes != 1 ) ? "s" : "", g_szVoteMaps[ iWinner ] ); } else { client_print( 0 , print_chat , "* %s has received %d vote%s and will be the next map!" , g_szVoteMaps[ iWinner ] , iMostVotes , ( iMostVotes != 1 ) ? "s" : "" ); }
set_task( 3.0 , "ChangeMap" , iWinner ); }
public ChangeMap( iMapIndex ) { server_cmd( "changelevel %s" , g_szVoteMaps[ iMapIndex ] ); } public SortMaps( elem1[] , elem2[] ) { if( elem1[ 1 ] > elem2[ 1 ] ) return -1; else if( elem1[ 1 ] < elem2[ 1 ] ) return 1; return 0; }
|
Hi all., As you may remove the part of changing the random map if no votes. Well what I want is that if nobody votes for any map .. mantega is the same map where it is, is the only thing I want. If you could help me, thanks.
(Sorry for my bad English).
Last edited by jar_09; 11-10-2011 at 14:20.
|
|