AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   More Efficient Way in Removing Entities (https://forums.alliedmods.net/showthread.php?t=91788)

hleV 05-05-2009 12:19

More Efficient Way in Removing Entities
 
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.

ConnorMcLeod 05-05-2009 12:29

Re: More Efficient Way in Removing Entities
 
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 ?

xPaw 05-05-2009 12:34

Re: More Efficient Way in Removing Entities
 
Well connor he unregisters forward at plugin_init

hleV 05-05-2009 12:42

Re: More Efficient Way in Removing Entities
 
Quote:

Originally Posted by ConnorMcLeod (Post 821712)
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?

SchlumPF* 05-05-2009 12:45

Re: More Efficient Way in Removing Entities
 
Quote:

Originally Posted by xPaw (Post 821718)
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.

Dores 05-05-2009 16:13

Re: More Efficient Way in Removing Entities
 
Quote:

Originally Posted by SchlumPF* (Post 821729)
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?

hleV 06-05-2009 09:20

Re: More Efficient Way in Removing Entities
 
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.

[X]-RayCat 06-05-2009 10:40

Re: More Efficient Way in Removing Entities
 
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. :wink:

hleV 06-05-2009 10:55

Re: More Efficient Way in Removing Entities
 
So are you saying that these codes are the best possible ones?


All times are GMT -4. The time now is 23:37.

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