Reaction test
#1

Hi, i have problem with reaction test...Everything is fine until I have to write correct answer...example 55+12-45
and i type 22 and nothing happens...
Код:
new reaction;
new reactionmoney;
new result[128];

OnPlayerText:
if(strfind(text, result, true) != -1)
    {
	new string[128];
	new name[24];
	GetPlayerName(playerid, name, sizeof(name));
	format(string, sizeof(string), ""COL_BLUE"%s"COL_WHITE" won reaction test! Result: %d.", name,reaction);
	SendClientMessageToAll(COLOR_GRAY, string);
	SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
	sGivePlayerMoney(playerid, reactionmoney);
    }

public timer:
forward react();
public react()
{
new string[128];
reactionmoney = randomEx(1000, 3000);
new rand1 = randomEx(10, 99);
new rand2 = randomEx(10, 99);
new rand3 = randomEx(10, 99);
reaction = rand1+rand2+rand3;
format(result, sizeof(result), "%d", reaction);
format(string, sizeof(string), ""COL_WHITE"Reaction test | "COL_BLUE"%d - %d + %d "COL_WHITE"| "COL_BLUE"+1 score and $%d", rand1, rand2, rand3, reactionmoney);
SendClientMessageToAll(COLOR_GRAY, string);
return 1;
}

ongamemodeinit:
SetTimer("react", 20000, true);
Reply
#2

Try using strcmp instead of strfind.
Reply
#3

Код:
if(strcmp(text, result, true) != -1)
that?
Now everything I type is true and it says that I won reaction test
Reply
#4

Or you can compare the value instead of string.
Like this.
pawn Код:
new reaction;
new reactionmoney;

OnPlayerText:
if(reaction == strval(text))
    {
    new string[128];
    new name[24];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), ""COL_BLUE"%s"COL_WHITE" won reaction test! Result: %d.", name,reaction);
    SendClientMessageToAll(COLOR_GRAY, string);
    SetPlayerScore(playerid, GetPlayerScore(playerid)+1);
    sGivePlayerMoney(playerid, reactionmoney);
    }

public timer:
forward react();
public react()
{
new string[128];
reactionmoney = randomEx(1000, 3000);
new rand1 = randomEx(10, 99);
new rand2 = randomEx(10, 99);
new rand3 = randomEx(10, 99);
reaction = rand1+rand2+rand3;
format(string, sizeof(string), ""COL_WHITE"Reaction test | "COL_BLUE"%d - %d + %d "COL_WHITE"| "COL_BLUE"+1 score and $%d", rand1, rand2, rand3, reactionmoney);
SendClientMessageToAll(COLOR_GRAY, string);
return 1;
}
Reply
#5

STRCMP
Returns:
Код:
	
-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).
So try if(strcmp(text, result, true) == 0)
Reply
#6

If you have single number to put into string use valstr:
pawn Код:
valstr(result, reaction);
Maximum number length is 11, so you need only 12 cells for result size, not 128.

As for your problem:
pawn Код:
reaction = rand1+rand2+rand3;
Your challange is diffrent from answer, because it is equal to sum of all values, not "a - b + c"

#e: Also
Use !strcmp if you want to allow only reward only messages with exact answer and nothing else. Use strfind if you want to allow responses like: "The answer is 22"
Reply
#7

Works now, thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)