19.04.2011, 00:19
I was bored, this isn't exactly what you wanted (it was at first but i improvised) its like a quiz script. You will need sscanf properly installed and zcmd too. (if you wana use this) I know a solution has been posted but i'll post anyway so i don't feel like i'v wasted my time. NOT TESTED
EDIT: I just realised this is actually completely not what you asked for sorry, have it anyway if u want.
pawn Код:
#define FILTERSCRIPT
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define QUESTION_TIME (30*1000)
new bool:gQuestionActive;
new gQuestionAnswer[128];
new bool:gAnswerIsNumber;
new gNumberAnswer = -1;
new gAnswerTimer;
No_Answer(const zAnswer[]);
SendQuestionToPlayers(const zQuestion[], const zAnswer[])
{
new
qStr[128];
gQuestionActive = true;
format(gQuestionAnswer, 128, "%s", zAnswer);
if(isnumeric(gQuestionAnswer))
{
gAnswerIsNumber = true;
gNumberAnswer = strval(gQuestionAnswer);
}
format(qStr, 128, "| Quiz |: %s?", zQuestion);
SendClientMessageToAll(0x00FF00AA, qStr);
gAnswerTimer = SetTimerEx("No_Answer", QUESTION_TIME, false, "s", gQuestionAnswer);
}
public No_Answer(const zAnswer[])
{
new
aStr[128] = "No-body answered correctly, the answer was ";
strcat(aStr, zAnswer);
SendClientMessageToAll(0x00FF00AA, aStr);
gQuestionActive = false;
gAnswerIsNumber = false;
gNumberAnswer = -1;
strdel(gQuestionAnswer, 0, 128);
}
public OnPlayerText(playerid, text[])
{
if(gQuestionActive)
{
if(!gAnswerIsNumber)
{
if(!strcmp(text, gQuestionAnswer))//player typed the correct answer
{
//give player money or something else
gQuestionActive = false;
gAnswerIsNumber = false;
gNumberAnswer = -1;
strdel(gQuestionAnswer, 0, 128);
KillTimer(gAnswerTimer);
}
}
else
{
if(strval(text) == gNumberAnswer)//player typed the correct answer
{
//give player money or something else
gQuestionActive = false;
gAnswerIsNumber = false;
gNumberAnswer = -1;
strdel(gQuestionAnswer, 0, 128);
KillTimer(gAnswerTimer);
}
}
}
return 1;
}
//example command
COMMAND:ask(playerid, params[])
{
new zQuestion[128], zAnswer[128];
if(sscanf(params, "s[128]s[128]", zQuestion, zAnswer)) return SendClientMessage(playerid, 0x00FF00AA, "ERROR: Usage /ask [question][answer]");
else
SendQuestionToPlayers(zQuestion, zAnswer);
return 1;
}
stock isnumeric(str[])// ******
{
new
ch,
i;
while ((ch = str[i++])) if (ch < '0' || ch > '9') return 0;
return 1;
}