Here's a basic method of doing it. You will need more code so more than 1 player can run a giveaway at a time.
PHP Code:
#include <amxmodx>
#include <amxmisc>
new const Version[] = "0.1";
const GiveawayTaskID = 9312434;
new bool:g_bActiveGiveaway;
new g_JoinedGiveaway;
public plugin_init()
{
register_plugin( "Giveaway Plugin" , Version , "bugsy" );
register_concmd( "start_giveaway" , "StartGiveaway" , ADMIN_KICK );
register_clcmd( "say /join" , "JoinGiveaway" );
}
#if AMXX_VERSION_NUM < 190
public client_disconnect( id )
#else
public client_disconnected( id )
#endif
{
g_JoinedGiveaway &= ~( 1 << ( id & 31 ) );
}
public StartGiveaway( id , iAccess , iCid )
{
if ( cmd_access( id , iAccess , iCid , 0 ) )
{
g_JoinedGiveaway = 0;
g_bActiveGiveaway = true;
set_task( 6.0 , "EndGiveaway" , GiveawayTaskID );
client_print( 0 , print_chat , "* Say '/join' to join the giveaway!" );
}
return PLUGIN_HANDLED;
}
public JoinGiveaway( id )
{
if ( g_bActiveGiveaway )
{
if ( !( g_JoinedGiveaway & ( 1 << ( id & 31 ) ) ) )
{
client_print( id , print_chat , "* You have joined the giveaway!" );
g_JoinedGiveaway |= ( 1 << ( id & 31 ) );
}
else
{
client_print( id , print_chat , "* You have already joined the giveaway." );
}
}
else
{
client_print( id , print_chat , "* There is no active giveaway." );
}
return PLUGIN_HANDLED;
}
public EndGiveaway()
{
if ( !g_JoinedGiveaway )
{
client_print( 0 , print_chat , "* Giveaway has ended. No players joined the giveaway!" );
}
else
{
new iPlayers[ MAX_PLAYERS + 1 ] , i , szName[ 32 ] , iRandomPlayer;
for ( new id = 1 ; id <= MAX_PLAYERS ; id++ )
{
if ( g_JoinedGiveaway & ( 1 << ( id & 31 ) ) )
{
iPlayers[ i++ ] = id;
}
}
iRandomPlayer = iPlayers[ random( i ) ];
get_user_name( iRandomPlayer , szName , charsmax( szName ) );
client_print( 0 , print_chat , "* Giveaway has ended. Winning player is %s!" , szName );
}
g_bActiveGiveaway = false;
}
__________________