Raised This Month: $ Target: $400
 0% 

Buttons in order


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-03-2011 , 23:38   Buttons in order
Reply With Quote #1

I'm trying to make a plugin where the user has to try to press certain buttons in a certain order (Order is random each time). I'm not sure how to go about either of these things. I'm not sure how I would get a random sequence of buttons, nor how to make sure that they press it in the wrong order, and they have to start over from the beginning if they get it wrong.

Any suggestions?
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-03-2011 , 23:46   Re: Buttons in order
Reply With Quote #2

Are you talking about buttons in a map?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 04-04-2011 , 09:33   Re: Buttons in order
Reply With Quote #3

Sorry, I meant buttons like IN_ATTACK and IN_JUMP, etc..
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-06-2011 , 09:01   Re: Buttons in order
Reply With Quote #4

You can create an array containing those button bits and then randomize the items to get your random sequence. You can then check the buttons pressed at FM_CmdStart. When I have time I'll try to put this together for you.
__________________
Bugsy is offline
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
Reply



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