require "Fake UI, KR and HP"
require "Papyrus Animation"

music = "nothing"
arenasize = {155,130}
wavetimer = 1/0
encountertext = ""

flee = true
fleesuccess = false
playerskipdocommand = true
unescape = true
startpos = true
progress = 0
phase = 1
Volumen = 1
timer = -1
Alternative = 0
Salir = 0
FUN = {"None", 0}

if not GetAlMightyGlobal("Seconds") then
	SetAlMightyGlobal("Seconds", 0)
end
if not GetAlMightyGlobal("Minutes") then
	SetAlMightyGlobal("Minutes", 0)
end
if not GetAlMightyGlobal("Hours") then
	SetAlMightyGlobal("Hours", 0)
end

enemies = {
"Disbelief Papyrus",
"Disbelief Sans",
"Disbelief Undyne",
"Egg Dog"
}

enemypositions = {
{0, 10},
{90, 10},
{0, 10},
{0, -10}
}

phase1 = {"Attack 1", "Attack 2", "Attack 3", "Attack 4", "Attack 5", "Attack 6", "Spare"}
phase2 = {"Intro Phase 2", "Attack 7", "Free Space", "Attack 9"}
phase3 = {"Attack 10", "Attack 11", "Attack 12"}
StatusPhase3 = {"", "", ""}

function EncounterStarting()
	if not isCYF then
		error("READ BEFORE REPORTING.\nLEA ANTES DE REPORTAR.\nПРОЧТИТЕ ПЕРЕД ТЕМ, КАК СООБЩАТЬ ОБ ОШИБКЕ.\n\nIt seems that you're NOT using CYF to play this mod, this mod only can be played on CYF and NOT Unitale.\nParece que NO estas usando CYF para jugar este mod, este mod solo puede ser jugado en CYF y NO en Unitale.\nПохоже, что вы используете НЕ CYF для игры в данную модификацию. Эту модификацию можно запустить только в CYF, НЕ В Unitale!\n\nThanks for reading and have a nice day.\nGracias por leer y ten un buen dia.\nСпасибо за то, что прочитали и хорошего вам дня.", 0)
	end
	if windows then
		Misc.WindowName = "Unofficial Disbelief Papyrus"
	end
	if not GetAlMightyGlobal("Idioma") then
		SetAlMightyGlobal("Idioma", "English")
	end
	if not GetAlMightyGlobal("Archivimentazo") then
		SetAlMightyGlobal("Archivimentazo", "00000000000000000000000000")
	end
	if not GetAlMightyGlobal("ProgresoProgresivamenteProgresante1") then
		SetAlMightyGlobal("ProgresoProgresivamenteProgresante1", "000000")
	end
	if not GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") then
		SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", "0000000")
	end
	SetAlMightyGlobal("ShortDialog", false)
	enemies[1].Call("SetBubbleOffset", {-10, 90})
	Player.name = "Chara"
	Player.lv = 19
	Player.hp = 92
	ConfigurateKR(true, false)
	Player.SetAttackAnim({"UI/Battle/spr_slice_o_0","UI/Battle/spr_slice_o_1","UI/Battle/spr_slice_o_2","UI/Battle/spr_slice_o_3","UI/Battle/spr_slice_o_4","UI/Battle/spr_slice_o_5"}, 0.1)
	GameMusic = "None"
	NewAudio.CreateChannel("One")
	NewAudio.CreateChannel("Loop")
	Inventory.AddCustomItems({"Pie", "Pay", "Пирог", "SnowPiece", "P. Nieve", "Кус. Снег.", "L. Hero", "Héroe L.", "Л. Герой", "Spaghetti", "Espagueti", "Спагетти", "C. Spaghetti", "Espagueti F.", "Х. Спагетти", "[starcolor:7d7d7d][color:7d7d7d]Nothing[color:ffffff]", "[starcolor:7d7d7d][color:7d7d7d]Nada[color:ffffff]", "[starcolor:7d7d7d][color:7d7d7d]Ничего[color:ffffff]"},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3})
	nextwaves = {"Loader"}
	State("DEFENDING")
end

