AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   I need an explanation of a define (https://forums.alliedmods.net/showthread.php?t=129454)

Alucard^ 06-13-2010 03:44

I need an explanation of a define
 
Hi,

Well, nothing... i just don't understand this code:

PHP Code:

#define MAX_ENTS    900 +  MAX_PLAYERS * 15
#define HOLDING_ENTS_ARRAY_SIZE    (MAX_ENTS / 32) + _:!!(MAX_ENTS % 32) 

Something can explain me this?

Also, apart of this... i see in some codes using two "!!", like in the code above... what means that?

Thanks

hleV 06-13-2010 04:26

Re: I need an explanation of a define
 
MAX_ENTS simply tells how many entities can possibly be in the map. So instead of writing "900 + MAX_PLAYERS * 15" all the time, you use MAX_ENTS.

!! means "no" to "no", but giving you a bool value (1 or 0). If you had number 10, it will return number 1, if you had 0, you'll get 0.
Code:
new Number = 20;
Code:
Number = !Number // Number is now 0 ("not 20")
Code:
Number = 20; Number = !!Number; // Number is now 1 ("not 20" is 0, "not 0" is 1)
The "HOLDING_ENTS_ARRAY_SIZE" define is probably used to set the side of an array which holds the data of (all?) entities.

I'm not really familiar with "%", I'm afraid.

ConnorMcLeod 06-13-2010 04:45

Re: I need an explanation of a define
 
According to arkshine,

900 + MAX_PLAYERS * 15

should be replaced with :

900 + (MAX_PLAYERS-1) * 15

not that in plugins you can see, MAX_PLAYERS is 32 because they are public, but if you make a private plugin you can replace it with the real maxplayer amount of your server.

Arkshine 06-13-2010 05:20

Re: I need an explanation of a define
 
Don't why they remove -1 ; it would make sense to use MAX_PLAYERS.

Alucard^ 06-13-2010 10:06

Re: I need an explanation of a define
 
I know the basic things -.- like define and others... i added the first define so you can understand the second define.

The part that i didn't understand at all is exactly this:

PHP Code:

_:!!(MAX_ENTS 32

Thanks hleV for the !! explanation...

@ Connor

The code is used in your plugin kz buttonlocs xd

Thanks to all

wrecked_ 06-13-2010 12:26

Re: I need an explanation of a define
 
@Alucard^
The % operator is the modulo operator. It returns the remainder after division. So if you did 8 % 5, you'd get 3 as a return value. The _: "untags" certain things. For example, if you did something like
PHP Code:

new iTeam _:cs_get_user_teamid )

// tag mismatch
if( cs_get_user_teamid ) == CS_TEAM_T ) {}

// untagged, so it is not a mismatch
if( cs_get_user_teamid ) == ) {} 


Alucard^ 06-13-2010 12:34

Re: I need an explanation of a define
 
Oh thanks...

About the _: thing... if i understand is for not use the enum things right?

Thanks

wrecked_ 06-13-2010 12:39

Re: I need an explanation of a define
 
Yes, it's more commonly used to detag members of an enum (don't know the pawn terminology for member).

No problem.

Arkshine 06-13-2010 18:37

Re: I need an explanation of a define
 
Quote:

// no tag mismatch whether iTeam is tagged or not.
if( iTeam == CS_TEAM_T )
For your information, CS_TEAM_T is tagged, you will get a tag mismatch since iTeam is not tagged.


All times are GMT -4. The time now is 14:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.