AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   ENTINDEX() and INDEXENT() Question. (https://forums.alliedmods.net/showthread.php?t=330242)

Abhinash 01-26-2021 00:46

ENTINDEX() and INDEXENT() Question.
 
I just started learning module coding.
I want to know the usage and meaning of ENTINDEX() and INDEXENT(), because I couldn't understand from the notes of HLSDK.

Please help me with example if possible.

fysiks 01-27-2021 23:06

Re: ENTINDEX() and INDEXENT() Question.
 
This question has already been answered here. If you have a more specific question, you should create a thread to ask the more specific question.

redivcram 01-28-2021 09:13

Re: ENTINDEX() and INDEXENT() Question.
 
Think of edict_t as a seat in a theater. The Goldsource engine (our theater) has a limited number of seats for each watcher.
Every watcher in this case is an entity that can be divided into groups: players, point entities, weapon entities, etc. For now, players are in our interest.


Every seat has its own unique number ranging from zero to the max amount of seats the theater can have. The player group can only have their own id number from one to thirty two which is the max amount of players a server can have. This is that id parameter you see everywhere in amxx plugins when a player is being referenced to. The amxx plugin references the seat number, not the player directly.


In AMXX modules, you are able to do much more than that (for now). You get to reference the seat number and the seat itself, accessing its properties directly.


edict_t (edicts) are not players, they are slots for entities that contain many values every entity including the player have in common, like position, classname, targetname, netname (nickname) and many more. The true player class is called CBasePlayer, but we are working with edicts here, aka the seats that still contain valuable data about its sitter.


So, finally, let's put it simple.


ENTINDEX(edict_t*) returns the specified seat's number. Note that it can't be empty, it needs to have a sitter in order for you to do something with them, duh. (Pointers are crucial and I suggest you do a little bit of research on C++ pointers, they are very beautiful things).

INDEXENT(int) returns a seat by a specified seat number.


Different functions that work with the same seat object types receive different references to the seat. Either the seat itself or its number.

Abhinash 01-28-2021 14:02

Re: ENTINDEX() and INDEXENT() Question.
 
So, in my term if I make it simple to understand it would be ENTINDEX() = Returns data of an entity and INDEXENT() = Returns entity of the data.
Right, redivcram ?

redivcram 01-28-2021 14:19

Re: ENTINDEX() and INDEXENT() Question.
 
No. ENTINDEX returns the index number of the entity and INDEXENT returns the entity that has the index number specified as the only argument when calling the function.

Sample uaage:

Code:

edict_t* pMyEnt = ENTINDEX(4); // pMyEnt now points to the entity with the index number of 4 if it exists, otherwise it will point nowhere (will be nullptr)

// Check validity, etc.
// ...

int id = INDEXENT(pMyEnt);

return id; // Will return 4.


Abhinash 01-28-2021 15:35

Re: ENTINDEX() and INDEXENT() Question.
 
Quote:

Originally Posted by redivcram (Post 2734670)
No. returns the index number of the entity and INDEXENT returns the entity that has the index number specified as the only argument when calling the function.

Sample uaage:

Code:

edict_t* pMyEnt = ENTINDEX(4); // pMyEnt now points to the entity with the index number of 4 if it exists, otherwise it will point nowhere (will be nullptr)

// Check validity, etc.
// ...

int id = INDEXENT(pMyEnt);

return id; // Will return 4.


I got you, I understood in your earlier post, I just said in my term to make me easy. Btw, thanks for examples. That was what, I was looking for.

I have a question, what if I use INDEXENT() for entity other than player ? Then, will it return the index of that entity ?

HamletEagle 01-29-2021 07:14

Re: ENTINDEX() and INDEXENT() Question.
 
Players ARE entities and every entity has an index.

redivcram 02-01-2021 14:42

Re: ENTINDEX() and INDEXENT() Question.
 
Quote:

Originally Posted by Abhinash (Post 2734685)
I have a question, what if I use INDEXENT() for entity other than player ? Then, will it return the index of that entity ?


Yes, but no reason to do so. Depends on what your function accepts, index or entity.


All times are GMT -4. The time now is 06:53.

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