function Update()
	if StartCounting then
		if StartCounting + tiempo <= Time.time and not GetAlMightyGlobal("MaxTime") then
			tiempo = tiempo + 1
			SetAlMightyGlobal("Seconds", GetAlMightyGlobal("Seconds") + 1)
			if GetAlMightyGlobal("Seconds") >= 60 then
				SetAlMightyGlobal("Minutes", GetAlMightyGlobal("Minutes") + 1)
				SetAlMightyGlobal("Seconds", GetAlMightyGlobal("Seconds") - 60)
			end
			if GetAlMightyGlobal("Minutes") >= 60 then
				SetAlMightyGlobal("Hours", GetAlMightyGlobal("Hours") + 1)
				SetAlMightyGlobal("Minutes", GetAlMightyGlobal("Minutes") - 60)
			end
			if GetAlMightyGlobal("Hours") == 9 and GetAlMightyGlobal("Minutes") == 59 and GetAlMightyGlobal("Seconds") == 59 then
				SetAlMightyGlobal("MaxTime", true)
			end
		end
	end
	if not StopEncounter then
		AnimatePapyrus()
		UpdateUI()
		if Input.GetKey("H") == 1 then
			State("ACTIONSELECT")
			nextwaves = {"No Bitch NO!"}
			State("DEFENDING")
		end
		if timer >= 0 then
			timer = timer + 1
			if timer == 31 then
				Bone = CreateSprite("Bullets/Bones/BoneP", "BelowBullet")
				Bone.MoveTo(48, -6)
				Bone.rotation = 90
			elseif timer > 31 then
				Bone.MoveTo(48, -6 + 40*math.abs(math.sin(math.rad(180/40*(timer - 31)))))
				if timer%40 == 31 and (Bad or Done) then
					Bone.Remove()
					Bone = nil
					timer = -1
				end
			end
			if Bone and Bone.y >= Player.absy - 8 and Player.absx <= 87 then
				if FUN[1] == "Legendary" and FUN[2] == 3 then
					X = Player.absx
					Y = Player.absy
					nextwaves = {"SIKE!"}
					FUN = {"None", 0}
					Player.hp = 1
					State("DEFENDING")
				else
					if Player.hp > 20 then
						Player.Hurt(20)
					elseif Player.hp > 1 then
						Player.Hurt(Player.hp - 1)
					end
				end
			end
		end
		if phase == -1 then
			if GameMusic == "ShortIntro" then
				NewAudio.PlaySound("One", "Intro Phase 1 Short", false, 1)
				NewAudio.SetPlayTime("One", 0)
				GameMusic = "Slow"
			elseif GameMusic == "Slow" and NewAudio.GetPlayTime("One") > 0.9 then
				if Volumen > 0 then
					Volumen = Volumen - 0.004
				end
				NewAudio.SetPitch("One", Volumen)
				if Volumen <= 0 then
					NewAudio.Stop("One")
					NewAudio.SetPitch("One", 1)
					GameMusic = "None"
					Volumen = 1
				end
			end
		elseif phase == 1 then
			if GameMusic == "StartImmediate" then
				NewAudio.PlaySound("One", "Intro Phase 1", false, 1)
				NewAudio.SetPlayTime("One", 22.645)
				GameMusic = "Intro"
			elseif GameMusic == "Start" then
				NewAudio.PlaySound("One", "Intro Phase 1", false, 1)
				GameMusic = "Intro"
			elseif GameMusic == "Intro" and (NewAudio.GetPlayTime("One") > 78.28 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop Phase 1", true, 1)
				GameMusic = "Playing"
			elseif GameMusic == "Volume" then
				if Volumen > 0.2 then
					Volumen = Volumen - 0.01
				end
				NewAudio.SetVolume("Loop", Volumen)
			elseif GameMusic == "Cry" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Ending Phase 1", false, Volumen)
				GameMusic = "Crying"
			elseif GameMusic == "Crying" then
				if Volumen < 1 then
					Volumen = Volumen + 0.01
				end
				NewAudio.SetVolume("One", Volumen)
			elseif GameMusic == "Believe" then
				NewAudio.PlaySound("Loop", "Believe", true, 1)
				GameMusic = "Wait"
			elseif GameMusic == "Stop" then
				NewAudio.SetPitch("Loop", 1)
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				Volumen = 1
				GameMusic = "End"
				phase = 2
				progress = 0
			elseif GameMusic == "NYEH!" then
				Volumen = Volumen - 0.01
				if NewAudio.GetVolume("One") > Volumen then
					NewAudio.SetVolume("One", Volumen)
				end
				if NewAudio.GetVolume("Loop") > Volumen then
					NewAudio.SetVolume("Loop", Volumen)
				end
				if Volumen <= 0 then
					NewAudio.SetVolume("One", 0)
					NewAudio.Stop("One")
					NewAudio.PlaySound("Loop", "Papyrus", true, 1)
					GameMusic = "WOWIE"
				end
			end
		elseif phase == 2 then
			if GameMusic == "Start" then
				NewAudio.PlaySound("One", "Intro Phase 2", false, 1)
				GameMusic = "Intro"
			elseif GameMusic == "Intro" and (NewAudio.GetPlayTime("One") > 13.34 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("One", "Intro 1 Phase 2", false, 1)
				GameMusic = "Loop 1"
			elseif GameMusic == "Loop 1" and (NewAudio.GetPlayTime("One") > 13.3 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 1 Phase 2", true, 1)
				GameMusic = "Wait 1"
			elseif GameMusic == "Continue 1" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 2 Phase 2", false, 1)
				GameMusic = "Loop 2"
			elseif GameMusic == "Loop 2" and (NewAudio.GetPlayTime("One") > 13.3 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 2 Phase 2", true, 1)
				GameMusic = "Wait 2"
			elseif GameMusic == "Continue 2" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 3 Phase 2", false, 1)
				GameMusic = "Loop 3"
			elseif GameMusic == "Loop 3" and (NewAudio.GetPlayTime("One") > 53.84 or NewAudio.isStopped("One")) then
				NewAudio.SetPlayTime("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "Loop 3 Phase 2", true, 1)
				GameMusic = "Wait 3"
			elseif GameMusic == "Continue 3" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 4 Phase 2", false, 1)
				GameMusic = "Wait 4"
			elseif GameMusic == "Continue 4" then
				NewAudio.SetVolume("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "choice", true, 1)
				GameMusic = "Wait 5"
			end
		elseif phase == 3 then
			if GameMusic == "Prepare" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 1 Phase 3", false, 1)
				GameMusic = "Waiting"
			elseif GameMusic == "Waiting" and (NewAudio.GetPlayTime("One") > 25.02 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 1 Phase 3", true, 1)
				GameMusic = "Wait 1"
			elseif GameMusic == "Continue 1" and ((NewAudio.GetPlayTime("Loop") > 2.37 and NewAudio.GetPlayTime("Loop") <= 2.4) or NewAudio.GetPlayTime("Loop") > 4.77) then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 2 Phase 3", false, 1)
				GameMusic = "Loop 1"
			elseif GameMusic == "Loop 1" and (NewAudio.GetPlayTime("One") > 48.24 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 2 Phase 3", true, 1)
				GameMusic = "Wait 2"
			elseif GameMusic == "Continue 2" and NewAudio.GetPlayTime("Loop") > 9.59 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 3 Phase 3", false, 1)
				GameMusic = "Loop 2"
			elseif GameMusic == "Loop 2" and (NewAudio.GetPlayTime("One") > 30.9 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 3 Phase 3", true, 1)
				GameMusic = "Wait 3"
			elseif GameMusic == "Continue 3" and NewAudio.GetPlayTime("Loop") > 2.37 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 4 Phase 3", false, 1)
				GameMusic = "Loop 3"
			elseif GameMusic == "Loop 3" and (NewAudio.GetPlayTime("One") > 105.58 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 4 Phase 3", true, 1)
				GameMusic = "Wait 4"
			elseif GameMusic == "Continue 4" and ((NewAudio.GetPlayTime("Loop") > 4.77 and NewAudio.GetPlayTime("Loop") <= 4.8) or NewAudio.GetPlayTime("Loop") > 9.58) then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 5 Phase 3", false, 1)
				GameMusic = "Loop 4"
			elseif GameMusic == "Loop 4" and (NewAudio.GetPlayTime("One") > 0.24 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 5 Phase 3", true, 1)
				GameMusic = "Wait 5"
			elseif GameMusic == "Continue 5" and NewAudio.GetPlayTime("Loop") > 1.17 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 6 Phase 3", false, 1)
				GameMusic = "End"
			end
		elseif phase == 4 then
			if GameMusic == "Finale" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Phase 4", false, 1)
				GameMusic = "It's Over"
			elseif GameMusic == "NYEH!" then
				NewAudio.SetVolume("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "Papyrus Slow", true, 1)
				GameMusic = "WOWIE"
			end
		end
		if GameMusic == "Fade" then
			Volumen = Volumen - 0.005
			if NewAudio.GetVolume("One") > Volumen then
				NewAudio.SetVolume("One", Volumen)
			end
			if NewAudio.GetVolume("Loop") > Volumen then
				NewAudio.SetVolume("Loop", Volumen)
			end
			if Volumen <= 0 then
				GameMusic = "End"
			end
		end
		if timerMiss then
			timerMiss = timerMiss + 1
			if timerMiss == 90 then
				Miss.Remove()
				Miss = nil
				timerMiss = nil
			end
		end
		if GetAlMightyGlobal("Idioma") then
			if Input.GetKey("Escape") > 0 then
				if not Quitando then
					Quitando = CreateSprite("Quiting1 "..GetAlMightyGlobal("Idioma"),"OverTop")
					Quitando.MoveTo(90, 460)
					Quitando.color = {0.75, 0.75, 0.75}
				end
				Salir = Salir + 1
			else
				if Quitando then
					Quitando.Remove()
					Quitando = nil
				end
				Salir = 0
			end
			if Quitando then
				Quitando.alpha = 1/80*Salir
				if Salir == 40 then
					Quitando.Set("Quiting2 "..GetAlMightyGlobal("Idioma"))
				elseif Salir == 80 then
					Quitando.Set("Quiting3 "..GetAlMightyGlobal("Idioma"))
				end
			end
			if Salir == 120 then
				Finalizar = true
			end
		end
	end
	if Finalizar then
		State("DONE")
	end
end

function EnteringState(new, old)
	if new == "ATTACKING" then
		if phase == -1 then
			nextwaves = {"Dude NO"}
			State("DEFENDING")
		elseif phase == 4 and (not Scared or Scared <= 4) then
			Animation = "WAIT!"
			vel = 0
		end
	elseif Player.absy < 175 and old == "MERCYMENU" and (new == "ENEMYDIALOGUE" or new == "DIALOGRESULT") then
		if phase == 1 then
			if progress == 6 and (not enemies[1]["Disculpado2"] or (enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] ~= 0)) then
				nextwaves = {"Overworld/Flee"}
				State("DEFENDING")
			elseif not SelectedFlee then
				nextwaves = {"Flee"}
				State("DEFENDING")
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					BattleDialog({"[effect:none]Papyrus no te dejará escapar."})
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
					BattleDialog({"[effect:none]Папирус не даст вам сбежать."})	
				else
					BattleDialog({"[effect:none]Papyrus won't let you run away."})
				end
			end
			SelectedFlee = true
		elseif phase == 4 then
			if not SelectedFlee2 then
				nextwaves = {"Flee"}
				State("DEFENDING")
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					BattleDialog({"[effect:none]Papyrus no te dejará escapar."})
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    BattleDialog({"[effect:none]Папирус не даст вам сбежать."})	
				else
					BattleDialog({"[effect:none]Papyrus won't let you run away."})
				end
			end
			SelectedFlee2 = true
		else
			if phase == 3 and progress == 0 and not (FUN[1] == "Rare" and FUN[2] == 3) then
				Audio["menuconfirm"] = "st"
			end
			nextwaves = {"Flee"}
			State("DEFENDING")
		end
	elseif new == "ENEMYDIALOGUE" and phase == 4 and Bubbles[1] then
		Bubble("", "", 0, 0, 0, 0, 1)
	elseif new == "ACTIONSELECT" and old == "DEFENDING" then
		if phase == 4 and not moved then
			SetAction("ACT")
			moved = true
		elseif phase == 1 and progress == 0 and not startpos then
			SetAction("FIGHT")
			startpos = true
		elseif phase == 2 and progress == 3 and posto then
			SetAction(posto)
			posto = nil
		end
	end
	if new == "MERCYMENU" and (GetAlMightyGlobal("Idioma") == "Spanish" or GetAlMightyGlobal("Idioma") == "Russian") then
		Perdonar = CreateSprite("Specials/Spare "..GetAlMightyGlobal("Idioma"),"Top")
		Perdonar.MoveTo(146, 189)
		if enemies[1]["canspare"] == true then
			Perdonar.color = {1, 1, 0}
		end
		if flee == true then
			Huir = CreateSprite("Specials/Flee "..GetAlMightyGlobal("Idioma"),"Top")
			Huir.MoveTo(139, 163)
		end
	elseif old == "MERCYMENU" and Perdonar then
		Perdonar.Remove()
		if Huir then
			Huir.Remove()
		end
		Perdonar = nil
		Huir = nil
	end
	if new == "ITEMMENU" and (GetAlMightyGlobal("Idioma") == "Spanish" or GetAlMightyGlobal("Idioma") == "Russian") then
		Page = CreateSprite("Specials/PAGE "..GetAlMightyGlobal("Idioma"),"Top")
		Page.MoveTo(369.5, 136)
	elseif old == "ITEMMENU" and Page then
		Page.Remove()
		Page = nil
	end
	if old == "DIALOGRESULT" then
		Inventory.SetInventory(Items)
	end
	UpdateStatesUI(new, old)
end

function EnemyDialogueStarting()
	if GetAlMightyGlobal("Idioma") == "Russian" then
		enemies[4]["randomdialogue"] = {"[effect:none] яйцо", "[effect:none] яйцо?", "[effect:none] ЯЙЦО!", " яйцооо~"}
	else
		enemies[4]["randomdialogue"] = {"[effect:none] egg egg", "[effect:none] egg?", "[effect:none] EGG!", " eegggg~"}
	end
	if GameOver then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]LO SIENTO HUMANO..."})
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
		    enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]ПРОСТИ,[w:5] ЧЕЛОВЕК..."})
		else
			enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]I'M SORRY HUMAN..."})
		end
	elseif phase == 1 then
		if progress < 6 and (Alternative < 1 or Alternative > 2) then
			progress = progress + 1
		end
		if progress == 1 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]DEJAME SABER\nSI ESTO DUELE."})
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
		        enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]ДАЙ ЗНАТЬ,[w:5] ЕСЛИ\nБУДЕТ БОЛЬНО."})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]LET ME KNOW\nIF THIS HURTS."})
			end
		elseif progress >= 2 and progress <= 6 and Spared and not Perdonando then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]ESTO ME DUELE\nMÁS DE LO QUE\nTE DUELE A TI."})
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]МНЕ ОТ ЭТОГО\nКУДА БОЛЬНЕЕ,[w:5]\nЧЕМ ТЕБЕ."})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]THIS HURTS ME\nMORE THAN IT\nHURTS YOU."})
			end
			Perdonando = true
		end
		if progress == 6 then
			if Ask and Ask == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]OH[w:10]\n[func:Head,Okay...]ENTIENDO..."})
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]OУ[w:10],\n[func:Head,Okay...]ЯСНО..."})
				else
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]OH[w:10]\n[func:Head,Okay...]I UNDERSTAND..."})
				end
				Ask = 4
			elseif Ask and Ask == 3 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head,Nyehehehe]GRACIAS[w:10]\nNYEHEHEHE..."})
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head,Nyehehehe]СПАСИБО[w:10]\nНЬЕ-ХЕ-ХЕ-ХЕ..."})
				else
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head,Nyehehehe]THANKS[w:10]\nNYEHEHEHE..."})
				end
				Ask = 4
			end
			if Ask and Ask == 4 and string.sub(GetAlMightyGlobal("Archivimentazo"), 13, 13) == "0" then
				SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 12).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 14))
				LogroDesbloqueado = {Timer = 0, Icon = 13}
			end
			enemies[1].SetVar("canspare", true)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1]["commands"][4] = "Consolar"
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				enemies[1]["commands"][4] = "Утешить"	
			else
				enemies[1]["commands"][4] = "Console"
			end
		end
	elseif phase == 2 or phase == 3 then
		progress = progress + 1
		if progress == 1 then
			Player.sprite.alpha = 0
		end
	end
