I noticed that many coders dealing with weapon drop. Often they have problems with detection of some of the following details:
: The weaponbox entity is not the actual weapon, it is the "box" entity that "contain" the weapon_* entity, i.e. the actual weapon entity. Of course weapon_* entities classnames (which equal to weapon names) are unique for the different weapon types. The actual weapon type is stored in the weapon's entity private data area that can be easily accessed via corresponding native function from the cstrike module.
Code:
/* AMX Mod X
* Weapon Drop Details
*
* (c) Copyright 2007 by VEN
*
* This file is provided as is (no warranties)
*/
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#define PLUGIN_NAME "Weapon Drop Details"
#define PLUGIN_VERSION "0.1"
#define PLUGIN_AUTHOR "VEN"
enum droptype {
droptype_manual,
droptype_onbuy,
droptype_ondeath,
droptype_ondisconnect
}
new const g_drop_type[droptype][] = {
"Manual",
"OnBuy",
"OnDeath",
"OnDisconnect"
}
new const g_drop[] = "drop"
#define MAX_PLAYERS 32
new g_command[MAX_PLAYERS + 1][sizeof g_drop + 1]
new const g_wbox_class[] = "weaponbox"
new const g_wbox_model[] = "models/w_weaponbox.mdl"
new const g_wbox_model_prefix[] = "models/w_"
stock const g_start_client_index = 1
new g_max_clients
new g_max_entities
public plugin_init() {
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_forward(FM_SetModel, "forward_set_model")
g_max_clients = global_get(glb_maxClients)
g_max_entities = global_get(glb_maxEntities)
}
public client_command(id) {
read_argv(0, g_command[id], sizeof g_drop)
}
public forward_set_model(ent, const model[]) {
if (!pev_valid(ent) || !equali(model, g_wbox_model_prefix, sizeof g_wbox_model_prefix - 1) || equali(model, g_wbox_model))
return FMRES_IGNORED
new id = pev(ent, pev_owner)
if (!(g_start_client_index <= id <= g_max_clients))
return FMRES_IGNORED
static class[32]
pev(ent, pev_classname, class, sizeof class - 1)
if (!equal(class, g_wbox_class))
return FMRES_IGNORED
for (new i = g_max_clients + 1; i < g_max_entities; ++i) {
if (!pev_valid(i) || ent != pev(i, pev_owner))
continue
new wid = cs_get_weapon_id(i)
new droptype:drop_type
if (!is_user_connected(id))
drop_type = droptype_ondisconnect
else if (!is_user_alive(id))
drop_type = droptype_ondeath
else if (equal(g_command[id], g_drop))
drop_type = droptype_manual
else if (wid != CSW_C4)
drop_type = droptype_onbuy
else
return FMRES_IGNORED
pev(i, pev_classname, class, sizeof class - 1)
server_print("BoxOwnerClientIndex: %2d, DropType: %-12s, Index: %2d, Name: %-16s, BoxEntityIndex: %3d, EntityIndex: %3d, BoxModel: %s", id, g_drop_type[drop_type], wid, class, ent, i, model)
return FMRES_IGNORED
}
return FMRES_IGNORED
}