Not accurate time in reaction test.
#1

This is a edited version of RyDeR's Reaction Test System, I want to calculate the time in which the player wins the test. I have used GetTickCount(..) but it isn't showing the accurate time, sometimes it shows 16 seconds (Actual 2-3 seconds)
pawn Код:
function ReactionTest()
{
     new
        Length = (random(5) + 3),
        str[128]
     ;
     Cash = (random(4000) + 2000);
     EXP = (random(2)+1);
     timecount = GetTickCount();
     format(Chars, sizeof(Chars), "");
     for (new i = 0; i < Length; i++)
     {
        format(Chars, sizeof(Chars), "%s%s", Chars, Characters[random(sizeof(Characters))][0]);
     }
     format(str, sizeof(str), "Reaction Test :: The first person to type {48D1CC}%s {ADFF2F}wins %d EXP and $%d!", Chars, EXP, Cash);
     SendClientMessageToAll(0xADFF2FFF, str);
     KillTimer(ReactionTimer);
     TestBusy = true;
     SetTimer("ReactionProgress", 30000, 0);
     return 1;
}
pawn Код:
public OnPlayerText(playerid, text[])
{
    switch (TestBusy)
    {
        case true:
        {
             if(!strcmp(Chars, text, false))
             {
                timecount2 = GetTickCount();
                result = timecount2 - timecount;
                new string[140], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));
                format(string, sizeof(string), "Reaction Test :: {%06x}%s(%d) {ADFF2F}has won the reaction test for the phrase {48D1CC}%s {ADFF2F} in %d seconds! +%d XP & $%d!", (GetPlayerColor(playerid) >>> 8), pName, playerid, Chars, result / 1000, EXP, Cash);
                SendClientMessageToAll(0xADFF2FFF, string);
                GivePlayerMoney(playerid, Cash);
                timecount2 = 0;
                timecount = 0;
                SetPlayerScore(playerid, GetPlayerScore(playerid) + EXP);
                ReactionTimer = SetTimer("ReactionTest", 60000, 1);
                TestBusy = false;
            }
        }
    }
    return 1;
}
Reply
#2

use this
pawn Код:
new Float:timetaken=0,timerid;//at top

forward timer();
public timer()
{
timetaken+=0.1;
return 1;
}


timerid=SetTimer("timer",100,true);//this under on command text

KillTimer(timerid);//under when a player wins right at the start
timetaken=0;//under when a player wins at end of code when player wins
so now the time taken will be stored in timetaken in seconds
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)