/* ATAC Bad Aim
*
* Copyright © 2007, ATAC Team
*
* This file is provided as is (no warranties).
*
*/

#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <atac>

#define PLUGIN "Bad Aim"
#define VERSION "1.0"
#define AUTHOR "ATAC Team"

public plugin_init()
{
	register_plugin( PLUGIN, VERSION, AUTHOR )
	atac_register_punishment()
}

public atac_punishment_name( id )
{
	new text[ 64 ]
	formatex( text, 63, "%L", id, "ATAC_BAD_AIM" )
	return engfunc( EngFunc_AllocString, text )
}

public atac_player_punish( killer, victim )
{
	exec_punishment( killer )
	return ATAC_HOOK_RESET
}

public atac_player_spawn( killer, victim )
{
	exec_punishment( killer )
	return ATAC_HOOK_RESET
}

public atac_player_reset( killer, victim )
{
	remove_task( killer )
	set_user_hitzones( killer, 0 )
}

exec_punishment( id )
{
	set_task( 10.0, "randomize_hitzones", id, _, _, "b" )
}

public randomize_hitzones( id )
{
	if ( is_user_alive( id ) )
	{
		new bodyPart, partIdx // add up to three of them back
		set_user_hitzones( id, 0, 0 ) // clear all hitzones

		for ( partIdx = 1; partIdx <= 3; partIdx++ )
		{
			bodyPart = ( 1 << 0 ) | ( 1 << random_num( 1, 7 ) )
			set_user_hitzones( id, 0, bodyPart )
		}
	}
}
