//Blaze's Enhanced Querly Death Plugin
//Weakness: If gibs are on, and a Querly gets exploded, no DeadGuy is created/replaced (gibs are made instead)
//No way to overcome this issue without editing doEventPlayerDeath (which can't be edited in a plugin)
out("Blaze's Enhanced Querly Death Plugin");

if (!variable_global_exists("querlyAdded")) global.querlyAdded = 0;
else global.querlyAdded = 1;

if (global.querlyAdded == 0) {
if file_exists("Plugins/Sprites/Damage127S.png") && file_exists("Plugins/Sprites/QuoteSmokeS.png")
&& file_exists("Plugins/Sprites/QuoteExpS.png") && file_exists("Plugins/Sounds/QuoteSnd.wav"){
global.damage127S = sprite_add("Plugins/Sprites/Damage127S.png", 1, 1, 0, 16, 4);
global.quoteSmokeS = sprite_add("Plugins/Sprites/QuoteSmokeS.png", 7, 1, 0, 8, 8);
global.quoteExpS = sprite_add("Plugins/Sprites/QuoteExpS.png", 5, 1, 0, 20, 20);
global.quoteSnd = sound_add("Plugins/Sounds/QuoteSnd.wav", 0, 1);
}else{
out("One of the files cannot be found!");
exit;
}

global.damage127 = object_add();
global.quoteSmoke = object_add();
global.quoteExp = object_add();
global.watchQuotes = object_add();

//set persistent
object_set_persistent(global.damage127, true);
object_set_persistent(global.quoteSmoke, true);
object_set_persistent(global.quoteExp, true);
object_set_persistent(global.watchQuotes, true);
object_set_sprite(global.damage127, global.damage127S);
object_set_sprite(global.quoteSmoke, global.quoteSmokeS);
object_set_sprite(global.quoteExp, global.quoteExpS);

object_event_add(global.damage127,ev_create,0,'image_speed = 0.3;
image_index = 0;
image_xscale = 2;
image_yscale = 2;
hspeed = 0;
vspeed = 1.8;
direction = 90;
image_alpha = 1;
fadeout = false;
alarm[0] = 58;
alarm[1] = 25;
alarm[2] = 45;');
object_event_add(global.damage127,ev_alarm,0,"instance_destroy();");
object_event_add(global.damage127,ev_alarm,1,"vspeed = 0;");
object_event_add(global.damage127,ev_alarm,2,"fadeout = true;");
object_event_add(global.damage127,ev_step,0,"if (fadeout) image_alpha *= 0.85;");
object_event_add(global.quoteExp,ev_create,0,'image_speed = 0.5;
image_xscale = 2;
image_yscale = 2;
image_index = 0;');
object_event_add(global.quoteExp,ev_step,0,"if (image_index == image_number-1) instance_destroy();");
object_event_add(global.quoteSmoke,ev_create,0,'image_speed = 0.3;
image_index = 0;
image_xscale = 2;
image_yscale = 2;
hspeed = random_range(2, 18);
vspeed = random_range(2, 18);
depth = random(1);');
object_event_add(global.quoteSmoke,ev_step,0,'hspeed /= 1.35; vspeed /= 1.35; if (image_index == image_number-1) instance_destroy();');

object_event_add(global.watchQuotes,ev_step,0,'
with(DeadGuy)
{
	if (sprite_index == QuoteRedS || sprite_index == CurlyBlueS) {
	playsound(x,y,global.quoteSnd)
	instance_create(x,y,global.quoteExp);
	for(i = 0; i <= 360; i+=16) {
	smoke = instance_create(x,y,global.quoteSmoke);
	smoke.direction=(random_range(i-15,i+15));
	}
	instance_create(x,y,global.damage127);
	instance_destroy();
	}
}');
}

instance_create(0,0,global.watchQuotes);