Define function help ...
#1

Hi, i make a function to verify if a player is Admin or V.I.P to use respective command.

Here is the code:
Код:
#define VACheck(%0,%1,%2)\
		do{\
	   		if(PlayerInfo[(%0)][pVip] < (%1) || PlayerInfo[(%0)][Level] < (%2)){\
    			new Str[128];\
    			format(Str, 128, "~r~~h~ERROR!~n~~w~You need to be V.I.P level ~y~~h~%d ~w~ or admin level ~y~~h~%d ~w~to use this command!", (%1), (%2));\
				return GameTextForPlayer((%0), Str, 3000, 4);\
			}\
		}\
		while(False)
Ok ... and i use:
Код:
CMD:god( playerid, params[ ] )
{
    VACheck( playerid, 4, 4 );
    SendClientMessage( playerid, 0xFFFFF, "Testing" );
    return 1;
}
If i have V.I.P level 4 and Admin level 4 or highest, the command will execute, but if i have Admin level 10, and V.I.P level 0, the command don't execute, and gave me: "ERROR You need to be ..."

What is the problem?
Reply
#2

Solved, just i change || with &&
Reply
#3

I HIGHLY encourage you read the PAWN Pre-Processor tutorial written by ******.

Quote:
Originally Posted by ******
So why use macros instead of functions (or why use functions instead of macros)? Macros replace text - so wherever you put the macro, there will your replacement go. If you have a macro in your code 100 times, that code will get generated 100 times. On the other hand if you have a function in your code 100 times, its code will only appear once with 100 calls to it. The latter is probably preferable if you have a lot of code - large chunks of code appearing 100 times will make a very large AMX file! Macros tend to be used for very small bits of code - calling a function takes time, so if you have very tiny code it's not really worth the effort of calling a function, but this is not a rule! If you used a function instead of the macros above, the code compiled would look like:
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)