PDA

View Full Version : Reaction test


CroM256
08/03/2014, 03:02 PM
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);

RenovanZ
08/03/2014, 03:07 PM
Try using strcmp instead of strfind.

CroM256
08/03/2014, 03:22 PM
if(strcmp(text, result, true) != -1)
that?
Now everything I type is true and it says that I won reaction test

RenovanZ
08/03/2014, 03:27 PM
Or you can compare the value instead of string.
Like this.

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;
}

Matess
08/03/2014, 03:27 PM
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)

Misiur
08/03/2014, 03:28 PM
If you have single number to put into string use valstr:
valstr(result, reaction);
Maximum number length is 11, so you need only 12 cells for result size, not 128.

As for your problem:
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"

CroM256
08/03/2014, 03:39 PM
Works now, thank you :)