12.07.2011, 21:55
(
Последний раз редактировалось dowster; 25.07.2011 в 21:33.
)
After reading ******' thread on macros i decided to make an example by making a simple distance formula macro. This is a 3 dimensional distance formula, because i needed to use one in making my custom chat radius. For more info on how this works you can view the thread by ******.
That is the macro, as you can see %1 - %3 are they X, Y, Z, of the first location. Where %4 - %6 are the X, Y, Z of the second location. You could also have a macro with just two variables that gets the sum of said variables, like this one.
Which could be used in the following code to get the sum of A and B, and write it to C.
Making the macro is faster and uses less code also, to create the exact same function for that macro you would need to do.
Which takes up 5 lines VS. 1. Finally, an example command that uses the Distance Formula Macro could look as follows, using Y_command as my command processor of choice.
This is just a rough example thrown together in 2 Minutes, but it works.
When i wrote this i forgot a key bit of info:
from the pawn language guide
Код:
#define DISTANCE(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6))
Код:
#define SUM(%1,%2) (%1+%2)
Код:
C = SUM( A, B);
Код:
stock SUM( A, B) { new c = A + B; return C; }
Код:
YCMD:distancefromstart(playerid, params[], help) { if (help) { SendClientMessage(playerid, 0xFF0000AA, "Gets the distance between you and the only spawn point in this script"); } else { new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); new string[64]; format(string, sizeof(string), "%f, meters from start", (DISTANCE( x, y, z, 1958.3783, 1343.1572, 15.3746))); SendClientMessage( playerid, 0xFF3333FF, string); } return 1; }
When i wrote this i forgot a key bit of info:
Quote:
Substitution macros can take up to 10 parameters. |