Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- /* This filterscript is made by Smokey. You can use it if you respect the following conditions:
- - You do not remove this text.
- - You do not remove the credits.
- Credits: Smokey - For the filterscript
- Y_Less - For minrand function
- - WhoEver Made the strtok function
- */
- #define COLOR_RED 0xFF0000AA
- #define COLOR_GREY 0xAFAFAFAA
- public OnFilterScriptInit()
- {
- SetTimer("MathContestRandom", 5*60000, 1);
- printf("Smokey's Math Contest Filterscript Loaded.");
- }
- new math1;
- new math2;
- new math3;
- new mathanswer;
- new IsMath;
- forward MathContestMinus();
- public MathContestMinus()
- {
- new string[128];
- math1 = minrand(100, 300);
- math2 = minrand(50, 99);
- math3 = random(50);
- mathanswer = math1 - math2 - math3;
- format(string, sizeof(string), "{66CCCC}SERVER:{FFFFFF} The first one who answers (solve) this {FF002B}%d-%d-%d{F2C80C} wins $2,500", math1, math2, math3);
- SendClientMessageToAll(0x66CCCCCC, string);
- IsMath = 1;
- SetTimer("MathContestEnd", 2*60000, 0);
- return 1;
- }
- forward MathContestPlus();
- public MathContestPlus()
- {
- new string[128];
- math1 = minrand(100, 260);
- if(math1 >= 200)
- {
- math2 = minrand(30, 50);
- }
- else if(math1 < 200)
- {
- math2 = minrand(50, 99);
- }
- math3 = random(50);
- mathanswer = math1 + math2 + math3;
- format(string, sizeof(string), "SERVER:{FFFFFF} The first one who answers (solve) this {FF3333}%d+%d+%d{FFCC00} wins $2,500", math1, math2, math3);
- SendClientMessageToAll(0x66CCCCCC, string);
- IsMath = 1;
- SetTimer("MathContestEnd", 2*60000, 0);
- return 1;
- }
- stock minrand(min, max)
- {
- return random(max - min) + min;
- }
- forward MathContestEnd();
- public MathContestEnd()
- {
- if(IsMath == 1)
- {
- new string[128];
- format(string, sizeof(string), "SERVER: {FFFFFF}No one won the Math Contest the answer is {FF3333}'%d'", mathanswer);
- SendClientMessageToAll(0x66CCCCCC, string);
- IsMath = 0;
- math1 = 0;
- math2 = 0;
- math3 = 0;
- mathanswer = 0;
- }
- return 1;
- }
- forward MathContestRandom();
- public MathContestRandom()
- {
- new randomvar = 0;
- new rand = random(2);
- randomvar = rand;
- if(randomvar == 0)
- {
- MathContestMinus();
- }
- if(randomvar == 1)
- {
- MathContestPlus();
- }
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- new pnamee[MAX_PLAYER_NAME];
- new tmp[128];//era 256
- new string[155];//era 256
- if(IsMath == 1)
- {
- new idx;
- tmp = strtok(text, idx);
- new result = strval(tmp);
- if(mathanswer == result)
- {
- GivePlayerMoney(playerid, 2500);
- GetPlayerName(playerid, pnamee, MAX_PLAYER_NAME);
- format(string, sizeof(string), "SERVER: {FF002B}%s(%d){FFFFFF} won the {F2C80C}Math Contest{FFFFFF}, He/She won the {F2C80C}$2500{FFFFFF} [ Answer: %d ]",pnamee, playerid, mathanswer);
- SendClientMessageToAll(0x66CCCCCC, string);
- IsMath = 0;
- mathanswer = 0;
- math1 = 0;
- math2 = 0;
- math3 = 0;
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new string[128];
- new cmd[128];
- new idx;
- cmd = strtok(cmdtext, idx);
- //---------------------------------------------------------------------------------------------------------------------------------------
- if(strcmp(cmd, "/startmath", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if(IsPlayerAdmin(playerid))
- {
- MathContestRandom();
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED, "<> You are not authorized to use this command!");
- }
- }
- return 1;
- }
- if(strcmp(cmd, "/mathanswer", true) == 0)
- {
- if(IsPlayerConnected(playerid))
- {
- if(IsPlayerAdmin(playerid))
- {
- format(string, sizeof(string), "math answer: %d", mathanswer);
- SendClientMessage(playerid, COLOR_GREY, string);
- }
- else
- {
- SendClientMessage(playerid, COLOR_GREY, "<> You are not authorized to use this command!");
- }
- }
- return 1;
- }
- return 0;
- }
- 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