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

Correct safety remove entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 10-02-2023 , 00:09   Correct safety remove entity
Reply With Quote #1

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?

Last edited by Arje; 10-02-2023 at 09:04.
Arje is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-02-2023 , 00:43   Re: Correct safety remove
Reply With Quote #2

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.
lexzor is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 10-02-2023 , 01:19   Re: Correct safety remove
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
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?
Arje is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-02-2023 , 03:01   Re: Correct safety remove
Reply With Quote #4

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

Last edited by lexzor; 10-02-2023 at 03:05.
lexzor is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 10-05-2023 , 10:34   Re: Correct safety remove
Reply With Quote #5

Quote:
Originally Posted by lexzor View Post
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);
    }

Arje is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 10-05-2023 , 11:49   Re: Correct safety remove entity
Reply With Quote #6

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));     } }

Last edited by lexzor; 10-05-2023 at 11:49.
lexzor is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-05-2023 , 20:39   Re: Correct safety remove entity
Reply With Quote #7

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);

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-05-2023 at 20:51.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 10-10-2023 , 20:22   Re: Correct safety remove entity
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
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.
MrPickles is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-10-2023 , 21:55   Re: Correct safety remove entity
Reply With Quote #9

Quote:
Originally Posted by MrPickles View Post
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...
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-10-2023 at 22:11.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 10-12-2023 , 12:00   Re: Correct safety remove entity
Reply With Quote #10

OR

PHP Code:
stock kill_entity(ent)
{
    
entity_set_int(entEV_INT_flagsFL_KILLME)

__________________
mlibre is offline
Reply



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 08:17.


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