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

[TF2] killing off multiple entities onpluginend


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-16-2013 , 13:13   [TF2] killing off multiple entities onpluginend
Reply With Quote #1

In one of my plugins i spawn multiple item_ammopack_small that have a gift box model.
When the plugin is unloaded, the gift boxes are removed with this code.

PHP Code:
public OnPluginEnd() {
    new 
ent = -1;
    while((
ent FindEntityByClassname(ent"item_ammopack_small")) != -1) {
        if(
IsValidEntity(ent)) {
            
decl String:name[MAX_NAME_LENGTH];
            
GetEntPropString(entProp_Data"m_iName"namesizeof(name));
            if(
StrEqual(name"giftbox%tak")) {
                
AcceptEntityInput(ent"kill");
            }
        }
    }

Is there another way to remove the entities without the use of setting/getting a name?
__________________
Chaosxk is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-16-2013 , 13:16   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #2

Throw all the entities you create into an adt array and then just iterate it when you want to remove them.
__________________
thetwistedpanda is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-16-2013 , 13:18   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #3

Quote:
Originally Posted by thetwistedpanda View Post
Throw all the entities you create into an adt array and then just iterate it when you want to remove them.
An adt_array of ent references (using EntIndexToEntRef), that is, so you can use EntRefToEntIndex later if those entities still exist.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-17-2013 , 13:27   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #4

I have never done anything with adt_arrays, so i don't actually know if i set this up right.
Also, i have a timer that eventually kills off the entity after a few seconds, do i need to remove it off the adt_array handle?

Here is what i got so far.

PHP Code:
new Handle:arrayCell;

public 
OnPluginStart() {
    
arrayCell CreateArray(32);
}

public 
OnPluginEnd() {
    for(new 
0GetArraySize(arrayCell); i++) {
        new 
ent EntRefToEntIndex(GetArrayCell(arrayCelli));
        
AcceptEntityInput(ent"kill");
    }
}

CreateGift() {
    new 
ent CreateEntityByName("item_ammopack_small");
    if(
IsValidEntity(ent)) {
        
CreateTimer(30.0KillEntityEntIndexToEntRef(ent));
        
PushArrayCell(arrayCellEntIndexToEntRef(ent));
    }
}

public 
Action:StartTouchTimer(Handle:timerany:entref) {
    new 
ent EntRefToEntIndex(entref);
    if(
IsValidEntity(ent)) {
        
AcceptEntityInput(ent"kill");
        
//do i need to remove ent from the adt_array when it is killed off with timer?
    
}

__________________
Chaosxk is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-17-2013 , 15:29   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #5

Quote:
Originally Posted by Chaosxk View Post
I have never done anything with adt_arrays, so i don't actually know if i set this up right.
Also, i have a timer that eventually kills off the entity after a few seconds, do i need to remove it off the adt_array handle?

Here is what i got so far.

PHP Code:
new Handle:arrayCell;

public 
OnPluginStart() {
    
arrayCell CreateArray(32);
}

public 
OnPluginEnd() {
    for(new 
0GetArraySize(arrayCell); i++) {
        new 
ent EntRefToEntIndex(GetArrayCell(arrayCelli));
        
AcceptEntityInput(ent"kill");
    }
}

CreateGift() {
    new 
ent CreateEntityByName("item_ammopack_small");
    if(
IsValidEntity(ent)) {
        
CreateTimer(30.0KillEntityEntIndexToEntRef(ent));
        
PushArrayCell(arrayCellEntIndexToEntRef(ent));
    }
}

public 
Action:StartTouchTimer(Handle:timerany:entref) {
    new 
ent EntRefToEntIndex(entref);
    if(
IsValidEntity(ent)) {
        
AcceptEntityInput(ent"kill");
        
//do i need to remove ent from the adt_array when it is killed off with timer?
    
}

For CreateArray, don't specify a blocksize unless it's an array of strings.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 08-17-2013 , 16:18   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #6

Unless you need a 2-dimensional dynamic array.
__________________
thetwistedpanda is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 08-17-2013 , 18:46   Re: [TF2] killing off multiple entities onpluginend
Reply With Quote #7

Okay, thanks for the help guys.
__________________
Chaosxk 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 04:30.


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