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))
}