Scriptname SuH_spellES_teliWorld extends activemagiceffect  

ObjectReference Property SuH_sdr_returnpoint Auto 
ObjectReference Property SuH_sd_spawn1 Auto 
ObjectReference Property SuH_sd_spawn2 Auto 
ObjectReference Property SuH_sd_spawn3 Auto 
ObjectReference Property SuH_sd_spawn4 Auto 
ObjectReference Property SuH_sd_spawn5 Auto 
ObjectReference Property SuH_sd_spawn6 Auto 
ObjectReference Property SuH_sd_spawn7 Auto 
ObjectReference Property SuH_sd_spawn8 Auto 
Actor property PlayerRef auto
Cell property SuH_realm auto
GlobalVariable property SuH_CHKdied auto
GlobalVariable property SuH_SETrandomdeathspawn auto

Event OnEffectStart(actor akTarget, actor akCaster)
	if PlayerRef.GetParentCell() == SuH_realm
		if SuH_CHKdied.GetValue() && SuH_SETrandomdeathspawn.GetValue()
			while PlayerRef.GetParentCell() == SuH_realm
			int rand = Utility.RandomInt(1, 8)
			if rand == 1
				PlayerRef.MoveTo(SuH_sd_spawn1)
			elseif rand == 2
				PlayerRef.MoveTo(SuH_sd_spawn2)
			elseif rand == 3
				PlayerRef.MoveTo(SuH_sd_spawn3)
			elseif rand == 4
				PlayerRef.MoveTo(SuH_sd_spawn4)
			elseif rand == 5
				PlayerRef.MoveTo(SuH_sd_spawn5)
			elseif rand == 6
				PlayerRef.MoveTo(SuH_sd_spawn6)
			elseif rand == 7
				PlayerRef.MoveTo(SuH_sd_spawn7)
			elseif rand == 8
				PlayerRef.MoveTo(SuH_sd_spawn8)
			else
				PlayerRef.MoveTo(SuH_sd_spawn1)
			endIf
			endWhile
		else
			PlayerRef.MoveTo(SuH_sdr_returnpoint)
		endIf
	else
		Debug.Notification("You must be in the main room to Disconnect!")
	endIf
endEvent