now i got it to work but im getting a run time error for the drop_bomb function.
Code:
#include <amxmodx>
#include <engine>
#include <fun>
#include <cstrike>
// Global Variables
new g_iFollow_Bomb;
new g_iPunish;
new g_iRadius;
new g_Mode[8];
new Float:c4origin[3];
new Float:pOrigin[3];
new players[32], num, i;
public plugin_init()
{
register_plugin("Follow The Bomber","0.7","The Speicialist");
register_event("ResetHUD","reset_hud","be");
register_event("BarTime", "bomb_planting", "be", "1=3");
register_logevent("bomb_is_planted", 3, "2=Planted_The_Bomb");
register_logevent("bomb_is_dropped", 3, "2=Dropped_The_Bomb");
register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");
register_logevent("bomb_defuse_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");
g_iFollow_Bomb = register_cvar("ftb_switch","1");
g_iPunish = register_cvar("ftb_punishment","a");
g_iRadius = register_cvar("ftb_radius","1000");
set_task(2.0,"find_bomb",0,"",0,"b");
}
// reset hud event
public reset_hud(id)
{
// show message to follow the bomb terrorists
if( cs_get_user_team(id) == CS_TEAM_T && find_ent_by_class(-1 , "weapon_c4"))
{
set_hudmessage(255, 255, 255, -1.0, 0.31, 0, 6.0, 12.0);
show_hudmessage(id, "Follow The Bomb Within %i Units^n Or Be Punished!",get_pcvar_num(g_iRadius));
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
// find bomb and players in and out of range
public find_bomb(id)
{
// find the bomb
new g_iBomb = find_ent_by_class(-1,"weapon_c4");
// if cvar is off OR if there is no bomb end function
if(get_pcvar_num(g_iFollow_Bomb)==0 || g_iBomb == 0)
{
return PLUGIN_HANDLED;
}else{
// find the origin of the bomb
entity_get_vector(g_iBomb,EV_VEC_origin,c4origin);
// get all terrorists
get_players(players,num,"ace","TERRORIST");
for(i=0;i<num;i++)
{
// find the origin of alive terrorists
entity_get_vector(players[i],EV_VEC_origin,pOrigin);
// get distance from alive t's to the bomb
new Float: g_Dist = get_distance_f(c4origin,pOrigin);
new g_iDist = floatround(g_Dist);
// show hud display of how far you are from the bomb
set_hudmessage(255, 255, 255, -1.0, 0.79, 0, 6.0, 2.0);
show_hudmessage(id, "You Are %i Units From The Bomb",g_iDist);
// if alive terrorists are out of range then punish
if( g_Dist > get_pcvar_num(g_iRadius))
{
punish_mode(players[i]);
}
}
}
return PLUGIN_HANDLED;
}
// punishment function
public punish_mode(players)
{
// get string for cvars
get_pcvar_string(g_iPunish,g_Mode,7);
// read flags from string cvar
new g_iMode = read_flags(g_Mode);
new g_iArmor = get_user_armor(players);
new g_iMoney = cs_get_user_money(players);
new g_iHealth = get_user_health(players);
// dispaly hud messages for leaving bomb
set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 2.0);
show_hudmessage(players, "Your Leaving The Bomb");
// punish based on flags from cvar string
if(g_iMode & 1 ) // flag a
{
// slap the user
user_slap(players,0);
}
if(g_iMode & 2 ) // flag b
{
// -1 armor from user
set_user_armor(players,(g_iArmor - 1));
}
if(g_iMode & 4 ) // flag c
{
// strip the weapons from that user
strip_user_weapons(players);
}
if(g_iMode & 8 ) // flag d
{
// take away money from user
cs_set_user_money(players,(g_iMoney - 10));
}
if(g_iMode & 16) // flag e
{
// kill the user
user_kill(players);
}
if(g_iMode & 32 ) // flag f
{
// no punishment
return PLUGIN_HANDLED;
}
if(g_iMode & 64) // flag g
{
// take 1 health from user
set_user_health(players,(g_iHealth - 1));
}
return PLUGIN_HANDLED;
}
// bar time event detects planting
public bomb_planting(id)
{
// get user who is planting the bomb
new i;
new g_Name[32];
get_user_name(id,g_Name,31);
// get alive terrorist
get_players(players,num,"ace","TERRORIST");
for(i = 0; i < num ; ++i)
{
// display message to alive terroist
set_hudmessage(255, 255, 255, -1.0, 0.35, 0, 6.0, 12.0);
show_hudmessage(id, "%s Is Planting The Bomb Cover Him!",g_Name);
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
// logevent cathces bomb is planted message
public bomb_is_planted(id)
{
// get alive terrorist
get_players(players,num,"ace","TERRORIST");
for(i = 0; i < num ; ++i)
{
// display message to alive terroist
set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 12.0);
show_hudmessage(id, "Bomb Is Planted Defend It !");
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
// detects if the bomb was dropped
public bomb_is_dropped(players)
{
new players = get_loguser_index();
punish_mode(players);
// display mssage to who ever dropped teh bomb
set_hudmessage(255, 255, 255, -1.0, 0.19, 0, 6.0, 12.0);
show_hudmessage(players, "Pick The Bomb Back Up!");
}
// detects if the bomb is being defused with no kit
public bomb_defuse_no_kit(id)
{
// see who is defusing
new id = get_loguser_index();
new g_Name[33];
get_user_name(id,g_Name,32);
get_players(players,num,"ace","CT");
// display message to all ct's alive
for(new i = 0 ; i < num ; ++i)
{
set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0);
show_hudmessage(id, "%s Is Defusing The Bomb Wih No Kit ^n Cover Hiim!",g_Name);
}
}
// detects if the bomb is being defused with a kit
public bomb_defuse_kit(id)
{
// see who is defusing
new id = get_loguser_index();
new g_Name[33];
get_user_name(id,g_Name,32);
get_players(players,num,"ace","CT");
// display message to all ct's alive
for(new i = 0 ; i < num ; ++i)
{
set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0);
show_hudmessage(id, "%s Is Defusing The Bomb Wih A Kit ^n Cover Hiim!",g_Name);
}
}
// function to get index from log events
stock get_loguser_index()
{
new loguser[80], name[32];
read_logargv(0, loguser, 79);
parse_loguser(loguser, name, 31);
return get_user_index(name);
}