[FilterScript] small Calculator
#1

Hi guys
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;
}
Reply
#2

Nice FS.
Reply
#3

Really easy but you should make the arithmetic operators a string.
Reply
#4

Instead of if, try to use switch. It's better and faster.
Reply
#5

I just made this. Don't know if it works. But it is more user-friendly.

pawn Код:
CMD:calculate(playerid, params)
{
    new num1, operation[1], num2;
    if(sscanf(params, "ici", num1, operation, num2)) return SendClientMessage(playerid, -1, "USAGE: /calculate [number1] [+,-,*,/] [number2]");
    new str[128];
    if(!strcmp("+", operation)) format(str, sizeof(str), "%i added to %i equals %i", num1, num2, num1 + num2);
    else if(!strcmp("-", operation)) format(str, sizeof(str), "%i subtracted from %i equals %i", num2, num1, num1 - num2);
    else if(!strcmp("*", operation)) format(str, sizeof(str), "%i multiplied by %i equals %i", num1, num2, num1 * num2);
    else if(!strcmp("/", operation)) format(str, sizeof(str), "%i divided by %i equals %i", num1, num2, num1 / num2);
    else return SendClientMessage(playerid, -1, "You didn't put a valid operator. Valid operators are +, -, /, *");
    SendClientMessage(playerid, -1, str);
    return true;
}
Reply
#6

Cool MAth ....
Reply
#7

Quote:
Originally Posted by rockhopper
Посмотреть сообщение
Cool MAth ....
Hahah"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)