scope EscapeKey initializer init
	import Game
	import Cinematic
	import Players

	function c takes nothing returns boolean
		integer id = GetPlayerId(GetTriggerPlayer())

		if Game.singlePlayer and Cinematic.over then
			FogEnable(false)
			DisplayTextToPlayer(Players.locl, 0., 0., "|cffffcc00[Singleplayer]|r Fog Disabled!")
		end

		if Cinematic.enabled and not Game.escapesPressed[id] then
			Game.escapesPressed[id] = true
			Players.escapePressedCount++

			if Players.escapePressedCount >= Players.humanCount then
				Cinematic.interrupt()
				DisplayTextToPlayer(Players.locl, 0., 0., "|cffffcc00[Notice]|r The cinematic was skipped due to popular vote.")
			else
				DisplayTextToPlayer(GetTriggerPlayer(), 0., 0., "|cffffcc00[Notice]|r Your cinematic skip request has been registered.")
			end
		end
		return false
	end

	function init takes nothing returns nothing
		trigger t = CreateTrigger()
		integer index = 0

		loop
			exitwhen index >= Players.COUNT
			TriggerRegisterPlayerEvent(t, Players.fromId[index], EVENT_PLAYER_END_CINEMATIC)
			index++
		end

		TriggerAddCondition(t, Condition(function c))
	end
endscope
