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

More Efficient Way in Removing Entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-05-2009 , 12:19   More Efficient Way in Removing Entities
Reply With Quote #1

Hi. I wanted to ask which objective entities' removing method is better?
Fakemeta's or Ham's?

Fakemeta:
Code:
#define MAX_OBJECTIVES 15   new g_szObjectiveClassNames[MAX_OBJECTIVES][] = {         "func_bomb_target",         "info_bomb_target",         "info_vip_start",         "func_vip_safetyzone",         "func_escapezone",         "hostage_entity",         "monster_scientist",         "func_hostage_rescue",         "info_hostage_rescue",         "env_fog",         "env_rain",         "env_snow",         "item_longjump",         "func_vehicle",         "func_buyzone" };   new g_iFwdSpawn;   public plugin_precache()         g_iFwdSpawn = register_forward(FM_Spawn, "fwdSpawn");   public plugin_init()         unregister_forward(FM_Spawn, g_iFwdSpawn);   public fwdSpawn(iEnt) {         if (!pev_valid(iEnt))                 return FMRES_IGNORED;           static s_szClassName[32], s_iNum;         pev(iEnt, pev_classname, s_szClassName, 31);           for (s_iNum = 0; s_iNum < MAX_OBJECTIVES; s_iNum++)                 if (equal(s_szClassName, g_szObjectiveClassNames[s_iNum]))                 {                         engfunc(EngFunc_RemoveEntity, iEnt);                           return FMRES_SUPERCEDE;                 }           return FMRES_IGNORED; }
Ham:
Code:
#define MAX_OBJECTIVES 15   new g_szObjectiveClassNames[MAX_OBJECTIVES][] = {         "func_bomb_target",         "info_bomb_target",         "info_vip_start",         "func_vip_safetyzone",         "func_escapezone",         "hostage_entity",         "monster_scientist",         "func_hostage_rescue",         "info_hostage_rescue",         "env_fog",         "env_rain",         "env_snow",         "item_longjump",         "func_vehicle",         "func_buyzone" };   new HamHook:g_iFwdObjectiveSpawn[MAX_OBJECTIVES];   public plugin_precache()         for (new iNum = 0; iNum < MAX_OBJECTIVES; iNum++)                 g_iFwdObjectiveSpawn[iNum] = RegisterHam(Ham_Spawn, g_szObjectiveClassNames[iNum], "fwdObjectiveSpawn");   public plugin_init()         for (new iNum = 0; iNum < MAX_OBJECTIVES; iNum++)                 if (g_iFwdObjectiveSpawn[iNum])                         DisableHamForward(g_iFwdObjectiveSpawn);   public fwdObjectiveSpawn(iEnt)         return pev_valid(iEnt) ? HAM_SUPERCEDE : HAM_IGNORED;
Note that I include both Fakemeta & Ham Sandwich in my plugin & I don't use Engine.

Also I wonder if I'm disabling Ham's forwards right.
__________________
hleV is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-05-2009 , 12:29   Re: More Efficient Way in Removing Entities
Reply With Quote #2

Try to only alter classnames and not remove ents.
In a no-objectives plugin, i was renaming "func_bomb_target" to "_func_bomb_target", and same for other objectives entities.
To set objectives back i only had to set again the right classname (and restart the round).

If you really want to remove them, why are you using forwards ? why don't you only remove all of them at map start ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Old 05-05-2009, 12:31
Arkshine
This message has been deleted by Arkshine. Reason: nvm
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 05-05-2009 , 12:34   Re: More Efficient Way in Removing Entities
Reply With Quote #3

Well connor he unregisters forward at plugin_init
__________________
xPaw is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 05-05-2009 , 12:42   Re: More Efficient Way in Removing Entities
Reply With Quote #4

