

PlayersWin = function()
	Media.PlaySoundNotification( allplayers, "AlertBuzzer")
	RateOfIncrease = 0.1
	BrightnessChangeSpeed = 3
	BrightestLight = 1.1
	if NoturnOn then
		turnOn()
	end
	
	if Difficulty == "easy" then
		Media.DisplayMessage("Good job guys you made this on Easy with " .. UnitPercent .. "0% enemy units, try Normal next time for a bigger challange.", "Materia", NameColor)
	end
	if Difficulty == "normal" then
		Media.DisplayMessage("Wow well done guys you accomplished this on Normal with " .. UnitPercent .. "0% enemy unit income, not bad but are you prepared for Hard ?", "Materia", NameColor)
	end
	if Difficulty == "hard" then
		if WaveInterval ~= 0 then
			Media.DisplayMessage("I'm really impressed, you made this on hard with " .. UnitPercent .. "0% enemy units, increase the income for a bigger challange.", "Materia", NameColor)
		end
		if WaveInterval == 0 then
			Media.DisplayMessage("What the ... , how did you do this ? i have to add a new level of difficulty for you guys, please upload this replay somewhere oO.", "Materia", NameColor)
		end
	end
	Trigger.AfterDelay(DateTime.Seconds(4), function()
		if Multi0 ~= nil then
			Multi0.MarkCompletedObjective(KillEnemysBase0)
		end
		if Multi1 ~= nil then
			Multi1.MarkCompletedObjective(KillEnemysBase1)
		end
		if Multi2 ~= nil then
			Multi2.MarkCompletedObjective(KillEnemysBase2)
		end
		if Multi3 ~= nil then
			Multi3.MarkCompletedObjective(KillEnemysBase3)
		end
		if Multi4 ~= nil then
			Multi4.MarkCompletedObjective(KillEnemysBase4)
		end
	end)
end

PlayerConquestConditions = function()
	if Multi0 ~= nil then
		KillEnemysBase0 = Multi0.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti0fact = Actor.Create("fact", true, { Location = CPos.New(13,24), Owner = Multi0 })
		Trigger.OnKilledOrCaptured(newMulti0fact, Player1Loose)
	end
	if Multi1 ~= nil then
		KillEnemysBase1 = Multi1.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti1fact = Actor.Create("fact", true, { Location = CPos.New(13,39), Owner = Multi1 })
		Trigger.OnKilledOrCaptured(newMulti1fact, Player2Loose)
	end
	if Multi2 ~= nil then
		KillEnemysBase2 = Multi2.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti2fact = Actor.Create("fact", true, { Location = CPos.New(13,50), Owner = Multi2 })
		Trigger.OnKilledOrCaptured(newMulti2fact, Player3Loose)
	end
	if Multi3 ~= nil then
		KillEnemysBase3 = Multi3.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti3fact = Actor.Create("fact", true, { Location = CPos.New(13,66), Owner = Multi3 })
		Trigger.OnKilledOrCaptured(newMulti3fact, Player4Loose)
	end
	if Multi4 ~= nil then
		KillEnemysBase4 = Multi4.AddPrimaryObjective("Destroy all the Enemys Buildings.")
		newMulti4fact = Actor.Create("fact", true, { Location = CPos.New(13,91), Owner = Multi4 })
		Trigger.OnKilledOrCaptured(newMulti4fact, Player5Loose)
	end
end


Player1Loose = function()
	Multi0.MarkFailedObjective(KillEnemysBase0)
	Media.DisplayMessage("" .. Multi0.Name .. "s mainbase has been killed!", "Materia", NameColor)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("" .. Multi0.Name .. " Is defeated!", "Materia", NameColor)
		allp1actors = Multi0.GetActors()
		for i,v in pairs(allp1actors) do
			if v.HasProperty("Health") then
				v.Stop()
				v.Kill()
			end
		end
	end)
end
Player2Loose = function()
	Multi1.MarkFailedObjective(KillEnemysBase1)
	Media.DisplayMessage("" .. Multi1.Name .. "s mainbase has been killed!", "Materia", NameColor)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("" .. Multi1.Name .. " Is defeated!", "Materia", NameColor)
		allp2actors = Multi1.GetActors()
		for i,v in pairs(allp2actors) do
			if v.HasProperty("Health") then
				v.Stop()
				v.Kill()
			end
		end
	end)
end
Player3Loose = function()
	Multi2.MarkFailedObjective(KillEnemysBase2)
	Media.DisplayMessage("" .. Multi2.Name .. "s mainbase has been killed!", "Materia", NameColor)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("" .. Multi2.Name .. " Is defeated!", "Materia", NameColor)
		allp3actors = Multi2.GetActors()
		for i,v in pairs(allp3actors) do
			if v.HasProperty("Health") then
				v.Stop()
				v.Kill()
			end
		end
	end)
end
Player4Loose = function()
	Multi3.MarkFailedObjective(KillEnemysBase3)
	Media.DisplayMessage("" .. Multi3.Name .. "s mainbase has been killed!", "Materia", NameColor)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("" .. Multi3.Name .. " Is defeated!", "Materia", NameColor)
		allp4actors = Multi3.GetActors()
		for i,v in pairs(allp4actors) do
			if v.HasProperty("Health") then
				v.Stop()
				v.Kill()
			end
		end
	end)
end
Player5Loose = function()
	Multi4.MarkFailedObjective(KillEnemysBase4)
	Media.DisplayMessage("" .. Multi4.Name .. "s mainbase has been killed!", "Materia", NameColor)
	Trigger.AfterDelay(DateTime.Seconds(3), function()
		Media.DisplayMessage("" .. Multi4.Name .. " Is defeated!", "Materia", NameColor)
		allp5actors = Multi4.GetActors()
		for i,v in pairs(allp5actors) do
			if v.HasProperty("Health") then
				v.Stop()
				v.Kill()
			end
		end
	end)
end
SetupPlayers = function()
	Enemys = Player.GetPlayer("Enemys")
	Neutral = Player.GetPlayer("Neutral")
	Multi0 = Player.GetPlayer("Multi0")
	Multi1 = Player.GetPlayer("Multi1")
	Multi2 = Player.GetPlayer("Multi2")
	Multi3 = Player.GetPlayer("Multi3")
	Multi4 = Player.GetPlayer("Multi4")
	Humans = { Multi0, Multi1, Multi2, Multi3, Multi4 }
end

