// Includes
#include <zcmd>
#include <sscanf2>
// Defines
#define CWHITE 0xFFFFFFAA
#define CGRAD 0xBFC0C2FF
CMD:calculate(playerid, params[])
{
return 1;
}
CMD:calcullate(playerid, params[])
{
new string[128], method[20], value1, value2;
return 1;
}
CMD:calcullate(playerid, params[])
{
new string[128], method[20], value1, value2;
if(sscanf(params, "ds[20]d", value1, method, value2))
{
SendClientMessage(playerid, CWHITE, "[USAGE]: /calculate [value] [operation] [value].");
SendClientMessage(playerid, CGRAD, "Operations: Add, Subtract, Multiply, Divide.");
return 1;
}
return 1;
}
CMD:calcullate(playerid, params[])
{
new string[128], method[20], value1, value2;
if(sscanf(params, "ds[20]d", value1, method, value2))
{
SendClientMessage(playerid, CWHITE, "USAGE: /calculate [value] [operation] [value].");
SendClientMessage(playerid, CGRAD, "Operations: Add, Subtract, Multiply, Divide.");
return 1;
}
if(strcmp(method,"multiply",true) == 0 || strcmp(method,"*",true) == 0)
{
// Continued code below
}
if(strcmp(method,"divide",true) == 0 || strcmp(method,"/",true) == 0)
{
// Continued code below
}
if(strcmp(method,"add",true) == 0 || strcmp(method,"+",true) == 0)
{
// Continued code below
}
if(strcmp(method,"subtract",true) == 0 || strcmp(method,"-",true) == 0)
{
// Continued code below
}
return 1;
}
CMD:calculate(playerid, params[])
{
new string[128], method[20], value1, value2;
if(sscanf(params, "ds[20]d", value1, method, value2))
{
SendClientMessage(playerid, CWHITE, "USAGE: /calculate [value] [operation] [value].");
SendClientMessage(playerid, CGRAD, "Operations: Add, Subtract, Multiply, Divide.");
return 1;
}
if(strcmp(method,"multiply",true) == 0 || strcmp(method,"*",true) == 0)
{
new sum = value1*value2; // We create a new define called sum which means the result of valu1 multiplied by value2
format(string,sizeof(string),"%d multiplied by %d equals %d.",value1,value2,sum); // The format of the SendClientMessage
SendClientMessage(playerid,CWHITE,string); // Sends message to the player which the format just above
}
if(strcmp(method,"divide",true) == 0 || strcmp(method,"/",true) == 0)
{
if(value2 == 0) // As Maths say that we can't divide by zero, we can't. So here we shall send him an error message.
{
SendClientMessage(playerid,CWHITE,"ERROR: Cannot divide by zero");
return 1;
}
new sum = value1/value2; // We create a new define called sum which means the result of valu1 divided by value2
format(string,sizeof(string),"%d divided by %d equals %d.",value1,value2,sum); // The format of the SendClientMessage
SendClientMessage(playerid,CWHITE,string); // Sends message to the player which the format just above
}
if(strcmp(method,"add",true) == 0 || strcmp(method,"+",true) == 0)
{
new sum = value1+value2; // We create a new define called sum which means the result of valu1 added to value2
format(string,sizeof(string),"%d added to %d equals %d.",value1,value2,sum); // The format of the SendClientMessage
SendClientMessage(playerid,CWHITE,string); // Sends message to the player which the format just above
}
if(strcmp(method,"subtract",true) == 0 || strcmp(method,"-",true) == 0)
{
new sum = value1-value2; // We create a new define called sum which means the result of valu1 subtraced by value2
format(string,sizeof(string),"%d subtracted by %d equals %d.",value1,value2,sum); // The format of the SendClientMessage
SendClientMessage(playerid,CWHITE,string); // Sends message to the player which the format just above
}
return 1;
}
Very nice tutorial. .
Everything is explained very clearly. +repped |
CMD:calculate(playerid, params[])
{
new string[128], method[20], Float:value1, Float:value2;
if(sscanf(params, "fs[20]f", value1, method, value2))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /calculate [value] [operation] [value].");
SendClientMessage(playerid, COLOR_GRAD2, "Operations: Add, Subtract, Multiply, Divide.");
return 1;
}
if(strcmp(method,"multiply",true) == 0 || strcmp(method,"*",true) == 0)
{
new Float:sum = Float:value1*Float:value2;
format(string,sizeof(string),"%0.2f multiplied by %0.2f equals %0.2f.",value1,value2,sum);
SendClientMessage(playerid,COLOR_WHITE,string);
}
if(strcmp(method,"divide",true) == 0 || strcmp(method,"/",true) == 0)
{
if(value2 == 0)
return GameTextForPlayer(playerid, "face~r~palm", 1000, 3);
new Float:sum = Float:value1/Float:value2;
format(string,sizeof(string),"%0.2f divided by %0.2f equals %0.2f.",value1,value2,sum);
SendClientMessage(playerid,COLOR_WHITE,string);
}
if(strcmp(method,"add",true) == 0 || strcmp(method,"+",true) == 0)
{
new Float:sum = Float:value1+Float:value2;
format(string,sizeof(string),"%0.2f added to %0.2f equals %0.2f.",value1,value2,sum);
SendClientMessage(playerid,COLOR_WHITE,string);
}
if(strcmp(method,"subtract",true) == 0 || strcmp(method,"-",true) == 0)
{
new Float:sum = Float:value1-Float:value2;
format(string,sizeof(string),"%0.2f subtracted by %0.2f equals %0.2f.",value1,value2,sum);
SendClientMessage(playerid,COLOR_WHITE,string);
}
return 1;
}