[Tutorial] Making Basic calculator commands.
#1

Hello,
Okay this is my 4th tutorial showing that how can you make a simple calculator commands.I know it sounds newbish but I made this for people who are new.Not tested so tell me if anything goes wrong.Or tell me if I have done something wrong.

Here is the full code with explanation:
pawn Код:
#include <a_samp>//you all know this.
#include <sscanf2>//including sscanf include in the script.
#if defined FILTERSCRIPT

#endif
new Answer;//the variable which would store the answer.
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/plus", cmdtext, true, 10) == 0)
    {
        new str[128],N1,N2;//these are the variables that will store the text of the string,the first number entered and the second.
        if(sscanf(cmdtext, "ii", N1, N2)) return SendClientMessage(playerid, -1, "Usage: /plus (1st number) (2nd number)");//this will send the player an error message if he enters invalid information or in a wrong format.
        format(str, sizeof(str), "The answer to %i + %i is %i", N1, N2, Answer);//this will format the answer and all the calculations and store it in the variable str.
        SendClientMessage(playerid,-1,str);//now this will send the information stored in the variable str to the player.
        return 1;
    }
    else if (strcmp("/minus", cmdtext, true, 10) == 0)
    {
        new str[128],N1,N2;//these are the variables that will store the text of the string,the first number entered and the second.
        if(sscanf(cmdtext, "ii", N1, N2)) return SendClientMessage(playerid, -1, "Usage: /minus (1st number) (2nd number)");//this will send the player an error message if he enters invalid information or in a wrong format.
        format(str, sizeof(str), "The answer to %i - %i is %i", N1, N2, Answer);//this will format the answer and all the calculations and store it in the variable str.
        SendClientMessage(playerid,-1,str);//now this will send the information stored in the variable str to the player.
        return 1;
    }
    else if (strcmp("/multiplay", cmdtext, true, 10) == 0)
    {
        new str[128],N1,N2;//these are the variables that will store the text of the string,the first number entered and the second.
        if(sscanf(cmdtext, "ii", N1, N2)) return SendClientMessage(playerid, -1, "Usage: /multiplay (1st number) (2nd number)");//this will send the player an error message if he enters invalid information or in a wrong format.
        format(str, sizeof(str), "The answer to %i x %i is %i", N1, N2, Answer);//this will format the answer and all the calculations and store it in the variable str.
        SendClientMessage(playerid,-1,str);//now this will send the information stored in the variable str to the player.
        return 1;
    }
    return 0;
}
replies appreciated.
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: 1 Guest(s)