PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fakemeta>
#include <fakemeta_util>
new g_Classname[] = "wboxexample";
new g_Model[] = "models/w_weaponbox.mdl";
public plugin_init()
{
register_plugin("Button Entity", "1.0", "redivcram");
//RegisterHam(Ham_Use, "func_button", "EvUse", 0);
register_forward( FM_EmitSound, "fw_EmitSound");
register_clcmd("say /wb", "CmdWB");
}
public plugin_precache()
{
precache_model(g_Model);
}
public CmdWB(id)
{
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
new Float:origin[3];
fm_get_aim_origin(id, origin);
set_pev(ent, pev_classname, g_Classname);
engfunc(EngFunc_AllocString, "func_button");
//set_pev(ent, pev_target, "weaponbox_test");
engfunc(EngFunc_SetModel, ent, g_Model);
engfunc(EngFunc_SetSize, ent, Float:{-25.0, -25.0, -25.0}, Float:{25.0, 25.0, 25.0});
set_pev(ent, pev_solid, SOLID_BBOX);
engfunc(EngFunc_SetOrigin, ent, origin);
}
public fw_EmitSound(id, iChannel, szSound[], Float: fVol, Float: fAttn, iFlags, iPitch)
{
if(!is_user_alive(id))
return FMRES_IGNORED;
if( equal( szSound, "common/wpn_denyselect.wav"))
{
if(IsAimingAtEnt(id, g_Classname))
{
//Your code here.
client_print(id, print_chat, "Button Press")
}
return FMRES_SUPERCEDE;
}
return FMRES_IGNORED;
}
stock bool: IsAimingAtEnt(id, const szEntityClassName[])
{
if(!strlen(szEntityClassName) || !is_user_alive(id))
return false;
static iTarget, iBody, szClassName[32];
get_user_aiming(id, iTarget, iBody);
pev(iTarget, pev_classname, szClassName, charsmax(szClassName));
if(equal(szEntityClassName, szClassName))
return true;
return true;
}
/*public EvUse(ent, id)
{
if(!is_user_alive(id))
return HAM_IGNORED;
new target[33];
pev(ent, pev_target, target, sizeof (target) - 1);
if(equali(target, "weaponbox_test"))
{
client_print(id, print_chat, "Button Press");
}
return HAM_IGNORED;
}*/