Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*------------------------*\
- | Maths script by Zezombia |
- \*------------------------*/
- #include <a_samp>
- #define yellow 0xFFFF00AA
- #define red 0xFF0000AA
- #define green 0x33FF33AA
- forward Maths();
- new answer;
- new answered;
- new score;
- new timer;
- new timerset;
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp("/answer", cmd, true) == 0)
- {
- new tmp[256], cmdid, string[256], pname[MAX_PLAYER_NAME];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) return SendClientMessage(playerid, red, "USAGE: /Answer [answer]");
- cmdid = strval(tmp);
- if(cmdid < answer || cmdid > answer)
- {
- SendClientMessage(playerid, red, "Wrong answer!");
- }
- if(cmdid == answer && answered == 0)
- {
- GetPlayerName(playerid, pname, sizeof(pname));
- format(string, sizeof(string), "%s has won %d score for answering the math question '%d'!", pname, score, cmdid);
- SendClientMessageToAll(green, string);
- GivePlayerMoney(playerid, 10000);
- answered = 1;
- SetPlayerScore(playerid, GetPlayerScore(playerid) + score);
- score = 0;
- return 1;
- }
- else if(cmdid == answer && answered == 1)
- {
- SendClientMessage(playerid, red, "To late!");
- }
- return 1;
- }
- if (strcmp("/startmaths", cmd, true) == 0)
- {
- if(IsPlayerAdmin(playerid) == 0) return SendClientMessage(playerid, red, "You are not an RCON admin");
- new tmp[256], cmdid, string[256];
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) return SendClientMessage(playerid, red, "USAGE: /Startmaths [timer (seconds)]");
- cmdid = strval(tmp);
- KillTimer(timer);
- timerset = cmdid * 1000;
- timer = SetTimer("Maths", timerset, 1);
- format(string, sizeof(string), "Maths started, timer set to every %d seconds", cmdid);
- SendClientMessage(playerid, yellow, string);
- return 1;
- }
- if (strcmp("/stopmaths", cmd, true) == 0)
- {
- if(IsPlayerAdmin(playerid) == 0) return SendClientMessage(playerid, red, "You are not an RCON admin");
- KillTimer(timer);
- SendClientMessage(playerid, yellow, "Maths stopped");
- return 1;
- }
- return 0;
- }
- public Maths()
- {
- new string[256], addsubtext1[10], addsubtext2[10];
- new temp1;
- new number1 = random(100);
- new number2 = random(100);
- new number3 = random(100);
- new addsubnumb1 = random(2);
- new addsubnumb2 = random(2);
- if(addsubnumb1 == 0)
- {
- score = score + 10;
- format(addsubtext1, sizeof(addsubtext1), "-");
- temp1 = number1 - number2;
- }
- else if(addsubnumb1 == 1)
- {
- score = score + 5;
- format(addsubtext1, sizeof(addsubtext1), "+");
- temp1 = number1 + number2;
- }
- if(addsubnumb2 == 0)
- {
- score = score + 10;
- format(addsubtext2, sizeof(addsubtext2), "-");
- answer = temp1 - number3;
- }
- else if(addsubnumb2 == 1)
- {
- score = score + 5;
- format(addsubtext2, sizeof(addsubtext2), "+");
- answer = temp1 + number3;
- }
- format(string, sizeof(string), "MATHS: %d%s%d%s%d - /answer to answer this question! Worth %d score!", number1, addsubtext1, number2, addsubtext2, number3, score);
- SendClientMessageToAll(yellow, string);
- answered = 0;
- return 1;
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement