Copy to Clipboard Test

FF Low HP/MP warning SFX Code

const int SFX_FF_LOWHP_WARN = 12;//Sownd that plays, when Link is low on HP.
const int SFX_FF_LOWMP_WARN = 26;//Ditto for low MP.

const int FF_LOWHP_WARN_THRESHOLD = 25;//Low HP warning threshold, in fracunits. By default 16 HP - 1 heart.
const int FF_LOWMP_WARN_THRESHOLD = 32;//Ditto for low MP.  By default 32 MP - 1 beaker.

const int FF_LOWHP_WARN_THRESHOLD_IS_PRECENT = 1;// if >0 - threshold 
const int FF_LOWMP_WARN_THRESHOLD_IS_PRECENT = 0;//Ditto for low MP.

const int FF_LOWHP_WARN_SFX_TIMER = 15;//Low HP warning playback frequency. Lower - faster. -1 - sound plays once until recover. 
const int FF_LOWMP_WARN_SFX_TIMER = -1;//Ditto for low MP.

int lowhpwarntimer = FF_LOWHP_WARN_SFX_TIMER;
int lowmpwarntimer = FF_LOWMP_WARN_SFX_TIMER;

//FF Low HP/MP warning script

//Extended variant of default low HP warning beep. SFX ID, playback frequency and warning threshold are customizable in constants in script file.

//Global script combining. Put  LowHPWArningUpdate() command between Waitdraw and Waitframe commands in the main loop of the Active global script.

global script Warning{
	void run(){
		while(true){
			Waitdraw();
			LowHPWArningUpdate();
			Waitframe();
		}
	}
}

void LowHPWArningUpdate(){
	int threshold = FF_LOWHP_WARN_THRESHOLD;
	if (FF_LOWHP_WARN_THRESHOLD_IS_PRECENT>0)threshold = Ceiling(Link->MaxHP*FF_LOWHP_WARN_THRESHOLD/100);
	if (Link->HP<=threshold){
		if (lowhpwarntimer==FF_LOWHP_WARN_SFX_TIMER)Game->PlaySound(SFX_FF_LOWHP_WARN);
		if (FF_LOWHP_WARN_SFX_TIMER>=-1)lowhpwarntimer--;
		if (lowhpwarntimer==0)lowhpwarntimer = FF_LOWHP_WARN_SFX_TIMER;
	}
	else lowhpwarntimer = FF_LOWHP_WARN_SFX_TIMER;
	threshold = FF_LOWMP_WARN_THRESHOLD;
	if (FF_LOWMP_WARN_THRESHOLD_IS_PRECENT>0)threshold = Ceiling(Link->MaxMP*FF_LOWMP_WARN_THRESHOLD/100);
	if (Link->MP<=threshold){
		if (lowmpwarntimer==FF_LOWMP_WARN_SFX_TIMER)Game->PlaySound(SFX_FF_LOWMP_WARN);
		if (FF_LOWMP_WARN_SFX_TIMER>=-1)lowmpwarntimer--;
		if (lowmpwarntimer==0)lowmpwarntimer = FF_LOWMP_WARN_SFX_TIMER;
	}
	else lowmpwarntimer = FF_LOWMP_WARN_SFX_TIMER;
}