Raised This Month: $12 Target: $400
 3% 

ENTINDEX() and INDEXENT() Question.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-26-2021 , 00:46   ENTINDEX() and INDEXENT() Question.
Reply With Quote #1

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.
Abhinash is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-27-2021 , 23:06   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #2

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.
__________________
fysiks is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 01-28-2021 , 09:13   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #3

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.

Last edited by redivcram; 01-28-2021 at 09:19.
redivcram is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-28-2021 , 14:02   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #4

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 ?
Abhinash is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 01-28-2021 , 14:19   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #5

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.

Last edited by redivcram; 01-28-2021 at 14:25.
redivcram is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 01-28-2021 , 15:35   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #6

Quote:
Originally Posted by redivcram View Post
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 ?

Last edited by Abhinash; 01-28-2021 at 15:37.
Abhinash is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-29-2021 , 07:14   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #7

Players ARE entities and every entity has an index.
__________________

Last edited by HamletEagle; 01-29-2021 at 07:15.
HamletEagle is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 02-01-2021 , 14:42   Re: ENTINDEX() and INDEXENT() Question.
Reply With Quote #8

Quote:
Originally Posted by Abhinash View Post
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.
redivcram is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:28.


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