Raised This Month: $ Target: $400
 0% 

entity purge howto


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 04-30-2006 , 01:51   entity purge howto
Reply With Quote #1

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.
alien is offline
Send a message via ICQ to alien
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 04-30-2006 , 02:41  
Reply With Quote #2

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 }
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 04-30-2006 , 06:04  
Reply With Quote #3

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 is offline
Send a message via ICQ to alien
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 04-30-2006 , 06:51  
Reply With Quote #4

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     }
alien is offline
Send a message via ICQ to alien
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 04-30-2006 , 07:02  
Reply With Quote #5

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++; }
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 05-01-2006 , 07:02  
Reply With Quote #6

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
alien is offline
Send a message via ICQ to alien
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 05-01-2006 , 16:05  
Reply With Quote #7

Ok, then start with -1. Use the code I've provided.
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 05-02-2006 , 13:02  
Reply With Quote #8

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)) }
VEN is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 05-03-2006 , 03:59  
Reply With Quote #9

Works fine now!!! Thank you!!!
alien is offline
Send a message via ICQ to alien
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 05:11.


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