AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Retrieving an entity id before it's created (https://forums.alliedmods.net/showthread.php?t=277658)

DavidLin 01-13-2016 11:15

Retrieving an entity id before it's created
 
How can I detect what id the entity will have before it's created ?

klippy 01-13-2016 11:38

Re: Retrieving an entity id before it's created
 
It may be predictable with code that simulates what ED_Alloc() engine function does here: https://github.com/dreamstalker/rehl..._edict.cpp#L48
I don't think it's possible to do it from an AMXX plugin though. As far as I know, AMXX doesn't offer any natives that deal with edicts directly, so it probably has to be written within a module.

Why do you even want to predict the id? I don't see how is that useful.

DavidLin 01-13-2016 12:10

Re: Retrieving an entity id before it's created
 
Well I get entity origins from a .cfg file and store them in a dynamic array. There is a menu from which I can delete the entity, add them and etc. So when I delete the entity I want to delete the dynamic array item too, but how can I retrieve the array item id when deleting the entity ?

klippy 01-13-2016 12:15

Re: Retrieving an entity id before it's created
 
You could save array index in entity's pev_iuser[1-4] fields. Easily retrieved with pev().
PHP Code:

set_pev(entpev_iuser1index); 


DavidLin 01-13-2016 13:27

Re: Retrieving an entity id before it's created
 
Thanks also why does this part give me a tag missmatch?
PHP Code:


enum _
:mearray {
        
id,
        
line_id,
        
Float:Origins],
        
Float:Angles]
}
DataOrigins ][ ] = 2.0; <-- This one 


klippy 01-13-2016 14:36

Re: Retrieving an entity id before it's created
 
You are probably declaring that array as:
PHP Code:

new Data[mearray]; 

The compiler doesn't actually look at the tag of "Origins" constant, but at the tag of "Data" variable. That's a compiler bug that (as Arkshine stated in one of the commits) was introduced in version 1.60 of AMXX, as is now fixed in newest 1.8.3 dev releases.

One way to get around that is to de-tag the value you assign to your variable:
PHP Code:

Data[Origins][0] = _:2.0

The other way would be to declare your variable ("structure") as:
PHP Code:

new anyData[mearray]; 

That's kind of bad because it allows you to assign a value of any tag to your variable, but it at least shuts the compiler warnings.

DavidLin 01-14-2016 07:12

Re: Retrieving an entity id before it's created
 
Thanks :)


All times are GMT -4. The time now is 09:26.

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