end

function EnemyDialogueEnding()
	if GameOver then
		nextwaves = {"Sorry Human"}
	elseif phase == -1 then
		nextwaves = {"Spare"}
	elseif phase == 1 then
		if Alternative == 1 then
			nextwaves = {"Egg "..math.random(3)}
		else
			if progress <= 5 then
				SetHead("Believe")
			end
			if not Done then
				if Ask and Ask == 0 then
					nextwaves = {"Answer"}
					Ask = 1
				else
					nextwaves = {phase1[math.min(progress, 7)]}
				end
				if progress == 6 then
					phase1[6] = "Spare"
				elseif progress == 7 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 then
					nextwaves = {"Betrayal"}
				end
			else
				nextwaves = {"Overworld/Pacifist"}
			end
		end
	elseif phase == 2 then
		nextwaves = {phase2[progress]}
	elseif phase == 3 then
		if progress == 2 and FUN[1] == "Rare" and FUN[2] == 2 and enemies[2]["Hitted"] then
			nextwaves = {"Sans Dying"}
		else
			nextwaves = {phase3[progress]}
		end
	elseif phase == 4 then
		if Scared == 6 and string.sub(GetAlMightyGlobal("Archivimentazo"), 11, 11) == "0" then
			SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 10).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 12))
			LogroDesbloqueado = {Timer = 0, Icon = 11}
		end
		if not Bad and not Done then
			nextwaves = {"Spare"}
		elseif Bad then
			nextwaves = {"Die"}
		elseif Done then
			nextwaves = {"Overworld/Pacifist"}
		end
	end
