AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   entity purge howto (https://forums.alliedmods.net/showthread.php?t=27810)

alien 04-30-2006 01:51

entity purge howto
 
Hi,

i'm interested in periodical purging of dropped weapons (esp. USP & scouts).

Code:
public repeat_purge()     {         new n = entity_count()         new class_name[32]         client_print(0, print_chat, "[%s] Purging unused entities.", PLUGIN_NAME)         for (new i = 0; i < n; i++)             {                 if (is_valid_ent(i))                     {                         entity_get_string(i, EV_SZ_classname, class_name, 31)                         if                             (                                 equal(class_name, "weaponbox") ||                                 (equal(class_name, "weapon_usp") && entity_get_int(i, EV_INT_movetype) == 0) ||                                 (equal(class_name, "weapon_scout") && entity_get_int(i, EV_INT_movetype) == 0)                             )                         remove_entity(i)                     }             }     }

It makes server failing cca. every half an hour. Is this a right way to do this? And i'm not sure, whether it's right, do distinguish dropped weapons from those carried by EV_INT_movetype flag. Could you help me?

Thank you.
Al.

GHW_Chronic 04-30-2006 02:41

A. [ small ] tags por favor
B.
Code:
public Remove_Weapons() {     new modelname[32]     for(new i=33;i<=entity_count();i++)     {         if(is_valid_ent(i))         {             entity_get_string(i,EV_SZ_model,modelname,31)             if(containi(modelname,"w_")!=-1)             {                 remove_entity(i)             }         }     }     return PLUGIN_HANDLED }

alien 04-30-2006 06:04

I'm sorry, but it just do the same as:

Code:
public Remove_Weapons() {     new classname[32]     for(new i=33;i<=entity_count();i++)     {         if(is_valid_ent(i))         {             entity_get_string(i,EV_SZ_classname,classname,31)             if(equal("weaponbox", classname))             {                 remove_entity(i)             }         }     }     return PLUGIN_HANDLED }

I have no problem with purging weaponboxes, but weapon_* entities. Those can be also carried by players or dropped. They have no model! I need to distinguish weapo_* being carried and dropped one. But thank you ...

alien 04-30-2006 06:51

What do you think about this:

Code:
public repeat_purge()     {         new class_name[32]         new owner         new n = entity_count()         new p = 0                     for (new i = 33; i <= n; i++)             {                 if (is_valid_ent(i))                     {                         entity_get_string(i, EV_SZ_classname, class_name, 31)                         if (equali("weaponbox", class_name))                             {                                 remove_entity(i)                                 p++                             }                         else                                                 if (containi(class_name, "weapon_") != -1)                             {                                 owner = entity_get_edict(i, EV_ENT_owner)                                 if (is_valid_ent(owner))                                     {                                         entity_get_string(owner, EV_SZ_classname, class_name, 31)                                         if (!equali("player", class_name))                                             {                                                 remove_entity(i)                                                 p++                                             }                                     }                             }                     }             }                 if (p) client_print(0, print_chat, "[%s] Purged %d of %d entities.", PLUGIN_NAME, p, n)         else client_print(0, print_chat, "[%s] Purge is needless.", PLUGIN_NAME)         return PLUGIN_HANDLED     }

v3x 04-30-2006 07:02

Use find_entity_by_class like so:
Code:
new ent = -1; while((find_ent_by_class(ent , "weaponbox")) != 0) {   entity_set_int(ent , EV_INT_flags , FL_KILLME);   p++; }

alien 05-01-2006 07:02

Is it ok to have one loop for each entity i would like to kill? I'm just asking ...
Thanks.

And btw, i'm not sure, whether it's correct to start with entid = 32 ... i made small entity listing command and noticed typical entities with id < 32. I think, it depends on player limit.

And what about weapon_bla entities? Do I have to code 1 loop for each of them? I think, it's not a solution :(

v3x 05-01-2006 16:05

Ok, then start with -1. Use the code I've provided.

VEN 05-02-2006 13:02

Max entities global should be used instead of entity_count

weaponbox also "contain" weapon_* entity which should be removed too in other case here is a chance of edict overflow.

Should be: for (new i = get_maxplayers() + 1 ...

Should be: while((ent = find_ent_by_class...

Here is the correct way:
Code:
new wprefix[] = "weapon_", class[11] new wbox, wbox_class[] = "weaponbox" new startent = get_maxplayers() + 1 new maxents = get_global_int(GL_maxEntities) for (new i = startent; i <= maxents; ++i) {     if (!is_valid_ent(i))         continue     entity_get_string(i, EV_SZ_classname, class, 7)     if (!equal(class, wprefix))         continue     wbox = entity_get_edict(i, EV_ENT_owner)     if (wbox < startent || !is_valid_ent(wbox))         continue     entity_get_string(wbox, EV_SZ_classname, class, 10)     if (!equal(class, wbox_class))         continue     kill_entity(wbox)     kill_entity(i) } stock kill_entity(id) {     entity_set_int(id, EV_INT_flags, (entity_get_int(id, EV_INT_flags) | FL_KILLME)) }

alien 05-03-2006 03:59

Works fine now!!! Thank you!!!


All times are GMT -4. The time now is 05:11.

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