AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Buttons in order (https://forums.alliedmods.net/showthread.php?t=154184)

nikhilgupta345 04-03-2011 23:38

Buttons in order
 
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?

Exolent[jNr] 04-03-2011 23:46

Re: Buttons in order
 
Are you talking about buttons in a map?

nikhilgupta345 04-04-2011 09:33

Re: Buttons in order
 
Sorry, I meant buttons like IN_ATTACK and IN_JUMP, etc..

Bugsy 04-06-2011 09:01

Re: Buttons in order
 
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 04-06-2011 21:20

Re: Buttons in order
 
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;
    }




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

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