Reaction Test
#1

Hi guys. I have Ryders reaction test, could I get the time of the player who won?

Like this:

« \%s\" has won the reaction test in 0.32131 milliseconds! »

pawn Код:
/*
    Release:
            » Reaction-Test Filterscript

    Author:
            » » RyDeR «

    Last Update:
            » 25/05/2010

    ChangeLog:
            » v0.1a:
                - Initial release

    Bugs:
            » No bugs

    Version:
            » v0.1a

    Functions:
            » /

    Credits:
            » /
*/


#include <a_samp>

#if !defined Loop
#define Loop(%0,%1) \
    for(new %0 = 0; %0 != %1; %0++)
#endif

#if !defined function
#define function%0(%1) \
    forward%0(%1); public%0(%1)
#endif

#if !defined PURPLE
#define PURPLE \
    0xBF60FFFF
#endif

#if !defined GREEN
#define GREEN \
    0x94D317FF
#endif

#if !defined TIME
#define TIME \
    180000
#endif

new
    xCharacters[][] =
    {
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
        "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
        "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
    },
    xChars[16] = "",
    xReactionTimer,
    xCash,
    xScore,
    bool: xTestBusy
;

public OnFilterScriptInit()
{
    xReactionTimer = SetTimer("xReactionTest", TIME, 1);
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(xReactionTimer);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    switch(xTestBusy)
    {
        case true:
        {
            if(!strcmp(xChars, text, false))
            {
                new
                    string[128],
                    pName[MAX_PLAYER_NAME]
                ;
                GetPlayerName(playerid, pName, sizeof(pName));
                format(string, sizeof(string), \%s\" has won the reaction test. »", pName);
                SendClientMessageToAll(GREEN, string);
                format(string, sizeof(string), "« You have earned $%d + %d score points. »", xCash, xScore);
                SendClientMessage(playerid, GREEN, string);
                GivePlayerMoney(playerid, xCash);
                SetPlayerScore(playerid, GetPlayerScore(playerid) + xScore);
                xReactionTimer = SetTimer("xReactionTest", TIME, 1);
                xTestBusy = false;
            }
        }
    }
    return 1;
}

function xReactionProgress()
{
    switch(xTestBusy)
    {
        case true:
        {
            new
                string[128]
            ;
            format(string, sizeof(string), "« No-one won the reaction-test. New one starting in %d minutes. »", (TIME/60000));
            SendClientMessageToAll(PURPLE, string);
            xReactionTimer = SetTimer("xReactionTest", TIME, 1);
        }
    }
    return 1;
}

function xReactionTest()
{
    new
        xLength = (random(8) + 2),
        string[128]
    ;
    xCash = (random(10000) + 20000);
    xScore = (random(2)+1);
    format(xChars, sizeof(xChars), "");
    Loop(x, xLength) format(xChars, sizeof(xChars), "%s%s", xChars, xCharacters[random(sizeof(xCharacters))][0]);
    format(string, sizeof(string), "« Who first types %s wins $%d + %d score points. »", xChars, xCash, xScore);
    SendClientMessageToAll(PURPLE, string);
    KillTimer(xReactionTimer);
    xTestBusy = true;
    SetTimer("xReactionProgress", 30000, 0);
    return 1;
}
Reply
#2

Yes, You just have to create a string and retrieve the time it took, I'll have a look see what i can come up with.
Reply
#3

pawn Код:
/*
    Release:
            » Reaction-Test Filterscript

    Author:
            » » RyDeR «

    Last Update:
            » 25/05/2010

    ChangeLog:
            » v0.1a:
                - Initial release

    Bugs:
            » No bugs

    Version:
            » v0.1a

    Functions:
            » /

    Credits:
            » /
*/


#include <a_samp>

#if !defined Loop
#define Loop(%0,%1) \
    for(new %0 = 0; %0 != %1; %0++)
#endif

#if !defined function
#define function%0(%1) \
    forward%0(%1); public%0(%1)
#endif

#if !defined PURPLE
#define PURPLE \
    0xBF60FFFF
#endif

#if !defined GREEN
#define GREEN \
    0x94D317FF
#endif

#if !defined TIME
#define TIME \
    180000
#endif

new
    xCharacters[][] =
    {
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
        "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
        "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
    },
    xChars[16] = "",
    xReactionTimer,
    xCash,
    xScore,
    bool: xTestBusy,
    xTickCount
;

public OnFilterScriptInit()
{
    xReactionTimer = SetTimer("xReactionTest", TIME, 1);
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(xReactionTimer);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    switch(xTestBusy)
    {
        case true:
        {
            if(!strcmp(xChars, text, false))
            {
                new
                    string[128],
                    pName[MAX_PLAYER_NAME]
                ;
                GetPlayerName(playerid, pName, sizeof(pName));
                format(string, sizeof(string), \%s\" has won the reaction test in %d miliseconds. »", pName, tickcount-xTickCount);
                xTickCount = 0;
                SendClientMessageToAll(GREEN, string);
                format(string, sizeof(string), "« You have earned $%d + %d score points. »", xCash, xScore);
                SendClientMessage(playerid, GREEN, string);
                GivePlayerMoney(playerid, xCash);
                SetPlayerScore(playerid, GetPlayerScore(playerid) + xScore);
                xReactionTimer = SetTimer("xReactionTest", TIME, 1);
                xTestBusy = false;
            }
        }
    }
    return 1;
}

