It's not perfect but it works. I made it only detect the playable buttons (buttons in the array) but I can make it detect all IN_[X] buttons if you want. For example, IN_ATTACK2 is not in the list of playable buttons, if it says "Press Duck" and the player presses Attack2, the plugin will not say "Wrong button pressed." It will however notify you if you press one of the playable buttons.
PHP Code:
#include <amxmodx>
#include <fakemeta>
new const Version[] = "0.1";
const MAXPLAYERS = 32;
enum ButtonInfo
{
ButtonFlag,
ButtonName[ 10 ]
}
new const ButtonData[][ ButtonInfo ] =
{
{ IN_USE , "Use" },
{ IN_JUMP , "Jump" },
{ IN_DUCK , "Duck" },
{ IN_ATTACK , "Attack" },
{ IN_RELOAD , "Reload" },
{ IN_SCORE , "Score" }
};
new ButtonBits = ( IN_USE | IN_JUMP | IN_DUCK | IN_ATTACK | IN_RELOAD | IN_SCORE );
enum PlayerInfo
{
PressIndex,
RandomButtons[ sizeof( ButtonData ) ],
PrevPressed,
bool:CurrentlyPlaying
}
new pi_Data[ MAXPLAYERS + 1 ][ PlayerInfo ];
public plugin_init()
{
register_plugin( "Simon Says" , Version , "bugsy" );
register_forward( FM_CmdStart , "fw_FMCmdStart" );
register_clcmd( "say /start" , "InitiateGame" );
}
public InitiateGame( id )
{
new iRandomNum , iRandomIndex , iRandomBits;
for ( new i = 0 ; i < sizeof( ButtonData ) ; i++ )
iRandomBits |= ( 1 << i );
while ( iRandomBits )
{
iRandomNum = random( sizeof( ButtonData ) );
if ( iRandomBits & ( 1 << iRandomNum ) )
{
pi_Data[ id ][ RandomButtons ][ iRandomIndex++ ] = iRandomNum;
iRandomBits &= ~( 1 << iRandomNum );
}
}
pi_Data[ id ][ CurrentlyPlaying ] = true;
pi_Data[ id ][ PrevPressed ] = 0;
pi_Data[ id ][ PressIndex ] = 0;
client_print( id , print_chat , ".: Simon Says - Starting :." );
client_print( id , print_chat , "Press %s" , ButtonData[ pi_Data[ id ][ RandomButtons ][ 0 ] ][ ButtonName ] );
}
public fw_FMCmdStart( id , handle , seed )
{
new iPressed = get_uc( handle , UC_Buttons ) & ButtonBits;
if ( pi_Data[ id ][ CurrentlyPlaying ] && iPressed && ( iPressed != pi_Data[ id ][ PrevPressed ] ) )
{
if ( iPressed == ButtonData[ pi_Data[ id ][ RandomButtons ][ pi_Data[ id ][ PressIndex ] ] ][ ButtonFlag ] )
{
client_print( id , print_chat , "Good! You pressed %s!" , ButtonData[ pi_Data[ id ][ RandomButtons ][ pi_Data[ id ][ PressIndex ] ] ][ ButtonName ] );
if ( ++pi_Data[ id ][ PressIndex ] == sizeof( ButtonData ) )
{
client_print( id , print_chat , "Good work, you're all done!" );
pi_Data[ id ][ CurrentlyPlaying ] = false;
}
else
{
client_print( id , print_chat , "Now press %s" , ButtonData[ pi_Data[ id ][ RandomButtons ][ pi_Data[ id ][ PressIndex ] ] ][ ButtonName ] );
}
}
else
{
pi_Data[ id ][ PressIndex ] = 0;
client_print( id , print_chat , "You pressed a button out of order! Starting over." );
client_print( id , print_chat , "Press %s" , ButtonData[ pi_Data[ id ][ RandomButtons ][ pi_Data[ id ][ PressIndex ] ] ][ ButtonName ] );
}
pi_Data[ id ][ PrevPressed ] = iPressed;
}
}
__________________