end

function DefenseEnding()
	if GameOver then
		State("ENEMYDIALOGUE")
	elseif phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			encountertext = "Dónde consiguió Papyrus\runa silla de ruedas?!"
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
		    encountertext = "Откуда Папирус взял кресло-\rкаталку?!"
		else
			encountertext = "Where did Papyrus get a\rwheelchair?!"
		end
	elseif phase == 1 then
		if SuperCry then
			nextwaves = {"Box"}
			State("DEFENDING")
			SuperCry = nil
		end
		if Alternative == 1 then
			if not DialogEgg then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Te enfrentas a un Egg Dog."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Вы столкнулись с Яйцепсом."
				else
					encountertext = "You confront an Egg Dog."
				end
				DialogEgg = true
			else
				local randomizador = math.random(3)
				if randomizador == 1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Esto no se ve como el mejor uso\rde tu tiempo."
					elseif GetAlMightyGlobal("Idioma") == "Russian" then
					    encountertext = "Похоже,[w:5] что это не стоит\rвашего времени."
					else
						encountertext = "This doesn't seem like the best\ruse of your time."
					end
				elseif randomizador == 2 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Huele a caninos y omelettes."
					elseif GetAlMightyGlobal("Idioma") == "Russian" then
					    encountertext = "Пахнет собакой с омлетом."
					else
						encountertext = "Smells like canine and\romelettes."
					end
				else
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Egg Dog salta emocionado."
					elseif GetAlMightyGlobal("Idioma") == "Russian" then
					    encountertext = "Яйцепёс радостно прыгает\rвокруг."
					else
						encountertext = "Egg Dog jumps around excitedly."
					end
				end
			end
		else
			if progress == 0 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus ya no cree en ti..."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Папирус больше не верит в вас..."
				else
					encountertext = "Papyrus no longer believes in\ryou..."
				end
			elseif progress == 1 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus te mira con una\rexpresión de disculpa."
			    elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Папирус смотрит на вас\rпрощающим взглядом."
				else
					encountertext = "Papyrus glares at you with\ran apologetic expression."
				end
			elseif progress == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Te haz metido en una situación\rmuy incómoda."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Вы попали в весьма некомфортную\rситуацию."
				else
					encountertext = "You've gotten yourself into a\rvery uncomfortable situation."
				end
			elseif progress == 3 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Parece molesti."
			    elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Похоже,[w:5] что он распустил нюни."
				else
					encountertext = "He seems upsetti."
				end
			elseif progress == 4 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus traiciona sus verdaderos\rcolores."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then	
					encountertext = "Папирус предаёт своё истинное\rлицо."
				else
					encountertext = "Papyrus betrays his true colors."
				end
			elseif progress == 5 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "No molestes al esqueleto."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then	
				    encountertext = "Не дразни скелета."
				else
					encountertext = "Don't noogie the skeleton."
				end
			elseif progress == 6 then
				if enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "[color:ff0000][voice:chara]Papyrus está distraído =)"
					elseif GetAlMightyGlobal("Idioma") == "Russian" then	
					    encountertext = "[color:ff0000][voice:chara]Папирус отвлечён =)"
					else
						encountertext = "[color:ff0000][voice:chara]Papyrus is distracted =)"
					end
				else
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Acaba con esto."
				    elseif GetAlMightyGlobal("Idioma") == "Russian" then
				        encountertext = "Покончи с этим."						
					else
						encountertext = "Get it over with."
					end
				end
			elseif progress == 7 or progress == 10 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then				
					encountertext = "Acaba con esto."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Покончи с этим."
				else
					encountertext = "Get it over with."
				end
			elseif progress == 9 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Haz que te lastime."
				elseif GetAlMightyGlobal("Idioma") == "Russian" then	
				    encountertext = "Заставь его навредить тебе."
				else
					encountertext = "Make him hurt you."
				end
			end
		end
	elseif phase == 2 then
		if progress == 1 then
			enemies[1].Call("SetDamageUIOffset", {0, 600})
			enemies[1].SetVar("canspare", false)
			if FUN[1] == "Epic" and FUN[2] == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "De dónde vino ese Espagueti?!"
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Откуда взялись эти Спагетти?!"
				else
					encountertext = "Where did that Spaghetti come\rfrom?!"
				end
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Parece que lo has hecho enojar."
			    elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    encountertext = "Похоже вы его разозлили."
				else
					encountertext = "Looks like you've made him angry."
				end
			end
		elseif progress == 3 then
			Backup = Items
			Items = {}
			for i=1,math.max(#Backup, 4) do
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					table.insert(Items, "Espagueti")
				elseif GetAlMightyGlobal("Idioma") == "Russian" then
				    table.insert(Items, "Спагетти")
				else
					table.insert(Items, "Spaghetti")
				end
			end
			Backup = nil
			Inventory.SetInventory(Items)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Sans hubiera encontrado esto\rhúmeroso."	
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    encountertext = "Санс бы посчитал это до костей\rуморительным."
			else
				encountertext = "Sans would have found this\rhumerus."
			end
		end
	elseif phase == 3 then
		if progress == 0 then
			Player.SetAttackAnim({"UI/Battle/spr_slice_o_0","UI/Battle/spr_slice_o_1","UI/Battle/spr_slice_o_2","UI/Battle/spr_slice_o_3","UI/Battle/spr_slice_o_4","UI/Battle/spr_slice_o_5"}, 0.1)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Los buenos recuerdos se\rdesvanecen..."
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    encountertext = "Хорошие воспоминания постепенно\rисчезают..."
			else
				encountertext = "The good memories are fading\raway..."
			end
		elseif progress == 1 then
			enemies[1]["monstersprite"].x = -90
			enemies[2].Call("SetActive", true)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "A pesar de todo[w:5], sientes más\rpecados."
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    encountertext = "И всё же[w:5], вы чувствуете всё\rбольше грехов."
			else
				encountertext = "Yet[w:5], more sins are felt."
			end
		elseif progress == 2 then
			enemies[1]["monstersprite"].x = 0
			enemies[3].Call("SetActive", true)
			enemies[1].Call("SetActive", false)
			enemies[2].Call("SetActive", false)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "No odias cuando el pescado es\rservido con huesos?"
		    elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    encountertext = "Ну разве не ужасно, когда рыбу\rподают с костями?"
			else
				encountertext = "Don't you just hate it when fish\ris served with bones?"
			end
		end
	elseif phase == 4 then
		enemies[1].Call("SetActive", true)
		enemies[2].Call("SetActive", false)
		enemies[3].Call("SetActive", false)
		if not SkipBoxDialog then
			encountertext = "..."
		else
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Realmente pensante que te\rmataría justo al final?![w:10]\nCon amor[w:10], Cezar Andrade."
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
			    encountertext = "Неужто ты думал[w:5],\rчто я убью тебя в конце?![w:10]\nС любовью[w:10], Cezar Andrade."
			else
				encountertext = "Did you really think I would\rkill you right at the end?![w:10]\nWith love[w:10], Cezar Andrade."
			end
		end
		SkipBoxDialog = nil
		enemies[1]["canspare"] = true
	end
	Player.sprite.alpha = 1
end

function HandleSpare()
	if phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			BattleDialog({"[effect:none][color:ff0000][voice:chara]QUE ESTAS HACIENDO?![w:10]\nSOLO MÁTALO YA."})
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
		    BattleDialog({"[effect:none][color:ff0000][voice:chara]ЧТО ТЫ ДЕЛАЕШЬ?![w:10]\nПРОСТО УБЕЙ ЕГО УЖЕ."})
		else
			BattleDialog({"[effect:none][color:ff0000][voice:chara]WHAT ARE YOU DOING?![w:10]\nJUST KILL HIM ALREADY."})
		end
		enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]???"})
	elseif phase == 1 and Alternative ~= 1 then
		if progress >= 1 and progress <= 5 then
			Spared = true
		elseif progress == 6 and (not enemies[1]["Disculpado2"] or (enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] ~= 0)) then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 20][func:Head, What]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 0][w:16][func:Arms, -140][func:Head, Finally!][func:Song][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 20][func:Head, What]ТЫ [color:f2c900]ЩАДИШЬ[color:000000]\nМЕНЯ?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 0][w:16][func:Arms, -140][func:Head, Finally!][func:Song][func:Jaw, 22]ВАУШКИ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ПОСТОЙ[w:10], ЭТО ЧТО[w:10],\nУЛОВКА...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]ПРОШУ ПРОЩЕНИЯ,[w:10]\nПРОСТО...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]Я ЭТОГО ТОЧНО\nНЕ ОЖИДАЛ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]Я ДУМАЛ[w:10], ЧТО\nТЫ ПОСТУПИШЬ\nНЕПРАВИЛЬНО.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]НО ТЫ СДЕЛАЛ\nВЕРНЫЙ ВЫБОР!!"})
			else 		
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 20][func:Head, What]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 0][w:16][func:Arms, -140][func:Head, Finally!][func:Song][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "Fade"
			Done = true
		elseif progress == 6 and enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] == 0 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Disappointed]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})								  
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]ТЫ [color:f2c900]ЩАДИШЬ[color:000000]\nМЕНЯ?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]ВАУШКИ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ПОСТОЙ[w:10], ЭТО ЧТО[w:10],\nУЛОВКА...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]ПРОШУ ПРОЩЕНИЯ,[w:10]\nПРОСТО...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]Я ЭТОГО ТОЧНО\nНЕ ОЖИДАЛ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]Я ДУМАЛ[w:10], ЧТО\nТЫ ПОСТУПИШЬ\nНЕПРАВИЛЬНО.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]НО ТЫ СДЕЛАЛ\nВЕРНЫЙ ВЫБОР!!"})
			else 		
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Disappointed]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "NYEH!"
			Volumen = 1
			Done = true
		elseif progress >= 7 then
			Legs.Set("Papyrus/Legs/Front")
			Body.MoveTo(0, 72)
			Head.MoveTo(4, 62)
			Jaw.MoveTo(Head.x, Head.y - 20)
			Animation = "None"
			fadeGlow = true
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]ТЫ [color:f2c900]ЩАДИШЬ[color:000000]\nМЕНЯ?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]ВАУШКИ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ПОСТОЙ[w:10], ЭТО ЧТО[w:10],\nУЛОВКА...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]ПРОШУ ПРОЩЕНИЯ,[w:10]\nПРОСТО...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]Я ЭТОГО\nТОЧНО НЕ ОЖИДАЛ!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]Я ДУМАЛ,[w:10] ЧТО\nТЫ ПОСТУПИШЬ\nНЕПРАВИЛЬНО.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]НО ТЫ СДЕЛАЛ\nВЕРНЫЙ ВЫБОР!!"})
			else 							  
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "NYEH!"
			Volumen = 1
			Done = true
		end
	elseif phase == 3 then
		StatusPhase3[progress + 1] = "Spare"
		if progress == 2 then
			moved = true
		end
	elseif phase == 4 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, huh]. . .?",
							  "[noskip][font:papyrus][voice:papyrus][effect:none]REALMENTE\nME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Thinking]ESO ES...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Well]GENIAL[w:10][func:Head, Thinking], PERO...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:SpecialHead]...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, HEY!][func:Music]PERO HEY![w:10] NO\nTODO ESTA\nPERDIDO AUN!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Look!]SOLO MIRATE![w:10]\nHICISTE LO\nCORRECTO!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, YES!]SOLAMENTE\nNECESITABAS\nEL APOYO DE MI[w:10][func:Head, NYEH HEH],\nEL GRAN PAPYRUS!"})
	    elseif GetAlMightyGlobal("Idioma") == "Russian" then
			enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, huh]. . .?",
							  "[noskip][font:papyrus][voice:papyrus][effect:none]ТЫ ДЕЙСТВИТЕЛЬНО\n[color:f2c900]ЩАДИШЬ[color:000000] МЕНЯ?!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Thinking]ЭТО...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Well]ЗАМЕЧАТЕЛЬНО[w:10][func:Head, Thinking],\nНО...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:SpecialHead]...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, HEY!][func:Music]НО ЭЙ![w:10] ЕЩЁ НЕ\nВСЁ ПОТЕРЯНО!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Look!]ПОСМОТРИ НА\nСЕБЯ![w:10]\nТЫ СДЕЛАЛ\nВЕРНЫЙ ВЫБОР!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, YES!]ТЕБЕ ВСЕГО ЛИШЬ\nБЫЛА НУЖНА\nПОДДЕРЖКА[func:Head, NYEH HEH]\nВЕЛИКОГО\nПАПИРУСА!"})
	    else 		
			enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, huh]. . .?",
							  "[noskip][font:papyrus][voice:papyrus][effect:none]ARE YOU REALLY\n[color:f2c900]SPARING[color:000000] ME?!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Thinking]THAT IS...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Well]GREAT[w:10][func:Head, Thinking], BUT...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:SpecialHead]...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, HEY!][func:Music]BUT HEY![w:10] NOT ALL\nIS LOST YET!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Look!]JUST LOOK AT\nYOURSELF![w:10]\nYOU DID THE RIGHT\nTHING!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, YES!]YOU ONLY NEEDED\nTHE SUPPORT OF\nME[w:10][func:Head, NYEH HEH], THE GREAT\nPAPYRUS!"})
		end
		Done = true
	end
	if phase ~= -1 then
		State("ENEMYDIALOGUE")
	end
