Ok. I have this almost working correctly. It brings up m menu blocks my use button . And I think It un-blocks it the way i want. But when it cmes to either the explosion or the removing the bomb it crashes. And theres no errors in my logs. Any ideas ? Thank You.
Code:
#include <amxmodx>
#include <fakemeta>
#define TE_EXPLOSION 3
new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3;
new g_Switch;
new i;
new Sprite;
public plugin_init()
{
register_plugin("Cut The Right Wire","0.1","The Speicialist");
g_Switch = register_cvar("ctrw_switch","1");
register_menucmd(register_menuid("menu_show"),1023,"menu_choose");
register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");
register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");
register_forward(FM_PlayerPreThink,"block_buttons");
}
// detect defusing
public bomb_defuse_no_kit()
{
new id = get_loguser_index();
if(get_pcvar_num(g_Switch)==0)
{
return 0;
}else{
new menu[192];
format(menu,191,"Choose The Right Wire Or Die!^n1. Red^n2. Blue^n3. Green^n^n0. Die");
show_menu(id,keys,menu,-1,"menu_show");
++i;
return PLUGIN_CONTINUE;
}
return PLUGIN_CONTINUE;
}
// remove use button and show menu
public menu_choose(id,key)
{
new const Time = get_cvar_num("mp_c4timer");
new wire = random(2);
switch(key)
{
case 0 :
{
if( wire == 0 )
{
--i
set_cvar_num("mp_c4timer",(Time + 10));
return PLUGIN_HANDLED;
}else{
bomb_explosion();
return PLUGIN_HANDLED;
}
}
case 1:
{
if( wire == 1)
{
--i
set_cvar_num("mp_c4timer",(Time + 10 ));
return PLUGIN_HANDLED;
}else{
bomb_explosion();
return PLUGIN_HANDLED;
}
}
case 2 :
{
if( wire == 2 )
{
--i
set_cvar_num("mp_c4timer",(Time + 10 ));
return PLUGIN_HANDLED;
}else{
bomb_explosion();
return PLUGIN_HANDLED;
}
}
}
set_cvar_num("mp_c4timer",Time);
return PLUGIN_HANDLED;
}
// block the users use button
public block_buttons(id)
{
if( i == 0 )
{
return FMRES_HANDLED;
}else{
set_pev( id, pev_button, pev(id,pev_button) & ~IN_USE);
}
return PLUGIN_HANDLED;
}
//bomb explosion
public bomb_explosion()
{
new Bomb = fm_find_ent_by_model(-1,"grenade","models/c4.mdl");
new Location = pev(Bomb, pev_origin);
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte(TE_EXPLOSION)
write_coord(Location)
write_coord(Location)
write_coord(Location)
write_short(Sprite)
write_byte(1)
write_byte(0)
write_byte(0)
message_end()
engfunc(EngFunc_RemoveEntity, Bomb);
}
// function to get index from log events
public get_loguser_index()
{
new loguser[80], name[32];
read_logargv(0, loguser, 79);
parse_loguser(loguser, name, 31);
return get_user_index(name);
}
// finding entity by model
public fm_find_ent_by_model(index, const classname[], const model[])
{
new ent = index, mdl[72];
while ((ent = engfunc(EngFunc_FindEntityByString, index, "classname", classname)))
{
pev(ent, pev_model, mdl, 71);
if (equal(mdl, model))
{
return ent;
}
}
return 0
}
//precache sprites for exloasion
public plugin_precache()
{
Sprite = precache_model("sprites/zerogxplode.spr");
}