How can i make a reaction test script?
#1

How can i make a reaction test script?
Like when the screen says random words
When the player types it first he gets prizes
Reply
#2

Here you go : https://sampforum.blast.hk/showthread.php?tid=150274
Reply
#3

Quote:
Originally Posted by Avi57
Посмотреть сообщение
Just made the following script to make you understand, as I think it's the easiest way of making this.

pawn Код:
// ===== at top ====== //

new ReactionTestAlph[ ][ ] =    {
                                    "A", "B", "C" // you can add yours
                                };
new bool:IsReactionTestStarted = false,
    ReactionTimeTicker = 0,
    gSaveRandomWords[ 8 ];
   
// ===== -- ====== //

SetTimer( "ReactionTimer", 1000, true ); // in Gamemode init

forward ReactionTimer( );
public ReactionTimer( ) // anywhere in script
{
    ReactionTimerTicker++;
   
    switch( ReactionTimerTicker )
    {
        case 120: // 2 minutes (60 + 60 = 120)
        {
            new szStr[ 128 ];
            if( !IsReactionTestStarted )
            {
                format( gSaveRandomWords, sizeof( gSaveRandomWords ), "%s%s%s", ReactionTestAlph[ random( sizeof( ReactionTestAlph ) ) ], ReactionTestAlph[ random( sizeof( ReactionTestAlph ) ) ], ReactionTestAlph[ random( sizeof( ReactionTestAlph ) ) ] );
               
                format( szStr, sizeof( szStr ), "RT: First one to type %s will be the winner", gSaveRandomWords );
                SendClientMessageToAll( -1, szStr );
               
                IsReactionTestStarted = true;
                ReactionTimerTicker = 0;
            }
            else
            {
                SendClientMessageToAll( -1, "No one was able to do the reaction test, lazy people" );
               
                IsReactionTestStarted = false;
               
                ReactionTimerTicker = 90; // 30 seconds
               
            }
        }
    }
}

public OnPlayerText( playerid, text[ ] )
{
    switch( IsReactionTestStarted )
    {
        case true:
        {
            if( !strcmp( gSaveRandomWords, text ) )
            {
                new ReactionString[ 128 ];
                format( ReactionString, sizeof( ReactionString ), "RT: %s has won the reaction test", PlayerName( playerid ) );
                SendClientMessageToAll( COLORS, ReactionString );

                printf( "%s", ReactionString );
               
                ReactionTimerTicker = 60; // 60 seconds

                IsReactionTestStarted = false;
            }
        }
    }
    return 1;
}

stock PlayerName( playerid ) // anywhere in script
{
    new szName[ MAX_PLAYER_NAME ];
    GetPlayerName( playerid, szName, sizeof( szName ) );
    return szName;
}
Reply
#4

Here is my quick try,


Код:
#include <a_samp>
#define TIME 3
#define MINIMUM_VALUE 2000000
#define MAXIMUM_VALUE 8000000
#define MINIMUM_PRIZE 5000
#define MAXIMUM_PRIZE 20000
#define MINIMUM_SCORE 1
#define MAXIMUM_SCORE 7

new CONTEST_PRIZE;
new CONTEST_SCORE;
new ContestAnswer = -1;
forward NewContest();
forward OnPlayerWinContest(playerid);
public OnFilterScriptInit()
{
	SetTimer("NewContest",(1000*60*TIME),1);
	return 1;
}

public OnPlayerText(playerid, text[])
{
	if(strval(text) == ContestAnswer && ContestAnswer != -1)
	{
		OnPlayerWinContest(playerid);
	}
	return 1;
}

public NewContest()
{
	new string [128];
	ContestAnswer = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
	format(string,sizeof string,"A new contest has started. Whoever types %d first, wins $%d and %d score.",ContestAnswer,CONTEST_PRIZE,CONTEST_SCORE);
	SendClientMessageToAll(0x00FFFFFF,string);
	return 1;
}

public OnPlayerWinContest(playerid)
{
	new pName[MAX_PLAYER_NAME],string[128];
	GetPlayerName(playerid,pName,sizeof pName);
	format(string,sizeof string,"Player %s has won the contest and has won $%d AND %d score!",pName,CONTEST_PRIZE,CONTEST_SCORE);
	SendClientMessageToAll(0x00FFFFFF,string);
	CONTEST_PRIZE = MINIMUM_PRIZE+random(MAXIMUM_PRIZE-MINIMUM_PRIZE);
	GivePlayerMoney(playerid,CONTEST_PRIZE);
	CONTEST_SCORE = MINIMUM_SCORE+random(MAXIMUM_SCORE-MINIMUM_SCORE);
	SetPlayerScore(playerid, GetPlayerScore(playerid) + CONTEST_SCORE);
	ContestAnswer = -1;
	return 1;
}
Reply
#5

Also instead of doing like
pawn Код:
new ReactionTestAlph[ ][ ] =    {
                                    "A", "B", "C" // you can add yours
                                };
We can do like
pawn Код:
new str[20],c;
for(new i=0;i<20;++i)
{
    c = random(3);
    if(c == 0) str[i] = random(10) + 48;//For numbers
    if(c == 1) str[i] = random(26) + 65;//For upper case A-Z
    if(c == 2) str[i] = random(26) + 97;//For lower case a-z
   
    c = random(2);
    if(c == 1 && i>=1)//here i>=1 means that reaction test will have min 1 digit
    {
        str[i]='\0';
        break;
    }
}
str[19] = '\0';
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)