I made a simple plugin where you can take the C4 from your bot teammate by being in a certain distance and pressing the USE key while aiming at it. I got this idea from CSGO and since I play with bots this is really handy.
It works perfectly but I was thinking of placing a HUD message when you aim at a bot teammate carrying a C4 to inform in other players. Like maybe it would say, "Press the USE key to take the C4 from your Bot teammate" or something like that. Thing is, I don't how to do this. How do hook this 'event ' of aiming at a player?
Here's the whole code. And before you say 'this looks familiar', you're right. Its from
joaquimandrade and
ConnorMcLeod's Easy Weapon Trade plugin.
PHP Code:
#include <amxmodx>
#include <fakemeta_util>
#include <hamsandwich>
new const Plugin[] = "C4 Bot Swap"
new const Author[] = "joaquimandrade and ConnorMcLeod"
new const Version[] = "1.0"
const MaxSlots = 32
new Float:TradeMaxDistance = 300.0
public plugin_init()
{
register_plugin(Plugin,Version,Author)
RegisterHam(Ham_ObjectCaps,"player","Use_Button")
}
getLookingAt(id)
{
static Float:start[3],Float:viewOffset[3],Float:path[3],Float:dest[3]
pev(id,pev_origin,start);
pev(id,pev_view_ofs,viewOffset);
xs_vec_add(start,viewOffset,start);
pev(id,pev_v_angle,path);
engfunc(EngFunc_MakeVectors,path);
global_get(glb_v_forward,path);
xs_vec_mul_scalar(path,TradeMaxDistance,dest);
xs_vec_add(start,dest,dest);
engfunc(EngFunc_TraceLine,start,dest,0,id,0);
new hit = get_tr2(0,TR_pHit)
return 1 <= hit <= MaxSlots ? hit : 0
}
C4_Swap(id)
{
new idLookingAt = getLookingAt(id)
if(idLookingAt && (get_user_team(id) == get_user_team(idLookingAt)) && is_user_bot(idLookingAt))
{
fm_transfer_user_gun(idLookingAt, id, CSW_C4);
}
}
public Use_Button(id)
{
if(is_user_connected(id))
{
if(pev(id,pev_button) & IN_USE)
{
C4_Swap(id);
}
}
}