Quote:
Originally Posted by ConnorMcLeod View Post
Try to only alter classnames and not remove ents.
In a no-objectives plugin, i was renaming "func_bomb_target" to "_func_bomb_target", and same for other objectives entities.
To set objectives back i only had to set again the right classname (and restart the round).

If you really want to remove them, why are you using forwards ? why don't you only remove all of them at map start ?
I want to remove all of them and then create "info_bomb_target" for the rounds to end normally.
Can you provide the non-Engine-module way of removing those objectives?
__________________
hleV is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 05-05-2009 , 12:45   Re: More Efficient Way in Removing Entities
Reply With Quote #5

Quote:
Originally Posted by xPaw View Post
Well connor he unregisters forward at plugin_init
cuz its unnecesarry code, with engine its one line per per ent or a 2 line loop.
anyway, "static s_szClassName[32] -> newszClassName[32]". you should not use a static there cuz it will still exist after FM_Spawn is run.

edit: you were faster... fakemeta engfunc( EngFunc_RemoveEntity, ent );
i guess youll have to do this in FM_Spawn or FM_KeyValue, at least spawns which are created after are not registered to the cs engine (changing an existing spawn, for example a ter spawn to ct spawn works!). maybe you can even use FMRES_SUPERCEDE.
__________________

Last edited by SchlumPF*; 05-05-2009 at 12:48.
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 05-05-2009 , 16:13   Re: More Efficient Way in Removing Entities
Reply With Quote #6

Quote:
Originally Posted by SchlumPF* View Post
anyway, "static s_szClassName[32] -> newszClassName[32]". you should not use a static there cuz it will still exist after FM_Spawn is run.
It doesn't matter, he gets the classname and sets it in szClassName so every time FM_Spawn is called the value is changed, not saved.
If you want it to be constant, you can do this:
PHP Code:
static var;
if (!var)
      var = 
8// Set it for the first time. 
Unless you mean that he unregisters FM_Spawn and the var will still exist?
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-05-2009 , 09:20   Re: More Efficient Way in Removing Entities
Reply With Quote #7

Bump.

I need the best way to get rid of entities and then create another one ("info_bomb_target").

It doesn't matter it's FM, Eng or Ham as long as it's the most efficient one.
__________________

Last edited by hleV; 06-05-2009 at 09:23.
hleV is offline
[X]-RayCat
Senior Member
Join Date: Sep 2006
Old 06-05-2009 , 10:40   Re: More Efficient Way in Removing Entities
Reply With Quote #8

Code:
#include <amxmodx> #include <fakemeta> new const entities_to_be_removed[][] = {     "info_player_deathmatch",     "info_player_vip" } new fow_keyvalue public plugin_init() {     register_plugin( "plugin", "version", "author" )     unregister_forward(FM_KeyValue,fow_keyvalue,0) } public plugin_precache() {     fow_keyvalue = register_forward(FM_KeyValue,"fm_keyvalue",0) } public fm_keyvalue(ent,kvdid) {     static key[24], value[24]     get_kvd(kvdid,KV_KeyName, key,23)     get_kvd(kvdid,KV_Value, value,23)     if(equal(key,"classname")) {         for(new i = 0; i < sizeof entities_to_be_removed; i++) {             if(equal(value,entities_to_be_removed[i])) {                 set_kvd(kvdid,KV_Value,  "lol123")  //invalid classname makes engine remove the entity             }         }     }     return FMRES_IGNORED }

Code:
#include <amxmodx> #include <fakemeta> new const g_class[] =   "func_bomb_target" //must be valid classname, otherwise crash! public plugin_init() {     register_plugin( "plugin", "version", "author") } public plugin_precache() {     new ent = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,g_class))     set_pev(ent,pev_solid, SOLID_NOT) }

I don't know where i got these codes but i've been using them.
__________________
[X]-RayCat is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-05-2009 , 10:55   Re: More Efficient Way in Removing Entities
Reply With Quote #9

So are you saying that these codes are the best possible ones?
__________________
hleV 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:27.


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