/* Script generated by Pawn Studio */

#include <amxmodx>
#include <amxmisc>

#include <fun>

#include <orpheu>
#include <orpheu_stocks>

#define PLUGIN	"0HP Bug"
#define AUTHOR	"DarkGL"
#define VERSION	"1.0"

new msgHealth ,
	bool: catchHealth = false ,
	currentPlayer = 0;

public plugin_init(){
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	msgHealth = get_user_msgid( "Health" );
	
	new OrpheuFunction:MessageBegin = OrpheuGetEngineFunction( "pfnMessageBegin","MessageBegin" );
	new OrpheuFunction:MessageEnd = OrpheuGetEngineFunction( "pfnMessageEnd","MessageEnd" )
	
	new OrpheuFunction:WriteByte = OrpheuGetEngineFunction( "pfnWriteByte","WriteByte" );
	
	OrpheuRegisterHook( MessageBegin ,"MessageBeginf", OrpheuHookPost );
	OrpheuRegisterHook( MessageEnd ,"MessageEndf", OrpheuHookPost );
	OrpheuRegisterHook( WriteByte ,"WriteBytef", OrpheuHookPre );
}

public OrpheuHookReturn:WriteBytef( iValue ){
	
	if( isCatchTrue() ){
		
		if( iValue > 255 ){
			OrpheuSetParam( 1 , 255 );
		}
		else if( iValue <= 0 && is_user_alive( getCurrentPlayer() ) ){
			OrpheuSetParam( 1 , 1 );
		}
		
	}
	
	return OrpheuIgnored;
}

public OrpheuHookReturn:MessageBeginf(msg_dest,msg_type, const Float:pOrigin[],ed){
	
	if( msg_type == msgHealth ){
		setCatchState( true );
		setCurrentPlayer( ed );
	}
	
	return OrpheuIgnored;
}

public OrpheuHookReturn:MessageEndf(){
	setCatchState( false );
	setCurrentPlayer( 0 );
	
	return OrpheuIgnored;
}

setCatchState( bool: bState ){
	catchHealth = bState;
}

isCatchTrue(){
	return catchHealth;
}

setCurrentPlayer( id ){
	currentPlayer = id;
}

getCurrentPlayer(){
	return currentPlayer;
}
