• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] optimize the code?
#1
You can improve this script or leave it like this
#include <a_samp>

#define? TIME? ? ? ? ? ? 1? //When the contest will start (Minutes)
#define? PRIZE? ? 3000 //Reward ($$$) when win in Math Contest
#define? PRIZESCORE? ? ? 5? //Reward (Score) when win in Math Contest

new answer;
new endm = 0;
new no1, no2, no3;
new typem = -1;
new timermath;
new timermath2;
new str[128];

forward Math();
forward MathEnd();

#define COLOR_YELLOW? ? 0xFFFF00FF

#define white? ? ? ? ? ? "{FFFFFF}"
#define red? ? ? ? ? ? ? "{FF002B}"
#define orange? ? ? ? ? "{F2C80C}"

#define FILTERSCRIPT
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
print("\n");
print("* Math System by BuzZ *");
print("* Loaded *");
print("\n");
typem = -1;
endm = 0;
timermath = SetTimer("Math", 1000*60*TIME, true);
return 1;
}

public OnFilterScriptExit()
{
print("\n");
print("* Math System by BuzZ *");
print("* Unloaded *");
print("\n");
typem = -1;
endm = 0;
KillTimer(timermath);
return 1;
}

#endif

public Math()
{
typem = random(2);
no1 = random(600);
no2 = random(50);
no3 = random(100);

endm = 1;
switch(typem)
{
case 0:
{
? ? answer = no1 no2 no3;
format(str, sizeof(str), "MATH: "white"The first one who answers (solve) this "red"%d%d%d "orange"wins $3,000 5 score", no1, no2, no3);
SendClientMessageToAll(COLOR_YELLOW, str);
}
case 1:
{
answer = no1 - no2 - no3;
format(str, sizeof(str), "MATH: "white"The first one who answers (solve) this "red"%d-%d-%d "orange"wins $3,000 5 score", no1, no2, no3);
SendClientMessageToAll(COLOR_YELLOW, str);
}
case 2:
{
answer = no1 * no2 * no3;
format(str, sizeof(str), "MATH: "white"The first one who answers (solve) this "red"%dx%dx%d "orange"wins $3,000 5 score", no1, no2, no3);
SendClientMessageToAll(COLOR_YELLOW, str);
}
}
SendClientMessageToAll(-1, "Math will end on 30 seconds!");
timermath2 = SetTimer("MathEnd", 1000*30, false);
return 1;
}

public MathEnd()
{
switch(typem)
{
case 0:
{
format(str, sizeof(str), "MATH: "white"No one won the Math Contest the answer is '%d'", answer);
SendClientMessageToAll(COLOR_YELLOW, str);
}
case 1:
{
format(str, sizeof(str), "MATH: "white"No one won the Math Contest the answer is '%d'", answer);
SendClientMessageToAll(COLOR_YELLOW, str);
}
case 2:
{
format(str, sizeof(str), "MATH: "white"No one won the Math Contest the answer is '%d'", answer);
SendClientMessageToAll(COLOR_YELLOW, str);
}
}
endm = 0;
KillTimer(timermath2);
return 1;
}

public OnPlayerText(playerid, text[])
{
if(strval(text) == answer && endm == 1)
{
? ? format(str, sizeof(str), "MATH: %s(%d) won the Math Contest, He/She won the $%d %i score [ Answer: %d ]", GetName(playerid), playerid, PRIZE, PRIZESCORE, answer);
? ? SendClientMessageToAll(COLOR_YELLOW, str);
? ? GivePlayerMoney(playerid, PRIZE);
? ? SetPlayerScore(playerid, GetPlayerScore(playerid) PRIZESCORE);
? ? KillTimer(timermath2);
? ? endm = 0;
? ? return 0;
}
return 1;
}

You can improve this script or leave it like this? ??
  Reply


Forum Jump: