Reaction Test help -
BlackWolf120 - 30.01.2011
hi,
im trying to code a reaction test.
I wrote down 50 words and 2 words of them are random chosen + combined and displayed via SendClientMessage as soon as a test starts.
Nearly everything works except this:
The 2 words are combined and stored in the variable "answer" but i dont know how to check if the answer that has been typed in is correct?
Now i just get an argument type mismatch.
pawn Код:
new cmdr[100],idxr;
cmdr = strtok(cmdtext, idxr);
if (strcmp("/react", cmdr, true) == 0)
{
new tmp[256], cmdid, string[256], pname[MAX_PLAYER_NAME];
tmp = strtok(cmdtext, idxr);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xAA3333AA, "Usage: /react [Answer]");
cmdid = strval(tmp);
if(!strval(answer,cmdr))//heres the problem
{
SendClientMessage(playerid, 0xAA3333AA, "The answer was not right!");
}
if(cmdid == answer && answered == 0)
{
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has won the Reaction Test!", pname);
SendClientMessageToAll(0xAA3333AA, string);
GivePlayerMoney(playerid, 2000);
Re: Reaction Test help -
BlackWolf120 - 30.01.2011
To explain some better:
The right answer is stored in: answer
E.g. if the answers was a number e.g. 5
itd look like this:
pawn Код:
if(cmdid < answer || cmdid > answer)//so this checks if the answer is biger or smaller than 5
{
SendClientMessage(playerid, color, "Wrong");
}
else
{
//announce winner...
}
//but how to do it here? with a word? Cause this does not work!
if(!strval(answer,cmdr))
{
SendClientMessage(playerid, 0xAA3333AA, "The answer was not right!");
}
Re: Reaction Test help -
admantis - 30.01.2011
pawn Код:
if(strcmp(cmd, "/answer", true) == 0)
{
if(IsPlayerConnected(playerid))
{
new string[72];
GetPlayerName(playerid, sendername, sizeof(sendername));
tmp = strtok(cmdtext, idx);
theanswer = strval(tmp);
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
new result_len = strlen(result);
if(!result_len)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "USAGE: /answer");
return 1;
}
if (result == answer && answered == 0)
{
format(string,72,"%s has won the reaction test",sendername);
SendClientMessageToAll(0xAA3333AA, string);
GivePlayerMoney(playerid, 2000);
}
}
return 1;
}
And I wouldnt be sure it works. Use sscanf.
Re: Reaction Test help -
iMonk3y - 30.01.2011
I would recommend doing OnPlayerText rather than OnPlayerCommandText :P anyways, here:
editing...
pawn Код:
//On top of your script
new reaction_string[64];
pawn Код:
//On reactiontest
format(reaction_string, sizeof(reaction_string), "%s%s", word1, word2);
format(str, sizeof(str),"** This is a reaction test '%s'", reaction_string);
SendClientMessageToAll(PURPLE, str);
pawn Код:
//OnPlayerText
if(!strcmp(text, reaction_string, true))
//Your codes here
I hope I did everything correct, so I wouldn't have to suck it up while some 'pro' explains me the right way
Edit: You could also do something like this just to get a little advantage, that's all xD
pawn Код:
//Before the actual reactiontest
format(reaction_string, sizeof(reaction_string), "%s%s", word1, word2);
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
if(strcmp(PlayerName(playerid),"BlackWolf120",true)
{
format(str, sizeof(str),"** Next reactiontest in 10 seconds, be prepared! '%s'", reaction_string);
SendClientMessage(playerid, PURPLE, str);
}
}
SetTimer("RealReactionTest", 10000, 0);
Re: Reaction Test help -
Limex - 30.01.2011
If answer is a string, then you would use strcmp.
If it's a integer, just use ==.
Re: Reaction Test help -
admantis - 30.01.2011
Exactly.
EX:
pawn Код:
if (text[0] == answer && answered == 0) {
// announce winner }
else if (text[0] != answer) {
// incorrect answer }
Re: Reaction Test help -
BlackWolf120 - 30.01.2011
ok thx guys

didnt expect that much help at once...
im gonna try it out tomorrow cause now its way too late

thx!!!
regards...
Re: Reaction Test help -
BlackWolf120 - 30.01.2011
still got some probs.
Id be so happy if someone could correct it.
It always says wrong answer but its not wrong!
pawn Код:
//ReactionTest
forward ReactionTest();
new answer;
new answered;
//OnGameModeInit
SetTimer("ReactionTest",900000,true);
//OnPlayerCommandText
new cmdr[100],idxr;
cmdr = strtok(cmdtext, idxr);
if (strcmp("/react", cmdr, true) == 0)
{
new tmp[256], cmdid, string[256], pname[MAX_PLAYER_NAME];
tmp = strtok(cmdtext, idxr);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xAA3333AA, "Usage: /react [Answer]");
cmdid = strval(tmp);
if(cmdid == answer && answered == 0)
{
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has won the Reaction Test!", pname);
SendClientMessageToAll(0xAA3333AA, string);
GivePlayerMoney(playerid, 2000);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 2);
answered = 1;
return 1;
}
else
{
SendClientMessage(playerid, 0xAA3333AA, "Wrong answer!");
}
if(cmdid == answer && answered == 1)
{
SendClientMessage(playerid, 0xAA3333AA, "No Reaction test currently in progress.");
}
return 1;
}
public ReactionTest()
{
new string[256];
//my example words
new word1[][] =
{
{"banan"},
{"team blue"},
{"teamwork"},
{"team red"}
};
new word2[][] =
{
{"sucks"},
{"rules"},
{"go home"},
{"talk to my hand"}
};
new randomtest1 = random(sizeof(word1));
new randomtest2 = random(sizeof(word2));
answer = randomtest1 + randomtest2;
format(string, sizeof(string), "Reaction: %s %s | Type in /react to attempt to solve this Test!", word1[randomtest1],word2[randomtest2]);
SendClientMessageToAll(0xFF0000FF, string);
answered = 0;
return 1;
}
id be so happy about help.
redards....
Re: Reaction Test help -
BlackWolf120 - 31.01.2011
pls someone?
Everything is alright except the /react command.
Cause it always says wrong answer in every case.
Pls someone may look at it?
Re: Reaction Test help -
Jefff - 31.01.2011
pawn Код:
//ReactionTest
forward ReactionTest();
new answer,answered;
//OnGameModeInit
SetTimer("ReactionTest",900000,true);
//OnPlayerCommandText
new cmdr[100],idxr;
cmdr = strtok(cmdtext, idxr);
if(strcmp("/react", cmdr, true) == 0)
{
if(answered) return SendClientMessage(playerid, 0xAA3333AA, "No Reaction test currently in progress.");
new tmp[256];
tmp = strtok(cmdtext, idxr);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xAA3333AA, "Usage: /react [Answer]");
new cmdid = strval(tmp);
if(cmdid == answer)
{
answered = 1;
new pname[24],string[55];
GetPlayerName(playerid, pname, sizeof(pname));
format(string, sizeof(string), "%s has won the Reaction Test!", pname);
SendClientMessageToAll(0xAA3333AA, string);
GivePlayerMoney(playerid, 2000);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 2);
}else SendClientMessage(playerid, 0xAA3333AA, "Wrong answer!");
return 1;
}
public ReactionTest()
{
new string[128];
//my example words
new word1[][] =
{
{"banan"},
{"team blue"},
{"teamwork"},
{"team red"}
};
new word2[][] =
{
{"sucks"},
{"rules"},
{"go home"},
{"talk to my hand"}
};
new randomtest1 = random(sizeof(word1));
new randomtest2 = random(sizeof(word2));
answer = randomtest1 + randomtest2;
format(string, sizeof(string), "Reaction: %s %s | Type in /react to attempt to solve this Test!", word1[randomtest1],word2[randomtest2]);
SendClientMessageToAll(0xFF0000FF, string);
answered = 0;
return 1;
}