Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
new bool:can_plant
new planter, old_bombtarget
new Float:bomb_origin[3]
public plugin_init()
{
register_plugin("Plant Anywhere", "0.2", "KRoTaL")
register_cvar("sv_c4plant", "60")
register_event("TextMsg", "game_restart", "a", "1=4", "2&#Game_C", "2&#Game_w")
register_event("SendAudio", "round_end", "a", "2=%!MRAD_terwin", "2=%!MRAD_ctwin", "2=%!MRAD_rounddraw")
register_logevent("new_round", 2, "0=World triggered", "1=Round_Start")
register_event("StatusIcon", "gotbomb", "be", "1=1", "1=2", "2=c4")
old_bombtarget = find_ent_by_class(-1, "func_bomb_target")
if(old_bombtarget > 0) entity_get_vector(old_bombtarget, EV_VEC_origin, bomb_origin)
}
public gotbomb(id)
{
planter = id
return PLUGIN_CONTINUE
}
public round_end()
{
set_task(4.0, "disable_planting", 78645135)
}
public game_restart()
{
set_task(0.5, "disable_planting", 71586461)
}
public remove_all_entity(classname[])
{
new ent
while((ent = find_ent_by_class(ent,classname)) != 0) {
remove_entity(ent)
}
}
public disable_planting()
{
if(task_exists(97564673)) remove_task(97564673)
planter = 0
can_plant = false
remove_all_entity("func_bomb_target")
remove_all_entity("info_bomb_target")
new bombtarget = create_entity("func_bomb_target")
if(bombtarget > 0)
{
DispatchKeyValue(bombtarget, "classname", "func_bomb_target")
DispatchSpawn(bombtarget)
entity_set_string(bombtarget, EV_SZ_classname, "func_bomb_target")
}
bombtarget = create_entity("info_bomb_target")
if(bombtarget > 0)
{
DispatchKeyValue(bombtarget, "classname", "info_bomb_target")
DispatchSpawn(bombtarget)
entity_set_string(bombtarget, EV_SZ_classname, "info_bomb_target")
}
}
public new_round()
{
remove_all_entity("func_bomb_target")
remove_all_entity("info_bomb_target")
set_task(get_cvar_float("sv_c4plant"), "enable_planting", 97564673)
}
public enable_planting()
{
can_plant = true
create_bombtarget()
}
public create_bombtarget()
{
if(old_bombtarget > 0)
{
new bombtarget = create_entity("func_bomb_target")
if(bombtarget > 0)
{
DispatchKeyValue(bombtarget, "classname", "func_bomb_target")
DispatchSpawn(bombtarget)
entity_set_size(bombtarget, Float:{-1000000.0,-1000000.0,-1000000.0}, Float:{1000000.0,1000000.0,1000000.0})
entity_set_string(bombtarget, EV_SZ_classname, "func_bomb_target")
entity_set_origin(bombtarget, bomb_origin)
}
bombtarget = create_entity("info_bomb_target")
if(bombtarget > 0)
{
DispatchKeyValue(bombtarget, "classname", "info_bomb_target")
DispatchSpawn(bombtarget)
entity_set_size(bombtarget, Float:{-1000000.0,-1000000.0,-1000000.0}, Float:{1000000.0,1000000.0,1000000.0})
entity_set_string(bombtarget, EV_SZ_classname, "info_bomb_target")
entity_set_origin(bombtarget, bomb_origin)
}
}
}
public client_PreThink(id)
{
if(id == planter && !can_plant)
{
new clip, ammo, weapon = get_user_weapon(id, clip, ammo)
if(weapon == CSW_C4)
{
entity_set_int(id, EV_INT_button, entity_get_int(id, EV_INT_button) & ~IN_ATTACK)
}
}
}