end

function HandleItem(ID)
	if phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			BattleDialog({"[effect:none][color:ff0000][voice:chara]No desperdicies tus Objetos."})
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			BattleDialog({"[effect:none][color:ff0000][voice:chara]Не трать свои Вещи впустую."})
		else
			BattleDialog({"[effect:none][color:ff0000][voice:chara]Don't waste your Items."})
		end
	else
		if ID == "PIE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Butterscotch Pie[w:10]\n"..MessageHeal(200),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Butterscotch Pie[w:10]\n"..MessageHeal(200)})
				end
				Player.Heal(200)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Butterscotch Pie]"})
			end
			for i=1,#Items do
				if Items[i] == "Pie" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "PAY" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Pay de Caramelo[w:10]\n"..MessageHeal(200),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Pay de Caramelo[w:10]\n"..MessageHeal(200)})
				end
				Player.Heal(200)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Pay de Caramelo]"})
			end
			for i=1,#Items do
				if Items[i] == "Pay" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "ПИРОГ" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Вы съели Ирисковый Пирог.[w:10]\n"..MessageHeal(200),"Папирус так же нашёл немного\rеды.[w:10]\nВы оба неплохо перекусили."})
				else
					BattleDialog({"[effect:none]Вы съели Ирисковый Пирог[w:10]\n"..MessageHeal(200)})
				end
				Player.Heal(200)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Вы съели[func:SpawnText,Ирисковый Пирог]"})
			end
			for i=1,#Items do
				if Items[i] == "Пирог" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "SNOWPIECE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Snowman Piece.[w:10]\n"..MessageHeal(45),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Snowman Piece.[w:10]\n"..MessageHeal(45)})
				end
				Player.Heal(45)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Snowman Piece]"})
			end
			for i=1,#Items do
				if Items[i] == "SnowPiece" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "P. NIEVE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Pedazo de Nieve[w:10]\n"..MessageHeal(45),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Pedazo de Nieve[w:10]\n"..MessageHeal(45)})
				end
				Player.Heal(45)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Pedazo de Nieve]"})
			end
			for i=1,#Items do
				if Items[i] == "P. Nieve" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "КУС. СНЕГ." then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Вы съели Кусок Снеговика.[w:10]\n"..MessageHeal(45),"Папирус так же нашёл немного\rеды.[w:10]\nВы оба неплохо перекусили."})
				else
					BattleDialog({"[effect:none]Вы съели Кусок Снеговика.[w:10]\n"..MessageHeal(45)})
				end
				Player.Heal(45)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Вы съели[func:SpawnText,Кусок Снеговика]"})
			end
			for i=1,#Items do
				if Items[i] == "Кус. Снег." then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "L. HERO" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Legendary Hero.[w:10]\nYour ATTACK increased by 4![w:10]\n"..MessageHeal(40),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Legendary Hero.[w:10]\nYour ATTACK increased by 4![w:10]\n"..MessageHeal(40)})
					if Alternative == 1 then
						enemies[4]["def"] = enemies[4]["def"] - 40
					end
				end
				Player.Heal(40)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Legendary Hero]"})
			end
			for i=1,#Items do
				if Items[i] == "L. Hero" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "HÉROE L." then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Héroe Legendario[w:10]\nTu ATAQUE aumentó por 4![w:10]\n"..MessageHeal(40),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Héroe Legendario[w:10]\nTu ATAQUE aumentó por 4![w:10]\n"..MessageHeal(40)})
					if Alternative == 1 then
						enemies[4]["def"] = enemies[4]["def"] - 40
					end
				end
				Player.Heal(40)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Héroe Legendario]"})
			end
			for i=1,#Items do
				if Items[i] == "Héroe L." then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "Л. ГЕРОЙ" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Вы съели Легендарного Героя.[w:10]\nВаша АТАКА увеличилась на 4![w:10]\n"..MessageHeal(40),"Папирус так же нашёл немного\rеды.[w:10]\nВы оба неплохо перекусили."})
				else
					BattleDialog({"[effect:none]Вы съели Легендарного Героя.[w:10]\nВаша АТАКА увеличилась на 4![w:10]\n"..MessageHeal(40)})
					if Alternative == 1 then
						enemies[4]["def"] = enemies[4]["def"] - 40
					end
				end
				Player.Heal(40)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Вы съели[func:SpawnText,Легендарного Героя]"})
			end
			for i=1,#Items do
				if Items[i] == "Л. Герой" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "C. SPAGHETTI" then
			if phase == 1 then
				local randomizador = math.random(40, 70)
				if progress <= 5 and Alternative ~= 1 then
					SetHead("Blocking")
					BattleDialog({"[effect:none]You ate the Cold Spaghetti.[w:10]\nPapyrus looks at you sadly.[w:10]\n"..MessageHeal(randomizador),"Even though the spaghetti is\rcold it tastes very good."})
					enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none][color:FF0000]BONE[color:000000] APPETIT[w:10]\nNYHEHEHE..."})
				else
					if Alternative ~= 1 then
						if progress == 6 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 and not Ask then
							SetHead("Disappointed")
							enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]DID YOU LIKE IT?"})
							Ask = 0
						elseif progress > 6 then
							SetHead("Blocking")
						end
					end
					BattleDialog({"[effect:none]You ate the Cold Spaghetti.[w:10]\n"..MessageHeal(randomizador),"Even though the spaghetti is\rcold it tastes very good."})
				end
				Player.Heal(randomizador)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Cold Spaghetti]"})
			end
			for i=1,#Items do
				if Items[i] == "C. Spaghetti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "ESPAGUETI F." then
			if phase == 1 then
				local randomizador = math.random(40, 70)
				if progress <= 5 and Alternative ~= 1 then
					SetHead("Blocking")
					BattleDialog({"[effect:none]Te comiste el Espagueti Frío.[w:10]\nPapyrus te mira tristemente.[w:10]\n"..MessageHeal(randomizador),"Aunque el espagueti esta\rfrío sabe muy bien."})
					enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none][color:FF0000]BONE[color:000000] APETITO[w:10]\nNYHEHEHE..."})
				else
					if Alternative ~= 1 then
						if progress == 6 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 and not Ask then
							SetHead("Disappointed")
							enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]TE GUSTÓ?"})
							Ask = 0
						elseif progress > 6 then
							SetHead("Blocking")
						end
					end
					BattleDialog({"[effect:none]Te comiste el Espagueti Frío.[w:10]\n"..MessageHeal(randomizador),"Aunque el espagueti esta\rfrío sabe muy bien."})
				end
				Player.Heal(randomizador)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Espagueti Frío]"})
			end
			for i=1,#Items do
				if Items[i] == "Espagueti F." then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "Х. СПАГЕТТИ" then
			if phase == 1 then
				local randomizador = math.random(40, 70)
				if progress <= 5 and Alternative ~= 1 then
					SetHead("Blocking")
					BattleDialog({"[effect:none]Вы съели Холодные Спагетти.[w:10]\nПапирус печально взглянул на вас.[w:10]\n"..MessageHeal(randomizador),"Несмотря на то[w:5], что спагетти\rхолодные[w:5], они очень вкусные."})
					enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none][color:FF0000]ПРЕХРЯЩНОГО[color:000000] АППЕТИТА[w:10]\nНЬЕ-ХЕ-ХЕ..."})
				else
					if Alternative ~= 1 then
						if progress == 6 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 and not Ask then
							SetHead("Disappointed")
							enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]ТЕБЕ ПОНРАВИЛОСЬ?"})
							Ask = 0
						elseif progress > 6 then
							SetHead("Blocking")
						end
					end
					BattleDialog({"[effect:none]Вы съели Холодные Спагетти.[w:10]\n"..MessageHeal(randomizador),"Несмотря на то,[w:10] что спагетти\rхолодные, они очень вкусные."})
				end
				Player.Heal(randomizador)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Вы съели[func:SpawnText,Холодные Спагетти]"})
			end
			for i=1,#Items do
				if Items[i] == "Х. Спагетти" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "SPAGHETTI" then
			if phase == 2 then
				BattleDialog({"[noskip][effect:none](You take a big bite.)","[noskip][effect:none](Your face reflexively scrunches\rup.)","[noskip][effect:none](It's even worse than last\rtime...)","[func:Recover,"..math.random(15, 45).."]"})
			elseif phase == 3 then
				local randomizador = math.random(30, 75)
				BattleDialog({"You ate the Spaghetti.[w:10]\n"..MessageHeal(randomizador)})
				StatusPhase3[progress + 1] = "Item"
				Player.Heal(randomizador)
			elseif phase == 4 then
				local randomizador = math.random(30, 75)
				BattleDialog({"You ate the Spaghetti.[w:10]\n"..MessageHeal(randomizador)})
				if not SelectedFlee2 and not Scared then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][waitall:5]. . ."})
				elseif not Itemed then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]I CAN MAKE YOU\nMORE IF YOU\n[color:f2c900]SPARE[color:000000] ME...","[noskip][font:papyrus][voice:papyrus][effect:none]PLEASE...[w:10]\nI'M STILL YOUR\nFRIEND..."})
					Itemed = true
				end
				Player.Heal(randomizador)
				moved = true
			end
			for i=1,#Items do
				if Items[i] == "Spaghetti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "ESPAGUETI" then
			if phase == 2 then
				BattleDialog({"[noskip][effect:none](Das un gran mordisco.)","[noskip][effect:none](Tu cara reflexivamente se\rarrugó.)","[noskip][effect:none](Es incluso peor que la última\rvez...)","[func:Recover,"..math.random(15, 45).."]"})
			elseif phase == 3 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Te comiste el Espagueti.[w:10]\n"..MessageHeal(randomizador)})
				StatusPhase3[progress + 1] = "Item"
				Player.Heal(randomizador)
			elseif phase == 4 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Te comiste el Espagueti.[w:10]\n"..MessageHeal(randomizador)})
				if not SelectedFlee2 and not Scared then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][waitall:5]. . ."})
				elseif not Itemed then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]PUEDO HACERTE\nMÁS SI ME\n[color:f2c900]PERDONAS[color:000000]...","[noskip][font:papyrus][voice:papyrus][effect:none]POR FAVOR...[w:10]\nSIGO SIENDO TU\nAMIGO..."})
					Itemed = true
				end
				Player.Heal(randomizador)
				moved = true
			end
			for i=1,#Items do
				if Items[i] == "Espagueti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "СПАГЕТТИ" then
			if phase == 2 then
				BattleDialog({"[noskip][effect:none](Вы откусили большой кусок.)","[noskip][effect:none](Ваше лицо рефлексивно\rсморщилось.)","[noskip][effect:none](Гораздо хуже[w:10], чем в прошлый\rраз...)","[func:Recover,"..math.random(15, 45).."]"})
			elseif phase == 3 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Вы съели Спагетти.[w:10]\n"..MessageHeal(randomizador)})
				StatusPhase3[progress + 1] = "Item"
				Player.Heal(randomizador)
			elseif phase == 4 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Вы съели Спагетти.[w:10]\n"..MessageHeal(randomizador)})
				if not SelectedFlee2 and not Scared then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][waitall:5]. . ."})
				elseif not Itemed then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]Я МОГУ СДЕЛАТЬ\nТЕБЕ ЕЩЁ[w:5], ЕСЛИ\nТЫ [color:f2c900]ПОЩАДИШЬ[color:000000]\nМЕНЯ...","[noskip][font:papyrus][voice:papyrus][effect:none]ПОЖАЛУЙСТА...[w:10]\nЯ ВСЁ ЕЩЁ\nТВОЙ ДРУГ..."})
					Itemed = true
				end
				Player.Heal(randomizador)
				moved = true
			end
			for i=1,#Items do
				if Items[i] == "Спагетти" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		end
		if #Items <= 0 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Items = {"[starcolor:7d7d7d][color:7d7d7d]Nada[color:ffffff]"}
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				Items = {"[starcolor:7d7d7d][color:7d7d7d]Ничего[color:ffffff]"}
			else
				Items = {"[starcolor:7d7d7d][color:7d7d7d]Nothing[color:ffffff]"}
			end
		end
	end
