PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <hamsandwich>
#include <customshop>
#define TASK_HUD 5345634
#define TASK_REMOVE 2423423
new bool:has_item[33]
new bool:using_item[33]
new sync_hud1
new cvar_deadlyshot_time
additem g_deadlyshot
public plugin_init()
{
// Edit by OciXCrom: converted for Custom Shop
register_plugin("[CSHOP] Extra Item: Deadly Shot (Human)", "1.0", "Dias")
register_event("HLTV", "event_newround", "a", "1=0", "2=0")
RegisterHam(Ham_TraceAttack, "player", "fw_traceattack")
cvar_deadlyshot_time = register_cvar("ds_time", "20.0")
sync_hud1 = CreateHudSyncObj(random_num(1, 10))
}
public plugin_precache()
{
g_deadlyshot = cshop_register_item("deadlyshot", "Deadly Shot", 16000, 1)
}
public event_newround(id)
{
remove_ds(id)
}
public cshop_item_selected(id, itemid)
{
if(itemid == g_deadlyshot)
{
if(!has_item[id] || using_item[id])
{
client_print(id, print_chat, "[ZP] You bought Deadly Shot !!!")
has_item[id] = true
using_item[id] = false
set_task(0.1, "show_hud", id+TASK_HUD, _, _, "b")
} else {
client_print(id, print_chat, "[ZP] You can't buy Deadly Shot at this time...")
}
}
}
public cshop_item_removed(id, itemid)
{
if(itemid == g_deadlyshot)
{
remove_ds(id)
}
}
public show_hud(id)
{
id -= TASK_HUD
set_hudmessage(0, 255, 0, -1.0, 0.88, 0, 2.0, 1.0)
if(has_item[id])
{
ShowSyncHudMsg(id, sync_hud1, "[E] -> Active Deadly Shot")
} else if(using_item[id]) {
ShowSyncHudMsg(id, sync_hud1, "Deadly Shot - Actived")
} else {
set_hudmessage(0, 255, 0, -1.0, 0.88, 0, 2.0, 5.0)
ShowSyncHudMsg(id, sync_hud1, "Deadly Shot - Disable")
if(task_exists(id+TASK_HUD)) remove_task(id+TASK_HUD)
}
}
public client_PostThink(id)
{
static Button
Button = get_user_button(id)
if(Button & IN_USE)
{
if(has_item[id] && !using_item[id])
{
has_item[id] = false
using_item[id] = true
set_task(get_pcvar_float(cvar_deadlyshot_time), "remove_headshot_mode", id+TASK_REMOVE)
}
}
}
public fw_traceattack(victim, attacker, Float:damage, direction[3], traceresult, dmgbits)
{
if(using_item[attacker])
{
set_tr2(traceresult, TR_iHitgroup, HIT_HEAD)
}
}
public remove_ds(id)
{
if(has_item[id] || using_item[id])
{
has_item[id] = false
using_item[id] = false
if(task_exists(id+TASK_HUD)) remove_task(id+TASK_HUD)
if(task_exists(id+TASK_REMOVE)) remove_task(id+TASK_REMOVE)
}
}
public remove_headshot_mode(id)
{
id -= TASK_REMOVE
has_item[id] = false
using_item[id] = false
if(task_exists(id+TASK_HUD)) remove_task(id+TASK_HUD)
}