Raised This Month: $ Target: $400
 0% 

Buttons in order


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-06-2011 , 21:20   Re: Buttons in order
Reply With Quote #5

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,
    
ButtonName10 ]
}
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,
    
RandomButtonssizeofButtonData ) ],
    
PrevPressed,
    
bool:CurrentlyPlaying
}
new 
pi_DataMAXPLAYERS ][ PlayerInfo ];

public 
plugin_init()
{
    
register_plugin"Simon Says" Version "bugsy" );

    
register_forwardFM_CmdStart "fw_FMCmdStart" );
    
register_clcmd"say /start" "InitiateGame" );
}

public 
InitiateGameid )
{
    new 
iRandomNum iRandomIndex iRandomBits;
    
    for ( new 
sizeofButtonData ) ; i++ )
        
iRandomBits |= ( << );

    while ( 
iRandomBits )
    {
        
iRandomNum randomsizeofButtonData ) );

        if ( 
iRandomBits & ( << iRandomNum ) )
        {
            
pi_Dataid ][ RandomButtons ][ iRandomIndex++ ] = iRandomNum;
            
iRandomBits &= ~( << iRandomNum );
        }
    }

    
pi_Dataid ][ CurrentlyPlaying ] = true;
    
pi_Dataid ][ PrevPressed ] = 0;
    
pi_Dataid ][ PressIndex ] = 0;
    
    
client_printid print_chat ".: Simon Says - Starting :." );
    
client_printid print_chat "Press %s" ButtonDatapi_Dataid ][ RandomButtons ][ ] ][ ButtonName ] );
}    

public 
fw_FMCmdStartid handle seed )
{
    new 
iPressed get_uchandle UC_Buttons ) & ButtonBits;

    if ( 
pi_Dataid ][ CurrentlyPlaying ] && iPressed && ( iPressed != pi_Dataid ][ PrevPressed ] ) )
    {
        if ( 
iPressed == ButtonDatapi_Dataid ][ RandomButtons ][ pi_Dataid ][ PressIndex ] ] ][ ButtonFlag ] ) 
        {    
            
client_printid print_chat "Good! You pressed %s!" ButtonDatapi_Dataid ][ RandomButtons ][ pi_Dataid ][ PressIndex ] ] ][ ButtonName ] );
            
            if ( ++
pi_Dataid ][ PressIndex ] == sizeofButtonData ) )
            {
                
client_printid print_chat "Good work, you're all done!" );
                
pi_Dataid ][ CurrentlyPlaying ] = false;
            }
            else
            {
                
client_printid print_chat "Now press %s" ButtonDatapi_Dataid ][ RandomButtons ][ pi_Dataid ][ PressIndex ] ] ][ ButtonName ] );
            }
        }
        else
        {
            
pi_Dataid ][ PressIndex ] = 0;
            
            
client_printid print_chat "You pressed a button out of order! Starting over." );
            
client_printid print_chat "Press %s" ButtonDatapi_Dataid ][ RandomButtons ][ pi_Dataid ][ PressIndex ] ] ][ ButtonName ] );
        }
        
        
pi_Dataid ][ PrevPressed ] = iPressed;
    }

__________________

Last edited by Bugsy; 04-06-2011 at 23:48.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode