/*
NOMBRE: VoteMap Countdown
VÍNCULO:
AUTOR: Chema - [ www.facebook.com/CSPlayerChema ]
CHANGELOG:
- 1.0b
[*] Versión inicial, Fecha de lanzamiento: 28 de junio de 2019.
*/
#include < amxmodx >
#include < engine >
#include < fakemeta >
#include < colorchat >
#pragma semicolon 1
/* GLOBAL STUFF */
#define IsUserValidConnected(%1) ( 1 <= %1 <= g_iMaxPlayers{0} && is_user_connected( %1 ) )
#define MAX_USERS 32 + 1
new const g_szPluginName[ ] = "VoteMap Countdown";
new const g_szPluginVersion[ ] = "1.0b";
new const g_szPluginAuthor[ ] = "Chema";
new const g_szPluginCvar[ ] = "vmc_version";
new const g_szWebsiteUrl[ ] = "www.skill-gamerz.net";
new const g_szItemMenuSound[ ] = "Ui/buttonclickrelease.wav";
enum _:eMap_Struct {
Map_Name[ 21 ],
Map_RealName[ 21 ]
};
new const g_szMapNames[ ][ _:eMap_Struct ] = {
{ "DUST II", "de_dust2" },
{ "INFERNO", "de_inferno" },
{ "NUKE", "de_nuke" },
{ "MIRAGE", "de_mirage" },
{ "CBBLE", "de_cbble" },
{ "ASSAULT", "cs_assault" },
{ "DUST", "de_dust" },
{ "MILITIA", "cs_militia" },
{ "ITALY", "cs_italy" },
{ "ESTATE", "cs_estate" }
};
new g_szPlayerName[ MAX_USERS ][ 32 ];
new g_iPage[ MAX_USERS ];
enum {
Countdown_Vote,
Countdown_Random,
Countdown_Normal
};
new g_iCountdown;
new g_iCountdownType;
new g_iCountdownEntity;
new g_iRandomMap;
new g_iMapWinner = 0;
new bool:g_bVoteStarted = false;
new bool:g_bVoteIsRunning;
new g_iMaps[ sizeof( g_szMapNames ) ];
new g_iVotes[ sizeof( g_szMapNames ) ];
new g_iMaxPlayers[ 1 char ];
public plugin_init( ) {
/* Register Plugin & Cvars */
register_plugin( g_szPluginName, g_szPluginVersion, g_szPluginAuthor );
register_cvar( g_szPluginCvar, g_szPluginVersion, FCVAR_SERVER|FCVAR_SPONLY );
/* Client-related Stuff */
register_clcmd( "say !startvote", "ClientCommand_StartCountdown" );
/* Menus */
register_menucmd( register_menuid( "Maps Menu" ), 1023, "HandlerVoteMapMenu" );
/* Think's */
static szCountClassName[ ] = "VoteMapTimer";
register_think( szCountClassName, "Think_VoteMap" );
/* Global Vars & Entities */
g_iCountdownEntity = create_entity( "info_target" );
set_pev( g_iCountdownEntity, pev_classname, szCountClassName );
g_iMaxPlayers{0} = get_maxplayers( );
}
/* Client-related Stuff */
public ClientCommand_StartCountdown( const id ) {
if( !( get_user_flags( id ) & ADMIN_IMMUNITY ) ) {
ColorChat( id, Red, "No tienes acceso para ejecutar una votación de mapa." );
return 1;
}
if( g_bVoteIsRunning ) {
ColorChat( id, Red, "Hay una votación en progreso." );
return 1;
}
if( g_bVoteStarted ) {
ColorChat( id, Red, "Ya se realizó una votación." );
return 1;
}
g_iCountdownType = Countdown_Vote;
g_iCountdown = 10;
set_pev( g_iCountdownEntity, pev_nextthink, get_gametime( ) );
get_user_name( id, g_szPlayerName[ id ], charsmax( g_szPlayerName ) );
ColorChat( id, Red, "El administrador ^4%s^1 inició el conteo para la votación de mapa.", g_szPlayerName[ id ] );
g_bVoteStarted = true;
return 1;
}
/* Think's */
public Think_VoteMap( const iEntity ) {
new iColor[ 3 ];
iColor[ 0 ] = random_num( 0, 255 );
iColor[ 1 ] = random_num( 0, 255 );
iColor[ 2 ] = random_num( 0, 255 );
if( g_iCountdown ) {
if( g_iCountdownType == Countdown_Vote ) {
set_hudmessage( iColor[ 0 ], iColor[ 1 ], iColor[ 2 ], -1.0, -1.0, 0, 0.0, 1.1, 0.0, 0.0, 1 );
show_hudmessage( 0, "La votación para el siguiente mapa^ncomenzará en %i segundo%s", g_iCountdown, g_iCountdown > 1 ? "s" : "" );
}
else if( g_iCountdownType == Countdown_Random ) {
set_hudmessage( iColor[ 0 ], iColor[ 1 ], iColor[ 2 ], -1.0, -1.0, 0, 0.0, 1.1, 0.0, 0.0, 1 );
show_hudmessage( 0, "Nadie votó, se elegirá un mapa aleatorio en %i segundo%s", g_iCountdown, g_iCountdown > 1 ? "s" : "" );
}
else if( g_iCountdownType == Countdown_Normal ) {
set_hudmessage( iColor[ 0 ], iColor[ 1 ], iColor[ 2 ], -1.0, -1.0, 0, 0.0, 1.1, 0.0, 0.0, 1 );
show_hudmessage( 0, "Cambiando de mapa en %i segundo%s...", g_iCountdown, g_iCountdown > 1 ? "s" : "" );
}
set_pev( iEntity, pev_nextthink, get_gametime( ) + 1.0 );
new szBuffer[ 16 ];
num_to_word( g_iCountdown, szBuffer, 15 );
client_cmd( 0, "spk ^"fvox/%s^"", szBuffer );
--g_iCountdown;
}
else {
if( g_iCountdownType == Countdown_Vote ) {
set_hudmessage( iColor[ 0 ], iColor[ 1 ], iColor[ 2 ], -1.0, -1.0, 0, 0.0, 1.1, 0.0, 0.0, 1 );
show_hudmessage( 0, "Votación para el siguiente mapa iniciada!" );
for( new i = 0; i < sizeof( g_szMapNames ); i++ ) {
g_iMaps[ i ] = 0;
g_iVotes[ i ] = 0;
}
g_bVoteIsRunning = true;
for( new id = 1; id <= g_iMaxPlayers{0}; id++ ) {
if( !is_user_connected( id ) )
continue;
if( get_user_team( id ) == 1 || get_user_team( id ) == 2 )
ShowVoteMapMenu( id, g_iPage[ id ] = 0 );
}
set_task( 10.0, "task_VoteMapEnd" );
}
else if( g_iCountdownType == Countdown_Random )
task__SelectRandomMap( );
else if( g_iCountdownType == Countdown_Normal ) {
set_hudmessage( iColor[ 0 ], iColor[ 1 ], iColor[ 2 ], -1.0, -1.0, 0, 0.0, 1.1, 0.0, 0.0, 1 );
show_hudmessage( 0, "La votación para el siguiente mapa^ncomenzará en %i segundo%s", g_iCountdown, g_iCountdown > 1 ? "s" : "" );
}
}
}
/* VoteMap Menu */
ShowVoteMapMenu( id, iPage ) {
if( iPage < 0 )
return 0;
new szMenu[ 256 ], szMap[ 22 ], iNum, iStart = iPage * 6, iEnd = iStart + 6;
get_mapname( szMap, charsmax( szMap ) );
iNum = sizeof( g_szMapNames );
if( iStart > iNum ) iStart = iPage = g_iPage[ id ] = 0;
if( iEnd > iNum ) iEnd = iNum;
new iActual, iLen, iCurrentKey, iKeys = ( 1 << 9 );
iLen = formatex( szMenu[ iLen ], 255, "\ySkill-Gamerz \r- \yVotación de mapa! \r(%s)^n\d%s^n^n", g_szPluginVersion, g_szWebsiteUrl );
for( new i = iStart; i < iEnd; i++ ) {
iActual = equal( szMap, g_szMapNames[ i ][ Map_RealName ] );
if( iActual )
iCurrentKey++;
else
iKeys |= ( 1 << iCurrentKey++ );
iLen += formatex( szMenu[ iLen ], 255 - iLen, "\r%i. %s%s%s^n", iCurrentKey, iActual ? "\d" : "\w", g_szMapNames[ i ][ Map_Name ], iActual ? " \r[ACTÚAL]" : "" );
}
iLen += formatex( szMenu[ iLen ], 255 - iLen, "^n\r7. \wNo votar" );
if( g_iPage[ id ] == 0 ) {
iKeys |= ( 1 << 6 )|( 1 << 8 );
iLen += formatex( szMenu[ iLen ], 255 - iLen, "^n\d8. \dAtrás^n" );
iLen += formatex( szMenu[ iLen ], 255 - iLen, "\r9. \wSiguiente^n" );
}
else {
iKeys |= ( 1 << 6 )|( 1 << 7 );
iLen += formatex( szMenu[ iLen ], 255 - iLen, "^n\r8. \wAtrás^n" );
iLen += formatex( szMenu[ iLen ], 255 - iLen, "\d9. \dSiguiente^n" );
}
iLen += formatex( szMenu[ iLen ], 255 - iLen, "^n\r0. \wCerrar" );
show_menu( id, iKeys, szMenu, -1, "Maps Menu" );
return 0;
}
public HandlerVoteMapMenu( const id, const iKey ) {
if( !g_bVoteIsRunning )
return 1;
get_user_name( id, g_szPlayerName[ id ], charsmax( g_szPlayerName ) );
switch( iKey ) {
case 0..5: {
g_iMaps[ g_iPage[ id ] * 6 + iKey ]++;
g_iVotes[ g_iPage[ id ] * 6 + iKey ]++;
ColorChat( id, Red, "^4%s^1 votó por el mapa: ^3%s^1.", g_szPlayerName[ id ], g_szMapNames[ g_iPage[ id ] * 6 + iKey ][ Map_Name ] );
}
case 6: ColorChat( id, Red, "^4%s^1 eligió no ser parte de la votación.", g_szPlayerName[ id ] );
case 7: {
if( g_iPage[ id ] == 1 )
g_iPage[ id ] = 0;
ShowVoteMapMenu( id, g_iPage[ id ] );
}
case 8: {
if( g_iPage[ id ] == 0 )
g_iPage[ id ] = 1;
ShowVoteMapMenu( id, g_iPage[ id ] );
}
}
if( iKey != 9 )
client_cmd( id, "spk ^"%s^"", g_szItemMenuSound );
return 1;
}
/* Task's */
public task__VoteMapEnd( ) {
g_bVoteIsRunning = false;
new iMapWinner[ 2 ], Float:fTotal;
for( new i = 0; i < sizeof( g_szMapNames ); i++ ) {
if( g_iMaps[ i ] > iMapWinner[ 1 ] ) {
iMapWinner[ 0 ] = i;
iMapWinner[ 1 ] = g_iMaps[ i ];
}
g_iMaps[ i ] = 0;
}
for( new id = 1; id <= g_iMaxPlayers{0}; id++ ) {
if( !is_user_connected( id ) )
continue;
show_menu( id, 0, "^n", 1 );
}
for( new i = 0; i < sizeof( g_szMapNames ); i++ )
fTotal = float( g_iMaps[ i ] + 1 );
if( !iMapWinner[ 1 ] ) {
g_iCountdownType = Countdown_Random;
g_iCountdown = 5;
set_pev( g_iCountdownEntity, pev_nextthink, get_gametime( ) );
}
else {
g_iMapWinner = iMapWinner[ 0 ];
ColorChat( 0, Red, "El mapa ganador fue: ^4%s^1 con ^3%i/%i^1 votos.", g_szMapNames[ iMapWinner[ 0 ] ][ Map_Name ], g_iVotes[ iMapWinner[ 0 ] ], floatround( fTotal ) );
g_iCountdownType = Countdown_Normal;
g_iCountdown = 5;
set_pev( g_iCountdownEntity, pev_nextthink, get_gametime( ) );
set_task( 5.0, "task__ChangeMap" );
}
return 1;
}
public task__SelectRandomMap( ) {
g_iRandomMap = random_num( 0, sizeof( g_szMapNames ) - 1 );
ColorChat( 0, Red, "El mapa elegido aleatoriamente fue: ^3%s^1.", g_szMapNames[ g_iRandomMap ][ Map_Name ] );
set_task( 2.5, "task__SetThink" );
return 1;
}
public task__SetThink( ) {
g_iCountdownType = Countdown_Normal;
g_iCountdown = 5;
set_pev( g_iCountdownEntity, pev_nextthink, get_gametime( ) );
set_task( 5.0, "task__ChangeRandomMap" );
}
public task__ChangeMap( ) {
server_cmd( "changelevel ^"%s^"", g_szMapNames[ g_iMapWinner ][ Map_RealName ] );
remove_task( );
return 1;
}
public task__ChangeRandomMap( ) {
server_cmd( "changelevel ^"%s^"", g_szMapNames[ g_iRandomMap ][ Map_RealName ] );
remove_task( );
return 1;
}