Skip to content

Instantly share code, notes, and snippets.

@ertrzyiks
Last active August 29, 2015 13:56
Show Gist options
  • Save ertrzyiks/8891563 to your computer and use it in GitHub Desktop.
Save ertrzyiks/8891563 to your computer and use it in GitHub Desktop.
Let players vote for boss!
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Vote for Boss"
#define VERSION "1.1.0"
#define AUTHOR "R3X"
#define BOSS_LIMIT_DURATION 2 * 60 * 60
new giBossLimitTime = 0;
new const gszTmp[] = "boss-timestmap.tmp";
new bool:gbVoted[33];
new bool:gbVoting = true;
public plugin_init ()
{
register_plugin( PLUGIN, VERSION, AUTHOR );
register_clcmd( "say /boss", "cmdBoss" );
set_task(360.0, "taskAnnouncement", 2562345, "", 0, "b");
}
public plugin_cfg ()
{
if ( file_exists( gszTmp ) )
{
giBossLimitTime = getTimestamp();
}
}
public cmdBoss ( id )
{
new diff = get_systime( - BOSS_LIMIT_DURATION ) - giBossLimitTime;
if ( diff < 0 )
{
client_print( id, print_chat, "Nastepne glosowanie na bossa mozliwe za %d sekund", -diff );
return PLUGIN_CONTINUE;
}
if ( !gbVoting )
{
client_print( id, print_chat, "Too late :(");
return PLUGIN_CONTINUE;
}
gbVoted[ id ] = true;
new iVotes = getVotesFor();
new iRequired = getVotesRequired();
new iRemaining = iRequired - iVotes;
new szName[32]
get_user_name( id, szName, 31 );
if ( iRemaining > 0)
{
client_print( 0, print_chat, "Gracz %s zaglosowal na bitwe z bossem, potrzeba jeszcze %d glosow", szName, iRemaining );
}
else
{
client_print( 0, print_chat, "Gracz %s zaglosowal na bitwe z bossem", szName );
}
checkVotes();
return PLUGIN_CONTINUE;
}
public client_connect ( id )
{
gbVoted[ id ] = false;
}
public client_disconnect ( id )
{
gbVoted[ id ] = false;
}
public taskAnnouncement()
{
client_print( 0, print_chat, "Type /boss to vote for Boss!" );
}
getVotesFor()
{
new iVotes = 0;
for( new id = 1; id <= 32; id++ )
{
if ( gbVoted[ id ] )
{
iVotes++;
}
}
return iVotes;
}
getVotesRequired()
{
new iPlayersNum = get_playersnum();
return (iPlayersNum + 1) / 2;
}
checkVotes ( )
{
new iVotes = getVotesFor();
new iRequired = getVotesRequired();
if ( iVotes >= iRequired)
{
gbVoting = false;
setTimestamp( get_systime() );
onBossVoted();
}
}
onBossVoted()
{
client_print( 0, print_chat, "BOSS!!");
}
getTimestamp()
{
new timestamp;
new fp = fopen( gszTmp, "r" );
fread ( fp, timestamp, BLOCK_INT );
fclose( fp );
return timestamp;
}
setTimestamp( timestamp )
{
new fp = fopen( gszTmp, "w" );
fwrite( fp, timestamp, BLOCK_INT );
fclose( fp );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment