07.11.2016, 11:14
Hey!
so far I've only seen calculators script which can handle only 2 numbers!
But now you can calculate with multiple numbers.
Function in this include takes string and returning result as integer..
(soon as Float)
For now it works only with:
Function
compute[] - String which will be calculated
&result - Return result in this variable
&bool:fail - Return 'true' if is there any errors
failstring[] - Store error string
const len = sizeof(failstring)
From example:
![](http://image.prntscr.com/image/158bf55988df47b696b0b364894982bd.png)
will return
![](http://image.prntscr.com/image/873812513c0e410e8992deab0eca1081.png)
But this:
![](http://image.prntscr.com/image/f781556320084cb9818511446b2d61db.png)
Script will remove empty letters and return:
![](http://image.prntscr.com/image/873812513c0e410e8992deab0eca1081.png)
![](http://image.prntscr.com/image/2235bda5e39b47cc9b2c8a348c4519c0.png)
return error:
![](http://image.prntscr.com/image/f32a29c8a4054a3fb570ddcae475612f.png)
![](http://image.prntscr.com/image/e16867de83654fd18943bcd4652d2e1f.png)
=
![](http://image.prntscr.com/image/5dcb95093134499899578be6ae6d6e4f.png)
![](http://image.prntscr.com/image/46bdec424790434d8655e1cef83896ee.png)
=
![](http://image.prntscr.com/image/e0fee738ab3a4a5fbabe1e35fd826010.png)
(real calculator)
![](http://image.prntscr.com/image/1bf4c790bd594b79b34b5705d24a0a29.png)
Example
Download:
https://github.com/Ino42O/PawnCalculator - 1.0.0
so far I've only seen calculators script which can handle only 2 numbers!
But now you can calculate with multiple numbers.
Function in this include takes string and returning result as integer..
(soon as Float)
For now it works only with:
Код:
Addition (+) Subtraction (−) Multiplication (Ч) Division (ч)
Код:
TryCalculate(compute[], &result, &bool:fail, failstring[], const len = sizeof(failstring));
&result - Return result in this variable
&bool:fail - Return 'true' if is there any errors
failstring[] - Store error string
const len = sizeof(failstring)
From example:
![](http://image.prntscr.com/image/158bf55988df47b696b0b364894982bd.png)
will return
![](http://image.prntscr.com/image/873812513c0e410e8992deab0eca1081.png)
But this:
![](http://image.prntscr.com/image/f781556320084cb9818511446b2d61db.png)
Script will remove empty letters and return:
![](http://image.prntscr.com/image/873812513c0e410e8992deab0eca1081.png)
![](http://image.prntscr.com/image/2235bda5e39b47cc9b2c8a348c4519c0.png)
return error:
![](http://image.prntscr.com/image/f32a29c8a4054a3fb570ddcae475612f.png)
![](http://image.prntscr.com/image/e16867de83654fd18943bcd4652d2e1f.png)
=
![](http://image.prntscr.com/image/5dcb95093134499899578be6ae6d6e4f.png)
![](http://image.prntscr.com/image/46bdec424790434d8655e1cef83896ee.png)
=
![](http://image.prntscr.com/image/e0fee738ab3a4a5fbabe1e35fd826010.png)
(real calculator)
![](http://image.prntscr.com/image/1bf4c790bd594b79b34b5705d24a0a29.png)
Example
Код:
CMD:calculate(playerid, arg[]) { new compute[64], result, bool:fail, error[24], str[64] ; if (!sscanf(arg, "s[64]", compute)) { TryCalculate(compute, result, fail, error, sizeof(error)); if(!fail) { format (str, sizeof(str), "Calculated: %d", result); SendClientMessage(playerid, -1, str); } else { format (str, sizeof(str), "Calculate Error: %s", error); SendClientMessage(playerid, -1, str); } } else SendClientMessage(playerid, -1, "Usage: /calculate [anything]"); return 1; }
https://github.com/Ino42O/PawnCalculator - 1.0.0