AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register entity removing (https://forums.alliedmods.net/showthread.php?t=25388)

GHW_Chronic 03-13-2006 00:55

Register entity removing
 
How would I register when an entity is removed / deleted? Or even when an entity takes damage. (not a player). register_event apparently does not work for entities, just players.

Twilight Suzuka 03-13-2006 01:30

register_event works for what the mod uses it for.

You can tell when an entity is removed by hooking FM.
Taking damage cannot be done through current hookings.

VEN 03-13-2006 04:41

Is it for bugs?
If so read http://forums.alliedmods.net/showthread.php?t=25365
It's possible to catch emitted sounds when func_breakable entity takes damage.
You have only check if entity is visible then it's still not "dead" and if EF_NODRAW is set then entity "destroyed".

Also FM note: you can't catch removing of some entities like weaponbox etc.

Twilight Suzuka 03-13-2006 15:45

That is because they are removed internally.

In theory, you can simply check to see if they still exist each and every server frame, but that would be silly.

GHW_Chronic 03-13-2006 16:38

exactly what I am trying to avoid, setting 50 tasks every 1.0 second to see if they died.

T(+)rget 03-13-2006 17:42

Why don't you hook pfnThink?

Then check the damage when its thinking, none done set the think inside itself of 0.1 or something, else create effects and remove the entity.

Note on Creation:
entity_set_float(entity, EV_FL_takedamage, DAMAGE_YES)
entity_set_float(entity, EV_FL_health, 10000.0)
entity_set_float(entity, EV_FL_nextthink, get_gametime() + 0.1) // starts your entity thinking

I give a ridiculous amount of HP because if it hits <= 0 then the entity will auto-remove by the engine :shock:

Twilight Suzuka 03-13-2006 18:32

Not all entities can be hooked using PFN think.

set tasks are inappropriate for this. A thinking entity is much much less laggy. I'd look into it.

GHW_Chronic 03-13-2006 18:33

*looking into it*

VEN 03-14-2006 02:42

As i said before make entity as func_breakable and check for it's EF_NODRAW flag every emit_sound. Register tasks/thinks unnecessarily in my opinion.
And not all entities removes at health <= 0, func_breakable entity is one of the examples.


All times are GMT -4. The time now is 20:24.

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