Scriptname aaaKimachuuRespawnMain Extends ReferenceAlias

Actor Property PlayerRef Auto
ObjectReference Property SMRef Auto
Quest Property aQuest Auto
Quest Property MQ101 Auto
Spell Property aSpell Auto

Event OnInit()
	PlayerRef.AddSpell(aSpell)
EndEvent

Event OnEnterBleedout()
	if MQ101.IsRunning()
		if MQ101.GetStage() < 800
			Utility.Wait(2.5)
			PlayerRef.RestoreActorValue("Health", 9999)
		EndIf
	Else
		ResuPlayer()
		PenaltySend()
	EndIf
endEvent

Function ResuPlayer()
	PlayerRef.SetGhost()
	PlayerRef.RestoreActorValue("Health", 9999)
	Utility.Wait(0.1)
	PlayerRef.Moveto(SMRef, 0.000000, 0.000000, 30.000000, true)
	PlayerRef.StopCombat()
	PlayerRef.StopCombatAlarm()
	Game.FadeOutGame(false, true, 2.0, 1.0)
	Utility.Wait(3.5)
	PlayerRef.PushActorAway(PlayerRef, 1.0)
	PlayerRef.RestoreActorValue("Health", 9999)
	Utility.Wait(1.0)
	PlayerRef.EquipSpell(aSpell, 2)
	PlayerRef.SetGhost(false)
EndFunction

Function PenaltySend()
	SendModEvent("PenaltyEvent")
EndFunction