function xReactionProgress()
{
    switch(xTestBusy)
    {
        case true:
        {
            new
                string[128]
            ;
            format(string, sizeof(string), "« No-one won the reaction-test. New one starting in %d minutes. »", (TIME/60000));
            SendClientMessageToAll(PURPLE, string);
            xReactionTimer = SetTimer("xReactionTest", TIME, 1);
        }
    }
    return 1;
}

function xReactionTest()
{
    new
        xLength = (random(8) + 2),
        string[128]
    ;
    xCash = (random(10000) + 20000);
    xScore = (random(2)+1);
    format(xChars, sizeof(xChars), "");
    Loop(x, xLength) format(xChars, sizeof(xChars), "%s%s", xChars, xCharacters[random(sizeof(xCharacters))][0]);
    format(string, sizeof(string), "« Who first types %s wins $%d + %d score points. »", xChars, xCash, xScore);
    SendClientMessageToAll(PURPLE, string);
    KillTimer(xReactionTimer);
    xTestBusy = true;
    SetTimer("xReactionProgress", 30000, 0);
    xTickCount = tickcount();
    return 1;
}
This should do the trick. I did not test it but I only added four lines.
Reply
#4

Instead of editing the script.
How about try Kostas's Reaction Test.
It has all you want. the milesecond result too.
Reply
#5

Quote:
Originally Posted by playbox12
Посмотреть сообщение
pawn Код:
/*
    Release:
            » Reaction-Test Filterscript

    Author:
            » » RyDeR «

    Last Update:
            » 25/05/2010

    ChangeLog:
            » v0.1a:
                - Initial release

    Bugs:
            » No bugs

    Version:
            » v0.1a

    Functions:
            » /

    Credits:
            » /
*/


#include <a_samp>

#if !defined Loop
#define Loop(%0,%1) \
    for(new %0 = 0; %0 != %1; %0++)
#endif

#if !defined function
#define function%0(%1) \
    forward%0(%1); public%0(%1)
#endif

#if !defined PURPLE
#define PURPLE \
    0xBF60FFFF
#endif

#if !defined GREEN
#define GREEN \
    0x94D317FF
#endif

#if !defined TIME
#define TIME \
    180000
#endif

new
    xCharacters[][] =
    {
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
        "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
        "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
    },
    xChars[16] = "",
    xReactionTimer,
    xCash,
    xScore,
    bool: xTestBusy,
    xTickCount
;

public OnFilterScriptInit()
{
    xReactionTimer = SetTimer("xReactionTest", TIME, 1);
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(xReactionTimer);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    switch(xTestBusy)
    {
        case true:
        {
            if(!strcmp(xChars, text, false))
            {
                new
                    string[128],
                    pName[MAX_PLAYER_NAME]
                ;
                GetPlayerName(playerid, pName, sizeof(pName));
                format(string, sizeof(string), \%s\" has won the reaction test in %d miliseconds. »", pName, tickcount-xTickCount);
                xTickCount = 0;
                SendClientMessageToAll(GREEN, string);
                format(string, sizeof(string), "« You have earned $%d + %d score points. »", xCash, xScore);
                SendClientMessage(playerid, GREEN, string);
                GivePlayerMoney(playerid, xCash);
                SetPlayerScore(playerid, GetPlayerScore(playerid) + xScore);
                xReactionTimer = SetTimer("xReactionTest", TIME, 1);
                xTestBusy = false;
            }
        }
    }
    return 1;
}

function xReactionProgress()
{
    switch(xTestBusy)
    {
        case true:
        {
            new
                string[128]
            ;
            format(string, sizeof(string), "« No-one won the reaction-test. New one starting in %d minutes. »", (TIME/60000));
            SendClientMessageToAll(PURPLE, string);
            xReactionTimer = SetTimer("xReactionTest", TIME, 1);
        }
    }
    return 1;
}

function xReactionTest()
{
    new
        xLength = (random(8) + 2),
        string[128]
    ;
    xCash = (random(10000) + 20000);
    xScore = (random(2)+1);
    format(xChars, sizeof(xChars), "");
    Loop(x, xLength) format(xChars, sizeof(xChars), "%s%s", xChars, xCharacters[random(sizeof(xCharacters))][0]);
    format(string, sizeof(string), "« Who first types %s wins $%d + %d score points. »", xChars, xCash, xScore);
    SendClientMessageToAll(PURPLE, string);
    KillTimer(xReactionTimer);
    xTestBusy = true;
    SetTimer("xReactionProgress", 30000, 0);
    xTickCount = tickcount();
    return 1;
}
This should do the trick. I did not test it but I only added four lines.
Man close enough
Код:
error 076: syntax error in the expression, or invalid function call
Line
Код:
format(string, sizeof(string), "« \%s\" has won the reaction test in %d miliseconds »", pName, tickcount-xTickCount);
@romel but this is better for me.

@deal or die just like what plaxbox did?
Reply
#6

Hah, it's still morning. My bad swap this line.

pawn Код:
format(string, sizeof(string), \%s\" has won the reaction test in %d miliseconds »", pName, tickcount()-xTickCount);
Reply
#7

Quote:
Originally Posted by playbox12
Посмотреть сообщение
Hah, it's still morning. My bad swap this line.

pawn Код:
format(string, sizeof(string), \%s\" has won the reaction test in %d miliseconds »", pName, tickcount()-xTickCount);
Thanks playbox! It works, and lastly it is possible to add decimal like this the (0.) 0.4123 milliseconds!
Reply
#8

You won't be able to complete the test so fast. 1ms is 1/10 of a second. That's like blinking once.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)