Raised This Month: $ Target: $400
 0% 

Properly remove entity at end of the round.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 07-07-2012 , 12:05   Properly remove entity at end of the round.
Reply With Quote #1

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!
Y060N is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 07-07-2012 , 14:24   Re: Properly remove entity at end of the round.
Reply With Quote #2

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

__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 07-07-2012 , 14:33   Re: Properly remove entity at end of the round.
Reply With Quote #3

It's better to use think instead of task.
__________________
<VeCo> is offline
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 07-07-2012 , 20:03   Re: Properly remove entity at end of the round.
Reply With Quote #4

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.
Y060N is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 07-08-2012 , 05:17   Re: Properly remove entity at end of the round.
Reply With Quote #5

if you need to remove all entities with classname "poison", just do remove_entity_name("poison")
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-08-2012 , 05:30   Re: Properly remove entity at end of the round.
Reply With Quote #6

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)

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-08-2012 at 05:31.
ConnorMcLeod 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 15:04.


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