06.02.2010, 11:11
Quote:
Mathematical functions * Written by Ettans (ettans@purgatoryserver.com) * Last modified 02/07/2010 * If you use this include, please give proper credit. |
for any scripter to use. For an example, you can use these functions to add mathematical minigames to your servers and reward
players when they answer correctly.
Note: I'm really looking forward to decent suggestions, as I intend to keep this updated.
Setup:
Extract na_math_include.zip and copy the na_math.inc to your /pawno/includes/ folder. Open your gamemode and add #include <na_math> to the top. You're all done!
Functions:
- euclid_gcd(a,b);
Example usage: euclid_gcd(6,12); // Will return 6
Example usage: euclid_gcd(25,5); // Will return 5
- euclid_lcm(a,b);
Example usage: euclid_lcm(4,; // Will return 8
Example usage: euclid_lcm(12,6); // Will return 12
- abs(a);
Example usage: abs(4); // Will return 4
Example usage: abs(-6); // Will return 6
- exp(Float:num);
Example usage: exp(-1); // Will return 0.3678794
Example usage: exp(5); // Will return 148.4131591
- deg2rad(Float:deg);
Example usage: deg2rad(6); // Will return 0.1047198
Example usage: deg2rad(10); // Will return 0.1745329
Example usage: deg2rad(10.5); // Will return 0.1832596
- rad2deg(Float:rad);
Example usage: rad2deg(2); // Will return 114.59156
Example usage: rad2deg(5); // Will return 286.4789
Example usage: rad2deg(2.4); // Will return 137.509872
Example commands:
Code:
printf("Euler's constant (1) %f",exp(1)); printf("5 Degrees to radians %f",deg2rad(10));
Code:
/* * Requires you to have string pre-defined somewhere in your script, mostly at the top of OnPlayerCommandText. * Simply copy these commands to your OnPlayerCommandText callback. */ // Greatest common divider if(strcmp(cmd, "/euclid_gcd", true) == 0) { new val_x1 = strval(cmdtext[12]); new val_x2 = strval(cmdtext[14]); format(string,sizeof(string),"(Greatest common divider) Result: %d",euclid_gcd(val_x1,val_x2)); SendClientMessage(playerid,0xFFFFFFFF,string); return 1; } // Least common multiple if(strcmp(cmd, "/euclid_lcm", true) == 0) { new val1 = strval(cmdtext[12]); new val2 = strval(cmdtext[14]); format(string,sizeof(string),"(Least common multiple) Result: %d",euclid_lcm(val1,val2)); SendClientMessage(playerid,0xFFFFFFFF,string); return 1; } // Absolute value if(strcmp(cmd, "/abs", true) == 0) { new val = strval(cmdtext[9]); format(string,sizeof(string),"Absolue value: %d",abs(val)); SendClientMessage(playerid,0xFFFFFFFF,string); return 1; }