Scriptname SuH_spellES_teliRealm extends activemagiceffect  

ObjectReference Property SuH_sevaspawn Auto ;Overwrites portal point
ObjectReference Property SuH_sdr_portalpoint Auto 
ObjectReference Property SuH_sdr_returnpoint Auto 
ObjectReference Property SuH_sd_lostchest Auto 
ObjectReference Property SuH_sd_goldchest Auto 
MiscObject property Gold001 auto
Actor property PlayerRef auto
Actor property SuH_actor_tali auto
Cell property SuH_realm auto
WorldSpace property SuH_worldspace auto
GlobalVariable property SuH_CHKdied auto
ObjectReference Property SuH_sd_returnpointcell 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
GlobalVariable property SuH_SETrandomdeathspawn auto
Message property SuH_menu_teliworld auto

Event OnEffectStart(actor akTarget, actor akCaster)
	;if PlayerRef.GetParentCell() == SuH_realm
	if PlayerRef.GetWorldSpace() == SuH_worldspace
		if SuH_CHKdied.GetValue() && SuH_SETrandomdeathspawn.GetValue()
			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
		else
			Int i = SuH_menu_teliWorld.Show()
			if i == 0
				PlayerRef.MoveTo(SuH_sdr_returnpoint)
			elseif i == 1
				PlayerRef.MoveTo(SuH_sd_returnpointcell)
			elseif i == 2
				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
			endIf		
		endIf
	else
		SuH_sd_lostchest.RemoveItem(Gold001, 999999)
		;SuH_sd_lostchest.RemoveAllItems(SuH_sd_goldchest)
		;SuH_actor_tali.RemoveItem(Gold001, -1)
		SuH_sdr_returnpoint.MoveTo(PlayerRef)
		PlayerRef.MoveTo(SuH_sevaspawn)
		SuH_CHKdied.SetValue(0)
	endIf
endEvent