SA-MP Forums Archive
[FilterScript] small Calculator - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] small Calculator (/showthread.php?tid=524518)



small Calculator - Need4samp - 07.07.2014

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;
}



Re: small Calculator - iFarbod - 07.07.2014

Nice FS.


Re: small Calculator - SickAttack - 07.07.2014

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


Re: small Calculator - ]Rafaellos[ - 07.07.2014

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


Re: small Calculator - Inverse - 07.07.2014

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;
}



Re: small Calculator - rockhopper - 07.07.2014

Cool MAth ....


Re: small Calculator - Need4samp - 08.07.2014

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