AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Correct safety remove entity (https://forums.alliedmods.net/showthread.php?t=344091)

Arje 10-02-2023 00:09

Correct safety remove entity
 
PHP Code:

new g_black_player[SH_MAXSLOTS+1];

new const 
gBlackHoleModel[] = "models/shmod/blackhole.mdl"

new const gBlackHole_EntName[] = "black_hole"
//------------------------------------------------------------------------------------------------
//                Black Create and Remove                        //
//------------------------------------------------------------------------------------------------
public black_create(id)    
{     
    new 
Float:vOrigin[3]
    
pev(idpev_originvOrigin);

    
//This will make it so that the disk appears in front of the user
    
new Float:viewing_angles[3]
    new 
distance_from_user 70
    pev
(idpev_anglesviewing_angles)
    
vOrigin[0] += floatcos(viewing_angles[1], degrees) * distance_from_user
    vOrigin
[1] += floatsin(viewing_angles[1], degrees) * distance_from_user
    vOrigin
[2] += floatsin(-viewing_angles[0], degrees) * distance_from_user
     
    
// This is for create the entity
    
new black_hole engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    if (!
pev_valid(black_hole)) {
        
sh_chat_message(idgHeroID"Error al crear el agujero negro.");
        return;
    }
    
g_black_player[id] = black_hole;
    
    
//sets the classname of the entity
    
set_pev(black_holepev_classnamegBlackHole_EntName); 
    
    
//This tells what the object will look like
    
engfunc(EngFunc_SetModelblack_holegBlackHoleModel); 

    
//This will set the origin of the entity 
    
engfunc(EngFunc_SetOriginblack_holevOrigin); 
    
    
//This will get the velocity of the entity 
    
new Float:vAim[3]
    
velocity_by_aim(idrandom_num(24), vAim);
    
    
//Sets the size of the entity
    
new FloatminBound[3] = {-2.5, -2.5, -2.5};  //sets the minimum bound of entity
    
new FloatmaxBound[3] = {2.52.52.5};    //sets the maximum bound of entity
    
set_pev(black_holepev_minsminBound);
    
set_pev(black_holepev_maxsmaxBound);
    
    
//Sets who the owner of the entity is
    
set_pev(black_holepev_ownerid);
    
    
//This will set the movetype of the entity 
    
set_pev(black_holepev_movetypeMOVETYPE_FLY); 

    
//This makes the entity touchable
    
set_pev(black_holepev_solidSOLID_BBOX);
    
    
//Sets who the owner of the entity is
    
set_pev(black_holepev_ownerid);
    
    
//This is for a make safety remove ?
    // set_pev(ent, pev_nextthink, get_gametime() + 8.0)
}

public 
remove_all_bh(id)
{
    new 
ent 33;
    
    while((
ent find_ent_by_class(entgBlackHoleModel)) != 0) {
        if( 
entity_get_edict(entEV_ENT_owner) != id )
            continue;
            
        
set_pev(entpev_flagsFL_KILLME)
        
remove_entity(ent);
    }


This is the correct form to delete a entity ? i dont understand how to use this "set_pev(ent, pev_flags, FL_KILLME)" but i read its necessary for safety?

lexzor 10-02-2023 00:43

Re: Correct safety remove
 
it's not necessary for safety, it's just a flag that tell the engine the entity must be removed in the next frame

i see you are using remove_entity(ent) so i'm sure you are using engine module, just use remove_entity and set the entity next think in order to remove it from the world.

Arje 10-02-2023 01:19

Re: Correct safety remove
 
Quote:

Originally Posted by lexzor (Post 2810924)
it's not necessary for safety, it's just a flag that tell the engine the entity must be removed in the next frame

i see you are using remove_entity(ent) so i'm sure you are using engine module, just use remove_entity and set the entity next think in order to remove it from the world.

PHP Code:

public remove_all_bh(id)
{
    new 
ent 33;
    
    while((
ent find_ent_by_class(entgBlackHoleModel)) != 0) {
        if( 
entity_get_edict(entEV_ENT_owner) != id )
            continue;
            
        
set_pev(entpev_flagsFL_KILLME)
        
remove_entity(ent);
    }


-->

PHP Code:

public remove_all_bh(id)
{
    new 
ent 33;
    
    while((
ent find_ent_by_class(entgBlackHoleModel)) != 0) {
        if( 
entity_get_edict(entEV_ENT_owner) != id )
            continue;
            

        
set_pev(entpev_nextthinkget_gametime() + 0.1);
    }


something like this?

lexzor 10-02-2023 03:01

Re: Correct safety remove
 
use remove_entity before nextthink
the fastest you can set a entity think (as far as i know) is 0.01

Arje 10-05-2023 10:34

Re: Correct safety remove
 
Quote:

Originally Posted by lexzor (Post 2810926)
use remove_entity before nextthink
the fastest you can set a entity think (as far as i know) is 0.01

Something like this ?
PHP Code:

public remove_all_bh(id)
{
    new 
ent 33;
    while((
ent find_ent_by_class(entgBlackHole_EntName)) != 0) {

        if( 
pev(entpev_owner) != id ) continue;
             
        
// set_pev(ent, pev_flags, FL_KILLME)
        
remove_entity(ent);
        
set_pev(entpev_nextthinkget_gametime() + 0.1);
    }



lexzor 10-05-2023 11:49

Re: Correct safety remove entity
 
Code:
public remove_all_bh(id) {     new ent = 33;     while((ent = find_ent_by_class(ent, gBlackHole_EntName)) != 0) {         if( pev_valid(ent) && pev(ent, pev_owner) != id ) continue;                       // set_pev(ent, pev_flags, FL_KILLME)         remove_entity(ent);         set_pev(ent, pev_nextthink, get_gametime() + 0.01);         server_print("Found entity %i with owner %n", ent, pev(ent, pev_owner));     } }

Natsheh 10-05-2023 20:39

Re: Correct safety remove entity
 
This is the proper way to remove entities with specific classname by owner...

PHP Code:

new ent MAX_PLAYERS 1;

while( (
ent find_ent_by_owner(entgBlackHole_EntNameid)) > 0)
{
    
set_pev(entpev_flagsFL_KILLME);
    
dllfunc(DLLFunc_Thinkent);



MrPickles 10-10-2023 20:22

Re: Correct safety remove entity
 
Quote:

Originally Posted by Natsheh (Post 2811153)
This is the proper way to remove entities with specific classname by owner...

PHP Code:

new ent MAX_PLAYERS 1;

while( (
ent find_ent_by_owner(entgBlackHole_EntNameid)) > 0)
{
    
set_pev(entpev_flagsFL_KILLME);
    
dllfunc(DLLFunc_Thinkent);



error will throw, u are starting the think to an invalid entity, u removed it before with FL_KILLME

setting KILL ME or with remove_entity( ent ) its more than enough.

Natsheh 10-10-2023 21:55

Re: Correct safety remove entity
 
Quote:

Originally Posted by MrPickles (Post 2811464)
error will throw, u are starting the think to an invalid entity, u removed it before with FL_KILLME

setting KILL ME or with remove_entity( ent ) its more than enough.

setting KILLME flag will safely remove the entity on think, setting the flag alone it doesn't mean anything until you call the entity think, if you don't know what you're talking about do not post...

You're just confusing the people...

mlibre 10-12-2023 12:00

Re: Correct safety remove entity
 
OR

PHP Code:

stock kill_entity(ent)
{
    
entity_set_int(entEV_INT_flagsFL_KILLME)




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

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