Code:
#include <amxmodx>
#include <engine>
#define ADMIN_ACCESS ADMIN_LEVEL_A
new maxplayers
public plugin_init()
{
register_plugin("Plant-Defuse-SaveHos", "0.2", "KRoTaL")
register_cvar("pdsh_active", "1")
maxplayers = get_maxplayers() + 1
}
public client_PreThink(id)
{
if(get_cvar_num("pdsh_active") == 0)
{
return PLUGIN_CONTINUE
}
if(!is_user_alive(id))
{
return PLUGIN_CONTINUE
}
if(get_user_flags(id) & ADMIN_ACCESS)
{
if(get_user_team(id) == 1)
{
if(get_user_button(id) & IN_USE && entity_get_int(id, 114) == 1)
{
new c4 = find_ent(-1, "grenade")
while(c4 > 0)
{
new model[32]
entity_get_string(c4, EV_SZ_model, model, 31)
if(equal(model, "models/w_c4.mdl"))
{
if(get_entity_distance(id, c4) < 72)
{
entity_set_int(id, 114, 2)
entity_set_int(id, 193, entity_get_int(id, 193) + (1<<16))
return PLUGIN_CONTINUE
}
}
c4 = find_ent(c4, "grenade")
}
new hostage = find_ent(-1, "hostage_entity")
while(hostage > 0)
{
if(get_entity_distance(id, hostage) < 72)
{
entity_set_int(id, 114, 2)
entity_set_int(id, 193, entity_get_int(id, 193) + (1<<16))
return PLUGIN_CONTINUE
}
hostage = find_ent(hostage, "hostage_entity")
}
}
if(!(get_user_button(id) & IN_USE) && get_user_oldbutton(id) & IN_USE && entity_get_int(id, 114) == 2)
{
entity_set_int(id, 114, 1)
entity_set_int(id, 193, entity_get_int(id, 193) - (1<<16))
}
}
}
return PLUGIN_CONTINUE
}
public entity_touch(entity1, entity2)
{
if(get_cvar_num("pdsh_active") == 0)
{
return PLUGIN_CONTINUE
}
if(entity1 > 0 && entity2 > 0 && entity2 < maxplayers)
{
if(get_user_flags(entity2) & ADMIN_ACCESS)
{
if(get_user_team(entity2) == 2)
{
new model[32]
entity_get_string(entity1, EV_SZ_model, model, 31)
new classname[32]
entity_get_string(entity1, EV_SZ_classname, classname, 31)
if(equal(model, "models/w_backpack.mdl"))
{
if(entity_get_int(entity2, 114) == 2)
{
entity_set_int(entity2, 114, 1)
set_task(0.1, "reset_team", entity2)
return PLUGIN_CONTINUE
}
}
if(equal(classname, "func_bomb_target"))
{
new clip, ammo, weapon = get_user_weapon(entity2, clip, ammo)
if(weapon == CSW_C4)
{
if(entity_get_int(entity2, 114) == 2)
{
if(get_user_button(entity2) & IN_ATTACK)
{
entity_set_int(entity2, 114, 1)
return PLUGIN_CONTINUE
}
}
}
else if(entity_get_int(entity2, 114) == 1)
{
entity_set_int(entity2, 114, 2)
return PLUGIN_CONTINUE
}
}
}
}
}
return PLUGIN_CONTINUE
}
public reset_team(id)
{
if(get_user_team(id) == 2 && entity_get_int(id, 114) == 1)
{
entity_set_int(id, 114, 2)
}
}