Only mode 4 was ok.
If you redirect the shot return HAM_HANDLED.
If you want to stop the function, use HAM_SUPERCEDE (or set the trace to HIT_GENERIC)
PHP Code:
//==============================================================//
// ******************* //
// * Cvar Values * //
// ******************* //
// nhs_mode 1 Blocks bots from shooting humans in the head //
// nhs_mode 2 Blocks all headshots (Humans and bots) //
// nhs_mode 3 Headshots Only (blocks all other hitzones) //
// nhs_mode 4 Redirects all hitzones to the head //
//==============================================================//
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
new mode, bool:gBotsRegistered;
public plugin_init()
{
register_plugin("No Headshot", "1.0", "=(GrG)=");
RegisterHam(Ham_TraceAttack, "player", "HamTraceAttack");
mode = register_cvar("nhs_mode", "2");
}
public client_authorized( id )
{
if( !gBotsRegistered && is_user_bot( id ) )
{
set_task( 0.1, "register_bots", id );
}
}
public register_bots( id )
{
if( !gBotsRegistered && is_user_connected( id ) )
{
RegisterHamFromEntity( Ham_TraceAttack, id, "HamTraceAttack");
gBotsRegistered = true;
}
}
public HamTraceAttack(Vic, Att, Float:dmg, Float:dir[3], traceresult, dmgbits)
{
new Nhs_Modes = get_pcvar_num(mode);
switch(Nhs_Modes)
{
case 1: // Blocks bots from shooting humans in the head
{
if(!is_user_bot(Vic) && is_user_bot(Att))
{
if(get_tr2(traceresult, TR_iHitgroup) == HIT_HEAD)
{
// set_tr2(traceresult, TR_iHitgroup, HIT_CHEST) //uncomment to make headshots hit the chest
// return HAM_HANDLED // HANDLED doesn't stop anything
return HAM_SUPERCEDE
}
}
}
case 2: // Blocks all headshots (Humans and bots)
{
if(get_tr2(traceresult, TR_iHitgroup) == HIT_HEAD)
{
//set_tr2(traceresult, TR_iHitgroup, HIT_CHEST) //uncomment to make headshots hit the chest
//return HAM_HANDLED
return HAM_SUPERCEDE
}
}
case 3: // Headshots Only (blocks all other hitzones)
{
if(get_tr2(traceresult, TR_iHitgroup) != HIT_HEAD)
{
return HAM_SUPERCEDE
}
}
case 4:
{
if(get_tr2(traceresult, TR_iHitgroup) != HIT_HEAD)
{
//Redirects all hitzones to the head // this one is ok
set_tr2(traceresult, TR_iHitgroup, HIT_HEAD) //uncomment to make headshots hit the chest
return HAM_HANDLED
}
}
}
return HAM_IGNORED;
}
__________________