AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detecting when an entity is destroyed (https://forums.alliedmods.net/showthread.php?t=326678)

Spike_Spiegel 08-11-2020 22:58

Detecting when an entity is destroyed
 
Hi guys, I have some func_breakable entities in my map (cs 1.6), one in particular called "shield". Is it possible to detect when this "shield" entity is destroyed?
I found this code, this detect when every func_breakable is destroyed, but I don't know how to modify it to detect just the one called shield.

PHP Code:

#include <amxmodx>
#include <fakemeta>

public plugin_init() {
    
register_plugin("break_alert""1.0""commonbullet")
    
register_message(SVC_TEMPENTITY"check_breakable"
    
}

public 
check_breakable(msgid) {
    if(
get_msg_arg_int(1) != TE_BREAKMODEL)
        return 
PLUGIN_CONTINUE
    
    
new Float:br_origin[3]
    new 
Float:br_size[3]    
    new 
Float:tempvector[3]
    new 
Float:health
    
new classname[32]
    new 
ent

    br_origin
[0] = get_msg_arg_float(2)
    
br_origin[1] = get_msg_arg_float(3)
    
br_origin[2] = get_msg_arg_float(4)
    
br_size[0] = get_msg_arg_float(5)
    
br_size[1] = get_msg_arg_float(6)
    
br_size[2] = get_msg_arg_float(7)
    
    while((
ent engfunc(EngFunc_FindEntityInSphereentbr_origin0))) {
        
pev(entpev_classnameclassname31)
        if(
equal(classname"func_breakable")) {
            
pev(entpev_healthhealth)
            if(
health && !(pev(entpev_spawnflags) & SF_BREAK_TRIGGER_ONLY))
                continue            
            
// breakable is still solid when this message is thrown
            // so it'll block already broken entities
            
if(pev(entpev_solid) == SOLID_NOT
                continue
            
fm_get_brush_entity_origin(enttempvector)
            if(!
equal_vector(tempvectorbr_origin))
                continue
            
pev(entpev_sizetempvector)
            if(!
equal_vector(tempvectorbr_size))
                continue            
            
            
// ------ ADD HANDLE CODE... --------
            
client_print(0print_chat"Entity %d has been broken."ent)
            
// ----------------------------------
            
            
break
        }
    }
    return 
PLUGIN_CONTINUE  
}

fm_get_brush_entity_origin(entFloat:orig[3]) {
    
// converted to fm from engine stocks
    
new Float:Min[3]
    new 
Float:Max[3]
    
pev(entpev_minsMin)
    
pev(entpev_maxsMax)
    
    
orig[0] = (Min[0] + Max[0]) * 0.5
    orig
[1] = (Min[1] + Max[1]) * 0.5
    orig
[2] = (Min[2] + Max[2]) * 0.5

    
return 1
}

equal_vector(const Float:vector1[3], const Float:vector2[3]) {
    return ((
vector1[0] == vector2[0]) && (vector1[1] == vector2[1]) && (vector1[2] == vector2[2]))




All times are GMT -4. The time now is 13:50.

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