defenderDeath = 0;
Diff = GetDifficulty();

function Start()
	sleep(5);
	startThread(checkWinAttacker);
	startThread(checkWinDefender);
	EnableAutoFinish(nil);
end;

function checkWinAttacker()
	repeat sleep(1); until length(GetDefenderCreatures()) == 0;
	
	playAnimation(GetAttackerHero(), "stir02", ONESHOT_STILL);
	sleep(30);
	Finish(ATTACKER);
end;

function checkWinDefender()
	repeat sleep(1); until length(GetAttackerCreatures()) == 0;
	
	sleep(30);
	Finish(DEFENDER);
end;

function DefenderCreatureDeath(creatureName)
	local x, y = GetUnitPosition(creatureName);
	defenderDeath = defenderDeath + 1;
	if defenderDeath <= 2 then
		sleep(20);
		SummonCreature(DEFENDER, 116, 30 + Diff * 10, x, y);
	end;
end;