end

function Recover(amount)
	Player.Heal(amount)
	progress = progress + 1
	EnemyDialogueEnding()
	State("DEFENDING")
end

function MessageHeal(cant)
	if (Player.hp + cant >= Player.lv*4 + 16 and (phase < 3 or (phase == 3 and progress <= 0))) or (Player.hp + cant >= 184 and ((phase >= 3 and progress > 0) or phase >= 4)) then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			return "Tu PV estan al maximo!"
		elseif GetAlMightyGlobal("Idioma") == "Russian" then	
		    return "Ваше ОЗ были восстановлены!"			
		else
			return "Your HP was maxed out!"
		end
	else
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			return "Recuperaste "..cant.." PV!"
		elseif GetAlMightyGlobal("Idioma") == "Russian" then	
		    return "Вы восстановили "..cant.." ОЗ!"
		else
			return "You recovered "..cant.." HP!"
		end
	end
end

function MISS()
	Miss = CreateSprite("Specials/MISS "..GetAlMightyGlobal("Idioma"),"Top")
	Miss.MoveTo(320, 420)
	timerMiss = 0
end

function ContinueMusic()
	if phase == 1 then
		if GameMusic == "Playing" then
			GameMusic = "Volume"
		elseif GameMusic == "Volume" then
			GameMusic = "Cry"
		elseif GameMusic == "Crying" then
			GameMusic = "Believe"
		elseif GameMusic == "Wait" then
			GameMusic = "Stop"
		end
	elseif phase == 2 then
		if GameMusic == "End" then
			GameMusic = "Start"
		elseif GameMusic == "Wait 1" then
			GameMusic = "Continue 1"
		elseif GameMusic == "Wait 2" then
			GameMusic = "Continue 2"
		elseif GameMusic == "Wait 3" and NewAudio.GetPlayTime("Loop") > 6.64 then
			GameMusic = "Continue 3"
		elseif GameMusic == "Wait 4" then
			GameMusic = "Continue 4"
		elseif GameMusic == "Wait 5" then
			GameMusic = "Fade"
		end
	elseif phase == 3 then
		if GameMusic == "End" then
			GameMusic = "Prepare"
		elseif GameMusic == "Wait 1" then
			GameMusic = "Continue 1"
		elseif GameMusic == "Wait 2" then
			GameMusic = "Continue 2"
		elseif GameMusic == "Wait 3" then
			GameMusic = "Continue 3"
		elseif GameMusic == "Wait 4" then
			GameMusic = "Continue 4"
		elseif GameMusic == "Wait 5" then
			GameMusic = "Continue 5"
		end
	end
end

function Trigger()
	Triggered = true
end