I was learning the language PHP this morning I remembered when I was playing in one of the servers ( RolePlay) ... because a small wrong , lost all my fortune on that server ... so I said why not Make Calculator is simple and easier to use so the players can use calculator within the game without the need to exit to use the calculator in Pc ( Take time )
Image
pawn Код:
CMD:calculator(playerid, params[])
{
new number1,type,number2, string[250];
if(sscanf(params, "iii", number1,type,number2)) return SendClientMessage(playerid, -1, "USAGE: /calculator [number 1] [1 = + | 2 = - | 3 = / | 4 = *] [number 2]");
if(type == 1)
{
format(string, sizeof(string), "Calculator : %d + %d = {FFFFFF}%d" , number1, number2, number1 + number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
if(type == 2)
{
if(number1 < number2)
{
format(string, sizeof(string), "Calculator : %d - %d = {FFFFFF}%d" , number2, number1, number2 - number1);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
else if(number1 > number2)
{
format(string, sizeof(string), "Calculator : %d - %d = {FFFFFF}%d" , number1, number2, number1 - number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
}
if(type == 3)
{
format(string, sizeof(string), "Calculator : %d / %d = {FFFFFF}%d" , number1, number2, number1/number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
if(type == 4)
{
format(string, sizeof(string), "Calculator : %d * %d = {FFFFFF}%d" , number1, number2, number2 * number1);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
return 1;
}
Quote:
Originally Posted by ]Rafaellos[
Instead of if, try to use switch. It's better and faster.
|
Okey mate
...
pawn Код:
CMD:calculator(playerid, params[])
{
new number1,type,number2, string[250];
if(sscanf(params, "iii", number1,type,number2)) return SendClientMessage(playerid, -1, "USAGE: /calculator [number 1] [1 = + | 2 = - | 3 = / | 4 = *] [number 2]");
switch(type)
{
case 0:
{
format(string, sizeof(string), "Calculator : %d + %d = {FFFFFF}%d" , number1, number2, number1 + number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
case 1:
{
if(number1 < number2)
{
format(string, sizeof(string), "Calculator : %d - %d = {FFFFFF}%d" , number2, number1, number2 - number1);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
else if(number1 > number2)
{
format(string, sizeof(string), "Calculator : %d - %d = {FFFFFF}%d" , number1, number2, number1 - number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
}
case 2:
{
format(string, sizeof(string), "Calculator : %d / %d = {FFFFFF}%d" , number1, number2, number1/number2);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
case 3:
{
format(string, sizeof(string), "Calculator : %d * %d = {FFFFFF}%d" , number1, number2, number2 * number1);
SendClientMessage(playerid, COLOR_LIGHTRED, string);
return 1;
}
}
return 1;
}