AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Properly remove entity at end of the round. (https://forums.alliedmods.net/showthread.php?t=189459)

Y060N 07-07-2012 12:05

Properly remove entity at end of the round.
 
I have a class that can create poison bombs and it has a task to remove the entity. When I try to remove this entity and it's task at the end of the round the server crashes.

My question is, how can I remove this entity safely if it is still there at the end of the round?

PHP Code:

..........
entity_set_stringentEV_SZ_classname"poison" );
set_task8.0"remove_this_ent"ent );
..........

public 
remove_this_entent )
{
    if( !
is_valid_entent ) )
        return;

    
remove_entityent );


Thanks!

yokomo 07-07-2012 14:24

Re: Properly remove entity at end of the round.
 
This should work.
PHP Code:

#define TASK_REMOVE 2684
#define ID_REMOVE (taskid - TASK_REMOVE)

..........
entity_set_stringentEV_SZ_classname"poison" );
set_task8.0"remove_this_ent"ent+TASK_REMOVE );
..........

public 
remove_this_ent(taskid)
{
    if(!
is_valid_ent(ID_REMOVE)) return;

    
remove_entity(ID_REMOVE);


public 
OnEndRound()
{
    
RemoveAllPoisonEnt()
}

RemoveAllPoisonEnt()
{
    new 
ent find_ent_by_class(-1"poison")
    while(
ent 0)
    {
        if(
is_valid_ent(ent))
        {
            
remove_task(ent+TASK_REMOVE)
            
remove_entity(ent)
        }
        
        
ent find_ent_by_class(-1"poison")
    }



<VeCo> 07-07-2012 14:33

Re: Properly remove entity at end of the round.
 
It's better to use think instead of task.

Y060N 07-07-2012 20:03

Re: Properly remove entity at end of the round.
 
Yeah I tried removing with find_ent_by_class before Yokomo and it crashed but I will try it again with the taskID's in place, thanks for the suggestion.

If that doesn't work I'll use think.

NiHiLaNTh 07-08-2012 05:17

Re: Properly remove entity at end of the round.
 
if you need to remove all entities with classname "poison", just do remove_entity_name("poison")

ConnorMcLeod 07-08-2012 05:30

Re: Properly remove entity at end of the round.
 
I suggest you to use both engine and fakemeta.

Better to cache classname in a global var so it saves some memory.
You can directly set allocated classname value instead of filling memory again and again.
Use think instead of tasks (if you need other feature than removal in the think process it can be done).
Remove all remaining entities at new round.

PHP Code:

#include <amxmodx>

#include <engine>
#include <fakemeta>

new const POISON_CLASS[] = "poison"
new g_iszPoisonClass // cache allocated POISON_CLASS here so we don't fill memory with it

public plugin_init()
{
    
register_event("HLTV""Event_HLTV_New_Round""a""1=0""2=0")
    
register_think(POISON_CLASS"RemovePoisonEnt")
    
g_iszPoisonClass engfunc(EngFunc_AllocStringPOISON_CLASS)
}

public 
Event_HLTV_New_Round()
{
    new 
ent = -1
    
while( (find_ent_by_class(entPOISON_CLASS)) > )
    {
        
remove_entity(ent)
    }
}

public 
RemovePoisonEntent )
{
    
set_pev(entpev_flagsFL_KILLME// just set this flag as game is executing Think function so detecting that flag game gonna remove that ent (not delayed)
}

{
    
set_pev_string(entpev_classnameg_iszPoisonClass// entity_set_string or set_pev would allocated again and again each time you send it
    
set_pev(entpev_nextthinkget_gametime() + 8.0)




All times are GMT -4. The time now is 15:04.

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