[Tutorial] Making Basic calculator commands.
#10

pawn Код:
#include <a_samp>
#include <sscanf2>

#define CALC_ADD        1
#define CALC_MINUS      2
#define CALC_MULTIPLY   3
#define CALC_DIVIDE     4

stock calculate(playerid, number1, number2, method) {
    new outcome, string[128];
    switch(method) {
        case CALC_ADD: format(string, 128, "%d + %d = %d", number1, number2, number1 + number2), SendClientMessage(playerid, -1, string);
        case CALC_MINUS: format(string, 128, "%d - %d = %d", number1, number2, number1 - number2), SendClientMessage(playerid, -1, string);
        case CALC_MULTIPLY: format(string, 128, "%d * %d = %d", number1, number2, number1 * number2), SendClientMessage(playerid, -1, string);
        case CALC_DIVIDE: format(string, 128, "%d / %d = %d", number1, number2, number1 / number2), SendClientMessage(playerid, -1, string);
    }
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/calc", cmdtext, true, 5) == 0 || strcmp("/calculate", true, 10) == 0) {
        new str[128], func[2], n1, n2, type;
        if(sscanf(cmdtext, "iis[2]", n1, n2, func)) return SendClientMessage(playerid, -1, "Usage: /calc(ulate) (1st number) (2nd number) (function: + - / *)");
        if(!sscanf(func, "+", true, 1)) { type = CALC_ADD; } else if(!sscanf(func, "-", true, 1)) { type = CALC_MINUS; } else if(!sscanf(func, "*", true, 1)) { type = CALC_MULTIPLY; } else if(!sscanf(func, "/", true, 1)) { type = CALC_DIVIDE; }
        calculate(playerid, n1, n2, type);
    }
    return 0;
}
Reply


Messages In This Thread
Making Basic calculator commands. - by TaLhA XIV - 05.09.2012, 12:22
Re: Making Basic calculator commands. - by leonardo1434 - 05.09.2012, 12:32
Re: Making Basic calculator commands. - by TaLhA XIV - 05.09.2012, 12:40
Re: Making Basic calculator commands. - by Sanady - 05.09.2012, 13:35
Re: Making Basic calculator commands. - by TaLhA XIV - 05.09.2012, 13:48
Re: Making Basic calculator commands. - by FUNExtreme - 05.09.2012, 14:05
Re: Making Basic calculator commands. - by Kirollos - 05.09.2012, 14:12
Re: Making Basic calculator commands. - by TaLhA XIV - 05.09.2012, 14:22
Re: Making Basic calculator commands. - by Faisal_khan - 05.09.2012, 14:33
Re: Making Basic calculator commands. - by jameskmonger - 05.09.2012, 14:37

Forum Jump:


Users browsing this thread: 3 Guest(s)