Jump to content

Soulgem spells collection


Stealth21

Recommended Posts

I decided to present here a collection of the soulgem spell scripts. I wrote them for myself and tested out (except the grand souls voider cause that is irrationally). Everyone can include them in your mods if you like. Edit them in any way you imagine. Requires OBSE.

 

Every spell has the next flags checked:

Disallow Spell Absorb/reflect

Script Effect Always Applies

Immune to Silence

 

Every spell has script effect only, and in any of them:

Range - Self

Duration - 1

School - Mysticism

Visual Effect - SoulTrap

 

Processing the stolen soulgems is thought out, so voiding/filling them do not "transform" them to the non-stolen.

Vanilla soulgems only, excluding Azura's Star and tomato.

 

Objectally filled soulgems have a different cost comparing to their empty analogs, so there is a compensation to give or to take according to the difference. In some 3/4 corellation from the minused difference.

 

SpellID: StandardEmptySoulGem1PettySoul

SpellName: Gap

SpellLevel: Novice

SpellCost: 3

ScriptEffectName: Petty soul voiding

scn zzSMEmptySoulGemPettySoul

Short button
Short combo
ref iter
Short PettyPettyTotal
Short LesserPettyTotal
Short CommonPettyTotal
Short GreaterPettyTotal
Short GrandPettyTotal
Short PettyPetty
Short LesserPetty
Short CommonPetty
Short GreaterPetty
Short GrandPetty
Short PettyPettyStolen
Short LesserPettyStolen
Short CommonPettyStolen
Short GreaterPettyStolen
Short GrandPettyStolen
Short VanPettyPetty
Short VanLesserPetty
Short VanCommonPetty
Short VanGreaterPetty
Short VanGrandPetty
Short VanPettyPettyStolen
Short VanLesserPettyStolen
Short VanCommonPettyStolen
Short VanGreaterPettyStolen
Short VanGrandPettyStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let PettyPetty := PettyPetty + iter.GetRefCount
		else
			let PettyPettyStolen := PettyPettyStolen + iter.GetRefCount
		endif
		let PettyPettyTotal := PettyPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let LesserPetty := LesserPetty + iter.GetRefCount
		else
			let LesserPettyStolen := LesserPettyStolen + iter.GetRefCount
		endif
		let LesserPettyTotal := LesserPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let CommonPetty := CommonPetty + iter.GetRefCount
		else
			let CommonPettyStolen := CommonPettyStolen + iter.GetRefCount
		endif
		let CommonPettyTotal := CommonPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let GreaterPetty := GreaterPetty + iter.GetRefCount
		else
			let GreaterPettyStolen := GreaterPettyStolen + iter.GetRefCount
		endif
		let GreaterPettyTotal := GreaterPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let GrandPetty := GrandPetty + iter.GetRefCount
		else
			let GrandPettyStolen := GrandPettyStolen + iter.GetRefCount
		endif
		let GrandPettyTotal := GrandPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem1Petty1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanPettyPetty := VanPettyPetty + iter.GetRefCount
		else
			let VanPettyPettyStolen := VanPettyPettyStolen + iter.GetRefCount
		endif
		let PettyPettyTotal := PettyPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanLesserPetty := VanLesserPetty + iter.GetRefCount
		else
			let VanLesserPettyStolen := VanLesserPettyStolen + iter.GetRefCount
		endif
		let LesserPettyTotal := LesserPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanCommonPetty := VanCommonPetty + iter.GetRefCount
		else
			let VanCommonPettyStolen := VanCommonPettyStolen + iter.GetRefCount
		endif
		let CommonPettyTotal := CommonPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterPetty := VanGreaterPetty + iter.GetRefCount
		else
			let VanGreaterPettyStolen := VanGreaterPettyStolen + iter.GetRefCount
		endif
		let GreaterPettyTotal := GreaterPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanGrandPetty := VanGrandPetty + iter.GetRefCount
		else
			let VanGrandPettyStolen := VanGrandPettyStolen + iter.GetRefCount
		endif
		let GrandPettyTotal := GrandPettyTotal + iter.GetRefCount
	endif
loop

if ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ABCDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Greater", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; ABCD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Greater"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ABCE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ABDE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Greater", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ACDE
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Greater", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BCDE
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) ; ABC
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; ABD
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Greater"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ABE
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; ACD
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Greater"
elseif ( PettyPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ACE
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; ADE
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Greater", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; BCD
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Greater"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BCE
	set combo to 10
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BDE
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Greater", "Grand"
elseif ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; CDE
	set combo to 13
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( PettyPettyTotal > 0 ) && ( LesserPettyTotal > 0 ) ; AB
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser"
elseif ( PettyPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) ; AC
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common"
elseif ( PettyPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; AD
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Greater"
elseif ( PettyPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; AE
	set combo to 8
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) ; BC
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common"
elseif ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; BD
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Greater"
elseif ( LesserPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BE
	set combo to 12
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Grand"
elseif ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; CD
	set combo to 13
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Greater"
elseif ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; CE
	set combo to 14
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Grand"
elseif ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; DE
	set combo to 15
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Greater", "Grand"
elseif ( PettyPettyTotal > 0 ) ; A
	set combo to 1
	MessageBox "Void the petty soulgem from the petty soul?", "Cancel", "Yes"
elseif ( LesserPettyTotal > 0 ) ; B
	set combo to 9
	MessageBox "Void the lesser soulgem from the petty soul?", "Cancel", "Yes"
elseif ( CommonPettyTotal > 0 ) ; C
	set combo to 13
	MessageBox "Void the common soulgem from the petty soul?", "Cancel", "Yes"
elseif ( GreaterPettyTotal > 0 ) ; D
	set combo to 15
	MessageBox "Void the greater soulgem from the petty soul?", "Cancel", "Yes"
elseif ( GrandPettyTotal > 0 ) ; E
	set combo to 16
	MessageBox "Void the grand soulgem from the petty soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a petty soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem1PettySoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 8 ) ; AXXXX, AXXX, AXX, AX, A
			set stage to 2
		elseif ( combo >= 9 ) && ( combo <= 12 ) ; BXXX, BXX, BX, B
			set stage to 3
		elseif ( combo == 13 ) || ( combo == 14 ) ; CXX, CX, C
			set stage to 4
		elseif ( combo == 15 ) ; DX, D
			set stage to 5
		elseif ( combo == 16 ) ; E
			set stage to 6
		endif
	elseif ( button == 2 )
		if ( combo >= 1 ) && ( combo <= 3 ) || ( combo == 5 ) ; XBXX, XBX, XB
			set stage to 3
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 9 ) || ( combo == 10 ) ; XCXX, XCX, XC
			set stage to 4
		elseif ( combo == 7 ) || ( combo == 11 ) || ( combo == 13 ); XDX, XD
			set stage to 5
		elseif ( combo == 8 ) || ( combo == 12 ) || ( combo == 14 ) || ( combo == 15 ) ; XE
			set stage to 6
		endif
	elseif ( button == 3 )
		if ( combo == 1 ) || ( combo == 2 ) ; XXCX, XXC
			set stage to 4
		elseif ( combo == 3 ) || ( combo == 4 ) || ( combo == 9 ); XXDX, XXD
			set stage to 5
		elseif ( combo >= 5 ) && ( combo <= 7 ) || ( combo == 10 ) || ( combo == 11 ) || ( combo == 13 ) ; XXE
			set stage to 6
		endif
	elseif ( button == 4 )
		if ( combo == 1 ) ; XXXD
			set stage to 5
		elseif ( combo >= 2 ) && ( combo <= 4 ) || ( combo == 10 ) || ( combo == 9 ) ; XXXE
			set stage to 6
		endif
	elseif ( button == 5 )
		;( combo == 1 ) XXXXE single case
		set stage to 6
	endif
elseif ( stage == 2 )
	if ( VanPettyPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem1Petty1PettySoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanPettyPetty > 1 )
			set VanPettyPetty to ( VanPettyPetty - 1 )
			let iter := CreateTempRef SoulGem1Petty1PettySoul
			iter.SetRefCount VanPettyPetty
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty1Petty 1
		Player.AddItemNS Gold001 22
	elseif ( VanPettyPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem1Petty1PettySoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanPettyPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanPettyPettyStolen > 1 )
			set VanPettyPettyStolen to ( VanPettyPettyStolen - 1 )
			let iter := CreateTempRef SoulGem1Petty1PettySoul
			iter.SetRefCount VanPettyPettyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 22
	elseif ( PettyPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( PettyPetty > 1 )
			set PettyPetty to ( PettyPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty1Petty
			iter.SetRefCount PettyPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
;		Player.AddItemNS SoulGemEmpty1Petty 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let PettyPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( PettyPettyStolen > 1 )
			set PettyPettyStolen to ( PettyPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty1Petty
			iter.SetRefCount PettyPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
		Message "A petty soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
		set stage to 0
elseif ( stage == 3 )
	if ( VanLesserPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserPetty > 1 )
			set VanLesserPetty to ( VanLesserPetty - 1 )
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
			iter.SetRefCount VanLesserPetty
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
		Player.AddItemNS Gold001 11
	elseif ( VanLesserPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanLesserPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserPettyStolen > 1 )
			set VanLesserPettyStolen to ( VanLesserPettyStolen - 1 )
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
			iter.SetRefCount VanLesserPettyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 11
	elseif ( LesserPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserPetty > 1 )
			set LesserPetty to ( LesserPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let LesserPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserPettyStolen > 1 )
			set LesserPettyStolen to ( LesserPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A lesser soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 0
elseif ( stage == 4 )
	if (( VanCommonPetty > 0 ) || ( VanCommonPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 8 )
		if ( VanCommonPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem3Common1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanCommonPetty > 1 )
				set VanCommonPetty to ( VanCommonPetty - 1 )
				let iter := CreateTempRef SoulGem3Common1PettySoul
				iter.SetRefCount VanCommonPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty3Common 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem3Common1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanCommonPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanCommonPettyStolen > 1 )
				set VanCommonPettyStolen to ( VanCommonPettyStolen - 1 )
				let iter := CreateTempRef SoulGem3Common1PettySoul
				iter.SetRefCount VanCommonPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 8
		Message "A common soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( CommonPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonPetty > 1 )
			set CommonPetty to ( CommonPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty3Common 1
		Message "A common soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( CommonPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonPettyStolen > 1 )
			set CommonPettyStolen to ( CommonPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A common soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 8 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
elseif ( stage == 5 )
	if (( VanGreaterPetty > 0 ) || ( VanGreaterPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 45 )
		if ( VanGreaterPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterPetty > 1 )
				set VanGreaterPetty to ( VanGreaterPetty - 1 )
				let iter := CreateTempRef SoulGem4Greater1PettySoul
				iter.SetRefCount VanGreaterPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty4Greater 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGreaterPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterPettyStolen > 1 )
				set VanGreaterPettyStolen to ( VanGreaterPettyStolen - 1 )
				let iter := CreateTempRef SoulGem4Greater1PettySoul
				iter.SetRefCount VanGreaterPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 45
		Message "A greater soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( GreaterPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterPetty > 1 )
			set GreaterPetty to ( GreaterPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Message "A greater soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( GreaterPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterPettyStolen > 1 )
			set GreaterPettyStolen to ( GreaterPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A greater soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 45 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
elseif ( stage == 6 )
	if (( VanGrandPetty > 0 ) || ( VanGrandPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 120 )
		if ( VanGrandPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandPetty > 1 )
				set VanGrandPetty to ( VanGrandPetty - 1 )
				let iter := CreateTempRef SoulGem5Grand1PettySoul
				iter.SetRefCount VanGrandPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandPettyStolen > 1 )
				set VanGrandPettyStolen to ( VanGrandPettyStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand1PettySoul
				iter.SetRefCount VanGrandPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 120
		Message "A grand soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( GrandPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandPetty > 1 )
			set GrandPetty to ( GrandPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A grand soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	elseif ( GrandPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandPettyStolen > 1 )
			set GrandPettyStolen to ( GrandPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A grand soulgem has been voided from the petty soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 120 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanPettyPetty to 0
set VanLesserPetty to 0
set VanCommonPetty to 0
set VanGreaterPetty to 0
set VanGrandPetty to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem1Petty1PettySoul )
		let VanPettyPetty := VanPettyPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
			let VanLesserPetty := VanLesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
			let VanCommonPetty := VanCommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
			let VanGreaterPetty := VanGreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
			let VanGrandPetty := VanGrandPetty + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem1Petty1PettySoul ) == 1 ) && ( VanPettyPetty == 0 )
	Player.RemoveItemNS SoulGem1Petty1PettySoul 1
endif
if (( Player.GetItemCount SoulGem2Lesser1PettySoul ) == 1 ) && ( VanLesserPetty == 0 )
	Player.RemoveItemNS SoulGem2Lesser1PettySoul 1
endif
if (( Player.GetItemCount SoulGem3Common1PettySoul ) == 1 ) && ( VanCommonPetty == 0 )
	Player.RemoveItemNS SoulGem3Common1PettySoul 1
endif
if (( Player.GetItemCount SoulGem4Greater1PettySoul ) == 1 ) && ( VanGreaterPetty == 0 )
	Player.RemoveItemNS SoulGem4Greater1PettySoul 1
endif
if (( Player.GetItemCount SoulGem5Grand1PettySoul ) == 1 ) && ( VanGrandPetty == 0 )
	Player.RemoveItemNS SoulGem5Grand1PettySoul 1
endif
let iter := 0
End

 

 

 

SpellID: StandardEmptySoulGem2LesserSoul

SpellName: Outlet

SpellLevel: Novice

SpellCost: 3

ScriptEffectName: Lesser soul voiding

scn zzSMEmptySoulGemLesserSoul

Short button
Short combo
ref iter
Short LesserLesserTotal
Short CommonLesserTotal
Short GreaterLesserTotal
Short GrandLesserTotal
Short LesserLesser
Short CommonLesser
Short GreaterLesser
Short GrandLesser
Short LesserLesserStolen
Short CommonLesserStolen
Short GreaterLesserStolen
Short GrandLesserStolen
Short VanLesserLesser
Short VanCommonLesser
Short VanGreaterLesser
Short VanGrandLesser
Short VanLesserLesserStolen
Short VanCommonLesserStolen
Short VanGreaterLesserStolen
Short VanGrandLesserStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let LesserLesser := LesserLesser + iter.GetRefCount
		else
			let LesserLesserStolen := LesserLesserStolen + iter.GetRefCount
		endif
		let LesserLesserTotal := LesserLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let CommonLesser := CommonLesser + iter.GetRefCount
		else
			let CommonLesserStolen := CommonLesserStolen + iter.GetRefCount
		endif
		let CommonLesserTotal := CommonLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let GreaterLesser := GreaterLesser + iter.GetRefCount
		else
			let GreaterLesserStolen := GreaterLesserStolen + iter.GetRefCount
		endif
		let GreaterLesserTotal := GreaterLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let GrandLesser := GrandLesser + iter.GetRefCount
		else
			let GrandLesserStolen := GrandLesserStolen + iter.GetRefCount
		endif
		let GrandLesserTotal := GrandLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanLesserLesser := VanLesserLesser + iter.GetRefCount
		else
			let VanLesserLesserStolen := VanLesserLesserStolen + iter.GetRefCount
		endif
		let LesserLesserTotal := LesserLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanCommonLesser := VanCommonLesser + iter.GetRefCount
		else
			let VanCommonLesserStolen := VanCommonLesserStolen + iter.GetRefCount
		endif
		let CommonLesserTotal := CommonLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterLesser := VanGreaterLesser + iter.GetRefCount
		else
			let VanGreaterLesserStolen := VanGreaterLesserStolen + iter.GetRefCount
		endif
		let GreaterLesserTotal := GreaterLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandLesser := VanGrandLesser + iter.GetRefCount
		else
			let VanGrandLesserStolen := VanGrandLesserStolen + iter.GetRefCount
		endif
		let GrandLesserTotal := GrandLesserTotal + iter.GetRefCount
	endif
loop

if ( LesserLesserTotal > 0 ) && ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; BCDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( LesserLesserTotal > 0 ) && ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) ; BCD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Greater"
elseif ( LesserLesserTotal > 0 ) && ( CommonLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; BCE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Grand"
elseif ( LesserLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; BDE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Greater", "Grand"
elseif ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; CDE
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( LesserLesserTotal > 0 ) && ( CommonLesserTotal > 0 ) ; BC
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common"
elseif ( LesserLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) ; BD
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Greater"
elseif ( LesserLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; BE
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Grand"
elseif ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) ; CD
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Greater"
elseif ( CommonLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; CE
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Grand"
elseif ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; DE
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Greater", "Grand"
elseif ( LesserLesserTotal > 0 ) ; B
	set combo to 1
	MessageBox "Void the lesser soulgem from the lesser soul?", "Cancel", "Yes"
elseif ( CommonLesserTotal > 0 ) ; C
	set combo to 5
	MessageBox "Void the common soulgem from the lesser soul?", "Cancel", "Yes"
elseif ( GreaterLesserTotal > 0 ) ; D
	set combo to 7
	MessageBox "Void the greater soulgem from the lesser soul?", "Cancel", "Yes"
elseif ( GrandLesserTotal > 0 ) ; E
	set combo to 8
	MessageBox "Void the grand soulgem from the lesser soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a lesser soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem2LesserSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 4 ) ; BXXX, BXX, BX, B
			set stage to 2
		elseif ( combo == 5 ) || ( combo == 6 ) ; CXX, CX, C
			set stage to 3
		elseif ( combo == 7 ) ; DX, D
			set stage to 4
		elseif ( combo == 8 ) ; E
			set stage to 5
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) || ( combo == 2 ) ; XCXX, XCX, XC
			set stage to 3
		elseif ( combo == 3 ) || ( combo == 5 ) ; XDX, XD
			set stage to 4
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 7 ) ; XE
			set stage to 5
		endif
	elseif ( button == 3 )
		if ( combo == 1 ); XXDX, XXD
			set stage to 4
		elseif ( combo == 2 ) || ( combo == 3 ) || ( combo == 5 ) ; XXE
			set stage to 5
		endif
	elseif ( button == 4 )
		;( combo == 1 ) XXXE single case
		set stage to 5
	endif
elseif ( stage == 2 )
	if ( VanLesserLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserLesser > 1 )
			set VanLesserLesser to ( VanLesserLesser - 1 )
			let iter := CreateTempRef SoulGem2Lesser2LesserSoul
			iter.SetRefCount VanLesserLesser
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
		Player.AddItemNS Gold001 41
	elseif ( VanLesserLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanLesserLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserLesserStolen > 1 )
			set VanLesserLesserStolen to ( VanLesserLesserStolen - 1 )
			let iter := CreateTempRef SoulGem2Lesser2LesserSoul
			iter.SetRefCount VanLesserLesserStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 41
	elseif ( LesserLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserLesser > 1 )
			set LesserLesser to ( LesserLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let LesserLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserLesserStolen > 1 )
			set LesserLesserStolen to ( LesserLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
		Message "A lesser soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
		set stage to 0
elseif ( stage == 3 )
	if ( VanCommonLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonLesser > 1 )
			set VanCommonLesser to ( VanCommonLesser - 1 )
			let iter := CreateTempRef SoulGem3Common2LesserSoul
			iter.SetRefCount VanCommonLesser
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty3Common 1
		Player.AddItemNS Gold001 22
	elseif ( VanCommonLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common2LesserSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanCommonLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonLesserStolen > 1 )
			set VanCommonLesserStolen to ( VanCommonLesserStolen - 1 )
			let iter := CreateTempRef SoulGem3Common2LesserSoul
			iter.SetRefCount VanCommonLesserStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 22
	elseif ( CommonLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonLesser > 1 )
			set CommonLesser to ( CommonLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty3Common 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonLesserStolen > 1 )
			set CommonLesserStolen to ( CommonLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
		Message "A common soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
		set stage to 0
elseif ( stage == 4 )
	if (( VanGreaterLesser > 0 ) || ( VanGreaterLesserStolen > 0 )) && ( Player.GetItemCount Gold001 >= 15 )
		if ( VanGreaterLesser > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterLesser > 1 )
				set VanGreaterLesser to ( VanGreaterLesser - 1 )
				let iter := CreateTempRef SoulGem4Greater2LesserSoul
				iter.SetRefCount VanGreaterLesser
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty4Greater 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater2LesserSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGreaterLesserStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterLesserStolen > 1 )
				set VanGreaterLesserStolen to ( VanGreaterLesserStolen - 1 )
				let iter := CreateTempRef SoulGem4Greater2LesserSoul
				iter.SetRefCount VanGreaterLesserStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 15
		Message "A greater soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	elseif ( GreaterLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterLesser > 1 )
			set GreaterLesser to ( GreaterLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Message "A greater soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	elseif ( GreaterLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterLesserStolen > 1 )
			set GreaterLesserStolen to ( GreaterLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A greater soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 15 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
elseif ( stage == 5 )
	if (( VanGrandLesser > 0 ) || ( VanGrandLesserStolen > 0 )) && ( Player.GetItemCount Gold001 >= 90 )
		if ( VanGrandLesser > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandLesser > 1 )
				set VanGrandLesser to ( VanGrandLesser - 1 )
				let iter := CreateTempRef SoulGem5Grand2LesserSoul
				iter.SetRefCount VanGrandLesser
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand2LesserSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandLesserStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandLesserStolen > 1 )
				set VanGrandLesserStolen to ( VanGrandLesserStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand2LesserSoul
				iter.SetRefCount VanGrandLesserStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 90
		Message "A grand soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	elseif ( GrandLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandLesser > 1 )
			set GrandLesser to ( GrandLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A grand soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	elseif ( GrandLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandLesserStolen > 1 )
			set GrandLesserStolen to ( GrandLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A grand soulgem has been voided from the lesser soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 90 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanLesserLesser to 0
set VanCommonLesser to 0
set VanGreaterLesser to 0
set VanGrandLesser to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul )
			let VanLesserLesser := VanLesserLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
			let VanCommonLesser := VanCommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
			let VanGreaterLesser := VanGreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
			let VanGrandLesser := VanGrandLesser + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem2Lesser2LesserSoul ) == 1 ) && ( VanLesserLesser == 0 )
	Player.RemoveItemNS SoulGem2Lesser2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem3Common2LesserSoul ) == 1 ) && ( VanCommonLesser == 0 )
	Player.RemoveItemNS SoulGem3Common2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater2LesserSoul ) == 1 ) && ( VanGreaterLesser == 0 )
	Player.RemoveItemNS SoulGem4Greater2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand2LesserSoul ) == 1 ) && ( VanGrandLesser == 0 )
	Player.RemoveItemNS SoulGem5Grand2LesserSoul 1
endif
let iter := 0
End

 

 

 

SpellID: StandardEmptySoulGem3CommonSoul

SpellName: Drainage

SpellLevel: Novice

SpellCost: 3

ScriptEffectName: Common soul voiding

scn zzSMEmptySoulGemCommonSoul

Short button
Short combo
ref iter
Short CommonCommonTotal
Short GreaterCommonTotal
Short GrandCommonTotal
Short CommonCommon
Short GreaterCommon
Short GrandCommon
Short CommonCommonStolen
Short GreaterCommonStolen
Short GrandCommonStolen
Short VanCommonCommon
Short VanGreaterCommon
Short VanGrandCommon
Short VanCommonCommonStolen
Short VanGreaterCommonStolen
Short VanGrandCommonStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 3 )
		if ( iter.GetOwner == 0 )
			let CommonCommon := CommonCommon + iter.GetRefCount
		else
			let CommonCommonStolen := CommonCommonStolen + iter.GetRefCount
		endif
		let CommonCommonTotal := CommonCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
		if ( iter.GetOwner == 0 )
			let GreaterCommon := GreaterCommon + iter.GetRefCount
		else
			let GreaterCommonStolen := GreaterCommonStolen + iter.GetRefCount
		endif
		let GreaterCommonTotal := GreaterCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
		if ( iter.GetOwner == 0 )
			let GrandCommon := GrandCommon + iter.GetRefCount
		else
			let GrandCommonStolen := GrandCommonStolen + iter.GetRefCount
		endif
		let GrandCommonTotal := GrandCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common3CommonSoul )
		if ( iter.GetOwner == 0 )
			let VanCommonCommon := VanCommonCommon + iter.GetRefCount
		else
			let VanCommonCommonStolen := VanCommonCommonStolen + iter.GetRefCount
		endif
		let CommonCommonTotal := CommonCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterCommon := VanGreaterCommon + iter.GetRefCount
		else
			let VanGreaterCommonStolen := VanGreaterCommonStolen + iter.GetRefCount
		endif
		let GreaterCommonTotal := GreaterCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandCommon := VanGrandCommon + iter.GetRefCount
		else
			let VanGrandCommonStolen := VanGrandCommonStolen + iter.GetRefCount
		endif
		let GrandCommonTotal := GrandCommonTotal + iter.GetRefCount
	endif
loop

if ( CommonCommonTotal > 0 ) && ( GreaterCommonTotal > 0 ) && ( GrandCommonTotal > 0 ) ; CDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( CommonCommonTotal > 0 ) && ( GreaterCommonTotal > 0 ) ; CD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Greater"
elseif ( CommonCommonTotal > 0 ) && ( GrandCommonTotal > 0 ) ; CE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Grand"
elseif ( GreaterCommonTotal > 0 ) && ( GrandCommonTotal > 0 ) ; DE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Greater", "Grand"
elseif ( CommonCommonTotal > 0 ) ; C
	set combo to 1
	MessageBox "Void the common soulgem from the common soul?", "Cancel", "Yes"
elseif ( GreaterCommonTotal > 0 ) ; D
	set combo to 3
	MessageBox "Void the greater soulgem from the common soul?", "Cancel", "Yes"
elseif ( GrandCommonTotal > 0 ) ; E
	set combo to 4
	MessageBox "Void the grand soulgem from the common soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a lesser soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem3CommonSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo == 1 ) || ( combo == 2 ) ; CXX, CX, C
			set stage to 2
		elseif ( combo == 3 ) ; DX, D
			set stage to 3
		elseif ( combo == 4 ) ; E
			set stage to 4
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) ; XDX, XD
			set stage to 3
		elseif ( combo == 2 ) || ( combo == 3 ) ; XE
			set stage to 4
		endif
	elseif ( button == 3 )
		;( combo == 1 ) XXE single case
			set stage to 4
		endif
elseif ( stage == 2 )
	if ( VanCommonCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common3CommonSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonCommon > 1 )
			set VanCommonCommon to ( VanCommonCommon - 1 )
			let iter := CreateTempRef SoulGem3Common3CommonSoul
			iter.SetRefCount VanCommonCommon
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty3Common 1
		Player.AddItemNS Gold001 75
	elseif ( VanCommonCommonStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common3CommonSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanCommonCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonCommonStolen > 1 )
			set VanCommonCommonStolen to ( VanCommonCommonStolen - 1 )
			let iter := CreateTempRef SoulGem3Common3CommonSoul
			iter.SetRefCount VanCommonCommonStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 75
	elseif ( CommonCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 3 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonCommon > 1 )
			set CommonCommon to ( CommonCommon - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonCommon
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty3Common 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 3 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonCommonStolen > 1 )
			set CommonCommonStolen to ( CommonCommonStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonCommonStolen
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A common soulgem has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 0
elseif ( stage == 3 )
	if ( VanGreaterCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterCommon > 1 )
			set VanGreaterCommon to ( VanGreaterCommon - 1 )
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
			iter.SetRefCount VanGreaterCommon
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Player.AddItemNS Gold001 37
	elseif ( VanGreaterCommonStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanGreaterCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterCommonStolen > 1 )
			set VanGreaterCommonStolen to ( VanGreaterCommonStolen - 1 )
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
			iter.SetRefCount VanGreaterCommonStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 37
	elseif ( GreaterCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterCommon > 1 )
			set GreaterCommon to ( GreaterCommon - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterCommon
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterCommonStolen > 1 )
			set GreaterCommonStolen to ( GreaterCommonStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterCommonStolen
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A greater soulgem has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 0
elseif ( stage == 4 )
	if (( VanGrandCommon > 0 ) || ( VanGrandCommonStolen > 0 )) && ( Player.GetItemCount Gold001 >= 38 )
		if ( VanGrandCommon > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandCommon > 1 )
				set VanGrandCommon to ( VanGrandCommon - 1 )
				let iter := CreateTempRef SoulGem5Grand3CommonSoul
				iter.SetRefCount VanGrandCommon
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand3CommonSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandCommonStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandCommonStolen > 1 )
				set VanGrandCommonStolen to ( VanGrandCommonStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand3CommonSoul
				iter.SetRefCount VanGrandCommonStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 38
		Message "A grand soulgem has been voided from the common soul" 4
;		playsound UIItemEnchant
	elseif ( GrandCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandCommon > 1 )
			set GrandCommon to ( GrandCommon - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandCommon
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A grand soulgem has been voided from the common soul" 4
;		playsound UIItemEnchant
	elseif ( GrandCommonStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandCommonStolen > 1 )
			set GrandCommonStolen to ( GrandCommonStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandCommonStolen
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A grand soulgem has been voided from the common soul" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 38 golds compensation" 4
;		playsound SPLDestructionFail
	endif
	set stage to 0
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanCommonCommon to 0
set VanGreaterCommon to 0
set VanGrandCommon to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem3Common3CommonSoul )
			let VanCommonCommon := VanCommonCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
			let VanGreaterCommon := VanGreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
			let VanGrandCommon := VanGrandCommon + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem3Common3CommonSoul ) == 1 ) && ( VanCommonCommon == 0 )
	Player.RemoveItemNS SoulGem3Common3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater3CommonSoul ) == 1 ) && ( VanGreaterCommon == 0 )
	Player.RemoveItemNS SoulGem4Greater3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand3CommonSoul ) == 1 ) && ( VanGrandCommon == 0 )
	Player.RemoveItemNS SoulGem5Grand3CommonSoul 1
endif
let iter := 0
End

 

 

 

SpellID: StandardEmptySoulGem4GreaterSoul

SpellName: Soulhole

SpellLevel: Novice

SpellCost: 3

ScriptEffectName: Greater soul voiding

scn zzSMEmptySoulGemGreaterSoul

Short button
Short combo
ref iter
Short GreaterGreaterTotal
Short GrandGreaterTotal
Short GreaterGreater
Short GrandGreater
Short GreaterGreaterStolen
Short GrandGreaterStolen
Short VanGreaterGreater
Short VanGrandGreater
Short VanGreaterGreaterStolen
Short VanGrandGreaterStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 4 )
		if ( iter.GetOwner == 0 )
			let GreaterGreater := GreaterGreater + iter.GetRefCount
		else
			let GreaterGreaterStolen := GreaterGreaterStolen + iter.GetRefCount
		endif
		let GreaterGreaterTotal := GreaterGreaterTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
		if ( iter.GetOwner == 0 )
			let GrandGreater := GrandGreater + iter.GetRefCount
		else
			let GrandGreaterStolen := GrandGreaterStolen + iter.GetRefCount
		endif
		let GrandGreaterTotal := GrandGreaterTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterGreater := VanGreaterGreater + iter.GetRefCount
		else
			let VanGreaterGreaterStolen := VanGreaterGreaterStolen + iter.GetRefCount
		endif
		let GreaterGreaterTotal := GreaterGreaterTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandGreater := VanGrandGreater + iter.GetRefCount
		else
			let VanGrandGreaterStolen := VanGrandGreaterStolen + iter.GetRefCount
		endif
		let GrandGreaterTotal := GrandGreaterTotal + iter.GetRefCount
	endif
loop

if ( GreaterGreaterTotal > 0 ) && ( GrandGreaterTotal > 0 ) ; DE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the greater soul?", "Cancel", "Greater", "Grand"
elseif ( GreaterGreaterTotal > 0 ) ; D
	set combo to 1
	MessageBox "Void the greater soulgem from the greater soul?", "Cancel", "Yes"
elseif ( GrandGreaterTotal > 0 ) ; E
	set combo to 2
	MessageBox "Void the grand soulgem from the greater soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a greater soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem4GreaterSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo == 1 ) ; DX, D
			set stage to 2
		elseif ( combo == 2 ) ; E
			set stage to 3
		endif
	elseif ( button == 2 )
		;( combo == 1 ) XE single case
			set stage to 3
	endif
elseif ( stage == 2 )
	if ( VanGreaterGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterGreater > 1 )
			set VanGreaterGreater to ( VanGreaterGreater - 1 )
			let iter := CreateTempRef SoulGem4Greater4GreaterSoul
			iter.SetRefCount VanGreaterGreater
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Player.AddItemNS Gold001 187
	elseif ( VanGreaterGreaterStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanGreaterGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterGreaterStolen > 1 )
			set VanGreaterGreaterStolen to ( VanGreaterGreaterStolen - 1 )
			let iter := CreateTempRef SoulGem4Greater4GreaterSoul
			iter.SetRefCount VanGreaterGreaterStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 187
	elseif ( GreaterGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 4 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterGreater > 1 )
			set GreaterGreater to ( GreaterGreater - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterGreater
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 4 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterGreaterStolen > 1 )
			set GreaterGreaterStolen to ( GreaterGreaterStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterGreaterStolen
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A greater soulgem has been voided from the greater soul" 4
;	playsound UIItemEnchant
	set stage to 0
elseif ( stage == 3 )
	if ( VanGrandGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGrandGreater > 1 )
			set VanGrandGreater to ( VanGrandGreater - 1 )
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
			iter.SetRefCount VanGrandGreater
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Player.AddItemNS Gold001 112
	elseif ( VanGrandGreaterStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanGrandGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGrandGreaterStolen > 1 )
			set VanGrandGreaterStolen to ( VanGrandGreaterStolen - 1 )
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
			iter.SetRefCount VanGrandGreaterStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 112
	elseif ( GrandGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandGreater > 1 )
			set GrandGreater to ( GrandGreater - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandGreater
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandGreaterStolen > 1 )
			set GrandGreaterStolen to ( GrandGreaterStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandGreaterStolen
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A grand soulgem has been voided from the greater soul" 4
;	playsound UIItemEnchant
	set stage to 0
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanGreaterGreater to 0
set VanGrandGreater to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul )
			let VanGreaterGreater := VanGreaterGreater + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
			let VanGrandGreater := VanGrandGreater + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem4Greater4GreaterSoul ) == 1 ) && ( VanGreaterGreater == 0 )
	Player.RemoveItemNS SoulGem4Greater4GreaterSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand4GreaterSoul ) == 1 ) && ( VanGrandGreater == 0 )
	Player.RemoveItemNS SoulGem5Grand4GreaterSoul 1
endif
let iter := 0
End

 

 

 

SpellID: StandardEmptySoulGem5GrandSoul

SpellName: Arkay's guaranteer

SpellLevel: Novice

SpellCost: 3

ScriptEffectName: Grand soul voiding

scn zzSMEmptySoulGemGrandSoul

Short button
Short combo
ref iter
short GrandGrandTotal
short BlackGrandTotal
short GrandGrand
short BlackGrand
short GrandGrandStolen
short BlackGrandStolen
short VanGrandGrand
short VanBlackGrand
short VanGrandGrandStolen
short VanBlackGrandStolen
short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 5 )
		if ( iter.GetOwner == 0 )
			let GrandGrand := GrandGrand + iter.GetRefCount
		else
			let GrandGrandStolen := GrandGrandStolen + iter.GetRefCount
		endif
		let GrandGrandTotal := GrandGrandTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 5 )
		if ( iter.GetOwner == 0 )
			let BlackGrand := BlackGrand + iter.GetRefCount
		else
			let BlackGrandStolen := BlackGrandStolen + iter.GetRefCount
		endif
		let BlackGrandTotal := BlackGrandTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand5GrandSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandGrand := VanGrandGrand + iter.GetRefCount
		else
			let VanGrandGrandStolen := VanGrandGrandStolen + iter.GetRefCount
		endif
		let GrandGrandTotal := GrandGrandTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == BlackSoulGemFilled )
		if ( iter.GetOwner == 0 )
			let VanBlackGrand := VanBlackGrand + iter.GetRefCount
		else
			let VanBlackGrandStolen := VanBlackGrandStolen + iter.GetRefCount
		endif
		let BlackGrandTotal := BlackGrandTotal + iter.GetRefCount
	endif
loop

if ( GrandGrandTotal > 0 ) && ( BlackGrandTotal > 0 )
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the grand soul?", "Cancel", "Grand", "Black"
elseif ( GrandGrandTotal > 0 )
	set combo to 1
	MessageBox "Void the grand soulgem from the grand soul?", "Cancel", "Yes"
elseif ( BlackGrandTotal > 0 )
	set combo to 2
	MessageBox "Void the black soulgem from the grand soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a grand soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem5GrandSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo == 1 )
			if ( VanGrandGrand > 0 )
				ForEach iter <- Player
					if ( iter.GetBaseObject == SoulGem5Grand5GrandSoul )
						if ( iter.GetOwner == 0 )
							iter.RemoveMeIR
						endif
					endif
				loop
				if ( VanGrandGrand > 1 )
					set VanGrandGrand to ( VanGrandGrand - 1 )
					let iter := CreateTempRef SoulGem5Grand5GrandSoul
					iter.SetRefCount VanGrandGrand
					iter.CopyIR Player
					endif
				Player.AddItemNS SoulGemEmpty5Grand 1
				Player.AddItemNS Gold001 225
			elseif ( VanGrandGrandStolen > 0 )
				ForEach iter <- Player
					if ( iter.GetBaseObject == SoulGem5Grand5GrandSoul ) && ( OtherGuy == 0 )
						if ( iter.GetOwner != 0 )
							let VanGrandGrandStolen := iter.GetRefCount
							let OtherGuy := iter.GetOwner
							iter.RemoveMeIR
						endif
					endif
				loop
				if ( VanGrandGrandStolen > 1 )
					set VanGrandGrandStolen to ( VanGrandGrandStolen - 1 )
					let iter := CreateTempRef SoulGem5Grand5GrandSoul
					iter.SetRefCount VanGrandGrandStolen
					iter.SetOwner OtherGuy
					iter.CopyIR Player
				endif
				let iter := CreateTempRef SoulGemEmpty5Grand
				iter.SetRefCount 1
				iter.SetOwner OtherGuy
				iter.CopyIR Player
				Player.AddItemNS Gold001 225
			elseif ( GrandGrand > 0 )
				ForEach iter <- Player
					if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 5 )
						if ( iter.GetOwner == 0 )
							iter.RemoveMeIR
						endif
					endif
				loop
				if ( GrandGrand > 1 )
					set GrandGrand to ( GrandGrand - 1 )
					let iter := CreateTempRef SoulGemEmpty5Grand
					iter.SetRefCount GrandGrand
					iter.SetCurrentSoulLevel 5
					iter.CopyIR Player
				endif
				Player.AddItemNS SoulGemEmpty5Grand 1
			else
				ForEach iter <- Player
					if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 5 ) && ( OtherGuy == 0 )
						if ( iter.GetOwner != 0 )
							let GrandGrandStolen := iter.GetRefCount
							let OtherGuy := iter.GetOwner
							iter.RemoveMeIR
						endif
					endif
				loop
				if ( GrandGrandStolen > 1 )
					set GrandGrandStolen to ( GrandGrandStolen - 1 )
					let iter := CreateTempRef SoulGemEmpty5Grand
					iter.SetRefCount GrandGrandStolen
					iter.SetCurrentSoulLevel 5
					iter.CopyIR Player
				endif
				let iter := CreateTempRef SoulGemEmpty5Grand
				iter.SetRefCount 1
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			Message "A grand soulgem has been voided from the grand soul" 4
;			playsound UIItemEnchant
			set stage to 0
		elseif ( combo == 2 )
			set stage to 2
		endif
	elseif ( button == 2 )
		;( combo == 1 ) один вариант
		set stage to 2
	endif
elseif ( stage == 2 )
	if ( VanBlackGrand > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == BlackSoulGemFilled )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanBlackGrand > 1 )
			set VanBlackGrand to ( VanBlackGrand - 1 )
			let iter := CreateTempRef BlackSoulGemFilled
			iter.SetRefCount VanBlackGrand
			iter.CopyIR Player
			endif
		Player.AddItemNS BlackSoulGem 1
		Player.AddItemNS Gold001 525
	elseif ( VanBlackGrandStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == BlackSoulGemFilled ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanBlackGrandStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanBlackGrandStolen > 1 )
			set VanBlackGrandStolen to ( VanBlackGrandStolen - 1 )
			let iter := CreateTempRef BlackSoulGemFilled
			iter.SetRefCount VanBlackGrandStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef BlackSoulGem
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 525
	elseif ( BlackGrand > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 5 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( BlackGrand > 1 )
			set BlackGrand to ( BlackGrand - 1 )
			let iter := CreateTempRef BlackSoulGem
			iter.SetRefCount BlackGrand
			iter.SetCurrentSoulLevel 5
			iter.CopyIR Player
		endif
		Player.AddItemNS BlackSoulGem 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 5 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let BlackGrandStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( BlackGrandStolen > 1 )
			set BlackGrandStolen to ( BlackGrandStolen - 1 )
			let iter := CreateTempRef BlackSoulGem
			iter.SetRefCount BlackGrandStolen
			iter.SetCurrentSoulLevel 5
			iter.CopyIR Player
		endif
		let iter := CreateTempRef BlackSoulGem
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A black soulgem has been voided from the grand soul" 4
;	playsound UIItemEnchant
	set stage to 0
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanGrandGrand to 0
set VanBlackGrand to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem5Grand5GrandSoul )
			let VanGrandGrand := VanGrandGrand + iter.GetRefCount
	elseif ( iter.GetBaseObject == BlackSoulGemFilled )
			let VanBlackGrand := VanBlackGrand + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem5Grand5GrandSoul ) == 1 ) && ( VanGrandGrand == 0 )
	Player.RemoveItemNS SoulGem5Grand5GrandSoul 1
endif
if (( Player.GetItemCount BlackSoulGemFilled ) == 1 ) && ( VanBlackGrand == 0 )
	Player.RemoveItemNS BlackSoulGemFilled 1
endif
let iter := 0
End

 

 

 

SpellID: StandardTransferToSoulGemEmpty1Petty

SpellName: Overcarry

SpellLevel: Novice

SpellCost: 42

ScriptEffectName: Petty soul transferring

scn zzSMTransferSoulGemPettySoul

Short button
Short combo
ref iter
Short LesserPettyTotal
Short CommonPettyTotal
Short GreaterPettyTotal
Short GrandPettyTotal
Short PettyEmpty
Short LesserPetty
Short CommonPetty
Short GreaterPetty
Short GrandPetty
Short PettyEmptyStolen
Short LesserPettyStolen
Short CommonPettyStolen
Short GreaterPettyStolen
Short GrandPettyStolen
Short VanLesserPetty
Short VanCommonPetty
Short VanGreaterPetty
Short VanGrandPetty
Short VanLesserPettyStolen
Short VanCommonPettyStolen
Short VanGreaterPettyStolen
Short VanGrandPettyStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 )
		if ( iter.GetOwner == 0 )
			let PettyEmpty := PettyEmpty + iter.GetRefCount
		else
			let PettyEmptyStolen := PettyEmptyStolen + iter.GetRefCount
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let LesserPetty := LesserPetty + iter.GetRefCount
		else
			let LesserPettyStolen := LesserPettyStolen + iter.GetRefCount
		endif
		let LesserPettyTotal := LesserPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let CommonPetty := CommonPetty + iter.GetRefCount
		else
			let CommonPettyStolen := CommonPettyStolen + iter.GetRefCount
		endif
		let CommonPettyTotal := CommonPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let GreaterPetty := GreaterPetty + iter.GetRefCount
		else
			let GreaterPettyStolen := GreaterPettyStolen + iter.GetRefCount
		endif
		let GreaterPettyTotal := GreaterPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
		if ( iter.GetOwner == 0 )
			let GrandPetty := GrandPetty + iter.GetRefCount
		else
			let GrandPettyStolen := GrandPettyStolen + iter.GetRefCount
		endif
		let GrandPettyTotal := GrandPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanLesserPetty := VanLesserPetty + iter.GetRefCount
		else
			let VanLesserPettyStolen := VanLesserPettyStolen + iter.GetRefCount
		endif
		let LesserPettyTotal := LesserPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanCommonPetty := VanCommonPetty + iter.GetRefCount
		else
			let VanCommonPettyStolen := VanCommonPettyStolen + iter.GetRefCount
		endif
		let CommonPettyTotal := CommonPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterPetty := VanGreaterPetty + iter.GetRefCount
		else
			let VanGreaterPettyStolen := VanGreaterPettyStolen + iter.GetRefCount
		endif
		let GreaterPettyTotal := GreaterPettyTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
		if ( iter.GetOwner == 0 )
			let VanGrandPetty := VanGrandPetty + iter.GetRefCount
		else
			let VanGrandPettyStolen := VanGrandPettyStolen + iter.GetRefCount
		endif
		let GrandPettyTotal := GrandPettyTotal + iter.GetRefCount
	endif
loop

if ( PettyEmpty == 0 ) && ( PettyEmptyStolen == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty petty soulgem" 4
	set stage to -1
elseif ( PettyEmpty > 26 )
;	playsound SPLDestructionFail
	Message "You have more than 26 of the empty petty soulgems in your inventory, the spell can not handle such quantity" 4
	set stage to -1
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BCDE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; BCD
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Greater"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BCE
	set combo to 2
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BDE
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Greater", "Grand"
elseif ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; CDE
	set combo to 5
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Greater", "Grand"
elseif ( LesserPettyTotal > 0 ) && ( CommonPettyTotal > 0 ) ; BC
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common"
elseif ( LesserPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; BD
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Greater"
elseif ( LesserPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; BE
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Grand"
elseif ( CommonPettyTotal > 0 ) && ( GreaterPettyTotal > 0 ) ; CD
	set combo to 5
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Greater"
elseif ( CommonPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; CE
	set combo to 6
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Grand"
elseif ( GreaterPettyTotal > 0 ) && ( GrandPettyTotal > 0 ) ; DE
	set combo to 7
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Greater", "Grand"
elseif ( LesserPettyTotal > 0 ) ; B
	set combo to 1
	MessageBox "Transfer the petty soul from the lesser soulgem to the petty soulgem?", "Cancel", "Yes"
elseif ( CommonPettyTotal > 0 ) ; C
	set combo to 5
	MessageBox "Transfer the petty soul from the common soulgem to the petty soulgem?", "Cancel", "Yes"
elseif ( GreaterPettyTotal > 0 ) ; D
	set combo to 7
	MessageBox "Transfer the petty soul from the greater soulgem to the petty soulgem?", "Cancel", "Yes"
elseif ( GrandPettyTotal > 0 ) ; E
	set combo to 8
	MessageBox "Transfer the petty soul from the grand soulgem to the petty soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a petty soulgem filled with a petty soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty1Petty
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 4 ) ; BXXX, BXX, BX, B
			set stage to 2
		elseif ( combo == 5 ) || ( combo == 6 ) ; CXX, CX, C
			set stage to 3
		elseif ( combo == 7 ) ; DX, D
			set stage to 4
		elseif ( combo == 8 ) ; E
			set stage to 5
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) || ( combo == 2 ) ; XCXX, XCX, XC
			set stage to 3
		elseif ( combo == 3 ) || ( combo == 5 ) ; XDX, XD
			set stage to 4
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 7 ) ; XE
			set stage to 5
		endif
	elseif ( button == 3 )
		if ( combo == 1 ); XXDX, XXD
			set stage to 4
		elseif ( combo == 2 ) || ( combo == 3 ) || ( combo == 5 ) ; XXE
			set stage to 5
		endif
	elseif ( button == 4 )
		;( combo == 1 ) XXXE single case
		set stage to 5
	endif
elseif ( stage == 2 )
	if ( VanLesserPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserPetty > 1 )
			set VanLesserPetty to ( VanLesserPetty - 1 )
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
			iter.SetRefCount VanLesserPetty
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
		Player.AddItemNS Gold001 11
	elseif ( VanLesserPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanLesserPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanLesserPettyStolen > 1 )
			set VanLesserPettyStolen to ( VanLesserPettyStolen - 1 )
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
			iter.SetRefCount VanLesserPettyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 11
	elseif ( LesserPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserPetty > 1 )
			set LesserPetty to ( LesserPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty2Lesser 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let LesserPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( LesserPettyStolen > 1 )
			set LesserPettyStolen to ( LesserPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A petty soul has been transferred from the lesser soulgem to the empty petty one" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 3 )
	if (( VanCommonPetty > 0 ) || ( VanCommonPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 8 )
		if ( VanCommonPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem3Common1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanCommonPetty > 1 )
				set VanCommonPetty to ( VanCommonPetty - 1 )
				let iter := CreateTempRef SoulGem3Common1PettySoul
				iter.SetRefCount VanCommonPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty3Common 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem3Common1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanCommonPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanCommonPettyStolen > 1 )
				set VanCommonPettyStolen to ( VanCommonPettyStolen - 1 )
				let iter := CreateTempRef SoulGem3Common1PettySoul
				iter.SetRefCount VanCommonPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 8
		Message "A petty soul has been transferred from the common soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( CommonPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonPetty > 1 )
			set CommonPetty to ( CommonPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty3Common 1
		Message "A petty soul has been transferred from the common soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( CommonPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonPettyStolen > 1 )
			set CommonPettyStolen to ( CommonPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A petty soul has been transferred from the common soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 8 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 6
	endif
elseif ( stage == 4 )
	if (( VanGreaterPetty > 0 ) || ( VanGreaterPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 45 )
		if ( VanGreaterPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterPetty > 1 )
				set VanGreaterPetty to ( VanGreaterPetty - 1 )
				let iter := CreateTempRef SoulGem4Greater1PettySoul
				iter.SetRefCount VanGreaterPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty4Greater 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGreaterPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterPettyStolen > 1 )
				set VanGreaterPettyStolen to ( VanGreaterPettyStolen - 1 )
				let iter := CreateTempRef SoulGem4Greater1PettySoul
				iter.SetRefCount VanGreaterPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 45
		Message "A petty soul has been transferred from the greater soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( GreaterPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterPetty > 1 )
			set GreaterPetty to ( GreaterPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Message "A petty soul has been transferred from the greater soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( GreaterPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterPettyStolen > 1 )
			set GreaterPettyStolen to ( GreaterPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A petty soul has been transferred from the greater soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 45 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 6
	endif
elseif ( stage == 5 )
	if (( VanGrandPetty > 0 ) || ( VanGrandPettyStolen > 0 )) && ( Player.GetItemCount Gold001 >= 120 )
		if ( VanGrandPetty > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandPetty > 1 )
				set VanGrandPetty to ( VanGrandPetty - 1 )
				let iter := CreateTempRef SoulGem5Grand1PettySoul
				iter.SetRefCount VanGrandPetty
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand1PettySoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandPettyStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandPettyStolen > 1 )
				set VanGrandPettyStolen to ( VanGrandPettyStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand1PettySoul
				iter.SetRefCount VanGrandPettyStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 120
		Message "A petty soul has been transferred from the grand soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( GrandPetty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandPetty > 1 )
			set GrandPetty to ( GrandPetty - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandPetty
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A petty soul has been transferred from the grand soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	elseif ( GrandPettyStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandPettyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandPettyStolen > 1 )
			set GrandPettyStolen to ( GrandPettyStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandPettyStolen
			iter.SetCurrentSoulLevel 1
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A petty soul has been transferred from the grand soulgem to the empty petty one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 120 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 6
	endif
elseif ( stage == 6 )
	if ( PettyEmpty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 1
		iter.CopyIR Player
		if ( PettyEmpty > 1 )
			set stage to 7
		endif
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let PettyEmptyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		if ( PettyEmptyStolen > 1 )
			set PettyEmptyStolen to PettyEmptyStolen - 1
			let iter := CreateTempRef SoulGemEmpty1Petty
			iter.SetRefCount PettyEmptyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
	endif
	if ( stage != 7 )
		set stage to 0
	endif
elseif ( stage == 7 )
	if ( PettyEmpty > 1 )
		Player.AddItemNS SoulGemEmpty1Petty 1
		set PettyEmpty to PettyEmpty - 1
	else
		set stage to 0
	endif
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanLesserPetty to 0
set VanCommonPetty to 0
set VanGreaterPetty to 0
set VanGrandPetty to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
			let VanLesserPetty := VanLesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
			let VanCommonPetty := VanCommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
			let VanGreaterPetty := VanGreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
			let VanGrandPetty := VanGrandPetty + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem2Lesser1PettySoul ) == 1 ) && ( VanLesserPetty == 0 )
	Player.RemoveItemNS SoulGem2Lesser1PettySoul 1
endif
if (( Player.GetItemCount SoulGem3Common1PettySoul ) == 1 ) && ( VanCommonPetty == 0 )
	Player.RemoveItemNS SoulGem3Common1PettySoul 1
endif
if (( Player.GetItemCount SoulGem4Greater1PettySoul ) == 1 ) && ( VanGreaterPetty == 0 )
	Player.RemoveItemNS SoulGem4Greater1PettySoul 1
endif
if (( Player.GetItemCount SoulGem5Grand1PettySoul ) == 1 ) && ( VanGrandPetty == 0 )
	Player.RemoveItemNS SoulGem5Grand1PettySoul 1
endif
; Give the remaining empty soulgems in case when the script was incompleted on the stage 7
; (are you playing on the potato-PC?..)
if ( stage == 7 ) && ( PettyEmpty > 1 )
	Message "The result empty petty soulgem group is partly defected. Do not keep such big quantity of them in your inventory!" 5
	set PettyEmpty to PettyEmpty - 1
	Player.AddItemNS SoulGemEmpty1Petty PettyEmpty
	set PettyEmpty to 0
	set stage to 0
endif
let iter := 0
End

 

 

 

SpellID: StandardTransferToSoulGemEmpty2Lesser

SpellName: Dislocation

SpellLevel: Apprentice

SpellCost: 82

ScriptEffectName: Lesser soul transferring

scn zzSMTransferSoulGemLesserSoul

Short button
Short combo
ref iter
Short CommonLesserTotal
Short GreaterLesserTotal
Short GrandLesserTotal
Short LesserEmpty
Short CommonLesser
Short GreaterLesser
Short GrandLesser
Short LesserEmptyStolen
Short CommonLesserStolen
Short GreaterLesserStolen
Short GrandLesserStolen
Short VanCommonLesser
Short VanGreaterLesser
Short VanGrandLesser
Short VanCommonLesserStolen
Short VanGreaterLesserStolen
Short VanGrandLesserStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 )
		if ( iter.GetOwner == 0 )
			let LesserEmpty := LesserEmpty + iter.GetRefCount
		else
			let LesserEmptyStolen := LesserEmptyStolen + iter.GetRefCount
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let CommonLesser := CommonLesser + iter.GetRefCount
		else
			let CommonLesserStolen := CommonLesserStolen + iter.GetRefCount
		endif
		let CommonLesserTotal := CommonLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let GreaterLesser := GreaterLesser + iter.GetRefCount
		else
			let GreaterLesserStolen := GreaterLesserStolen + iter.GetRefCount
		endif
		let GreaterLesserTotal := GreaterLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
		if ( iter.GetOwner == 0 )
			let GrandLesser := GrandLesser + iter.GetRefCount
		else
			let GrandLesserStolen := GrandLesserStolen + iter.GetRefCount
		endif
		let GrandLesserTotal := GrandLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanCommonLesser := VanCommonLesser + iter.GetRefCount
		else
			let VanCommonLesserStolen := VanCommonLesserStolen + iter.GetRefCount
		endif
		let CommonLesserTotal := CommonLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterLesser := VanGreaterLesser + iter.GetRefCount
		else
			let VanGreaterLesserStolen := VanGreaterLesserStolen + iter.GetRefCount
		endif
		let GreaterLesserTotal := GreaterLesserTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandLesser := VanGrandLesser + iter.GetRefCount
		else
			let VanGrandLesserStolen := VanGrandLesserStolen + iter.GetRefCount
		endif
		let GrandLesserTotal := GrandLesserTotal + iter.GetRefCount
	endif
loop

if ( LesserEmpty == 0 ) && ( LesserEmptyStolen == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty lesser soulgem" 4
	set stage to -1
elseif ( LesserEmpty > 26 )
;	playsound SPLDestructionFail
	Message "You have more than 26 of the empty lesser soulgems in your inventory, the spell can not handle such quantity" 4
	set stage to -1
elseif ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; CDE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Greater", "Grand"
elseif ( CommonLesserTotal > 0 ) && ( GreaterLesserTotal > 0 ) ; CD
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Greater"
elseif ( CommonLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; CE
	set combo to 2
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Grand"
elseif ( GreaterLesserTotal > 0 ) && ( GrandLesserTotal > 0 ) ; DE
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Greater", "Grand"
elseif ( CommonLesserTotal > 0 ) ; C
	set combo to 1
	MessageBox "Transfer the lesser soul from the common soulgem to the lesser soulgem?", "Cancel", "Yes"
elseif ( GreaterLesserTotal > 0 ) ; D
	set combo to 3
	MessageBox "Transfer the lesser soul from the greater soulgem to the lesser soulgem?", "Cancel", "Yes"
elseif ( GrandLesserTotal > 0 ) ; E
	set combo to 4
	MessageBox "Transfer the lesser soul from the grand soulgem to the lesser soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a lesser soulgem filled with a lesser soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty2Lesser
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo == 1 ) || ( combo == 2 ) ; CXX, CX, C
			set stage to 2
		elseif ( combo == 3 ) ; DX, D
			set stage to 3
		elseif ( combo == 4 ) ; E
			set stage to 4
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) ; XDX, XD
			set stage to 3
		elseif ( combo == 2 ) || ( combo == 3 ) ; XE
			set stage to 4
		endif
	elseif ( button == 3 )
		;( combo == 1 ) XXE single case
			set stage to 4
		endif
elseif ( stage == 2 )
	if ( VanCommonLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonLesser > 1 )
			set VanCommonLesser to ( VanCommonLesser - 1 )
			let iter := CreateTempRef SoulGem3Common2LesserSoul
			iter.SetRefCount VanCommonLesser
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty3Common 1
		Player.AddItemNS Gold001 22
	elseif ( VanCommonLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem3Common2LesserSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanCommonLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanCommonLesserStolen > 1 )
			set VanCommonLesserStolen to ( VanCommonLesserStolen - 1 )
			let iter := CreateTempRef SoulGem3Common2LesserSoul
			iter.SetRefCount VanCommonLesserStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 22
	elseif ( CommonLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonLesser > 1 )
			set CommonLesser to ( CommonLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty3Common 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( CommonLesserStolen > 1 )
			set CommonLesserStolen to ( CommonLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
		Message "A lesser soul has been transferred from the common soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
		set stage to 5
elseif ( stage == 3 )
	if (( VanGreaterLesser > 0 ) || ( VanGreaterLesserStolen > 0 )) && ( Player.GetItemCount Gold001 >= 15 )
		if ( VanGreaterLesser > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterLesser > 1 )
				set VanGreaterLesser to ( VanGreaterLesser - 1 )
				let iter := CreateTempRef SoulGem4Greater2LesserSoul
				iter.SetRefCount VanGreaterLesser
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty4Greater 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem4Greater2LesserSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGreaterLesserStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGreaterLesserStolen > 1 )
				set VanGreaterLesserStolen to ( VanGreaterLesserStolen - 1 )
				let iter := CreateTempRef SoulGem4Greater2LesserSoul
				iter.SetRefCount VanGreaterLesserStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 15
		Message "A lesser soul has been transferred from the greater soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	elseif ( GreaterLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterLesser > 1 )
			set GreaterLesser to ( GreaterLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Message "A lesser soul has been transferred from the greater soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	elseif ( GreaterLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterLesserStolen > 1 )
			set GreaterLesserStolen to ( GreaterLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A lesser soul has been transferred from the greater soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 15 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 5
	endif
elseif ( stage == 4 )
	if (( VanGrandLesser > 0 ) || ( VanGrandLesserStolen > 0 )) && ( Player.GetItemCount Gold001 >= 90 )
		if ( VanGrandLesser > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandLesser > 1 )
				set VanGrandLesser to ( VanGrandLesser - 1 )
				let iter := CreateTempRef SoulGem5Grand2LesserSoul
				iter.SetRefCount VanGrandLesser
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand2LesserSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandLesserStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandLesserStolen > 1 )
				set VanGrandLesserStolen to ( VanGrandLesserStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand2LesserSoul
				iter.SetRefCount VanGrandLesserStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 90
		Message "A lesser soul has been transferred from the grand soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	elseif ( GrandLesser > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandLesser > 1 )
			set GrandLesser to ( GrandLesser - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandLesser
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A lesser soul has been transferred from the grand soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	elseif ( GrandLesserStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandLesserStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandLesserStolen > 1 )
			set GrandLesserStolen to ( GrandLesserStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandLesserStolen
			iter.SetCurrentSoulLevel 2
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A lesser soul has been transferred from the grand soulgem to the empty lesser one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 90 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 5
	endif
elseif ( stage == 5 )
	if ( LesserEmpty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 2
		iter.CopyIR Player
		if ( LesserEmpty > 1 )
			set stage to 6
		endif
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let LesserEmptyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 2
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		if ( LesserEmptyStolen > 1 )
			set LesserEmptyStolen to LesserEmptyStolen - 1
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetRefCount LesserEmptyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
	endif
	if ( stage != 6 )
		set stage to 0
	endif
elseif ( stage == 6 )
	if ( LesserEmpty > 1 )
		Player.AddItemNS SoulGemEmpty2Lesser 1
		set LesserEmpty to LesserEmpty - 1
	else
		set stage to 0
	endif
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanCommonLesser to 0
set VanGreaterLesser to 0
set VanGrandLesser to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
			let VanCommonLesser := VanCommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
			let VanGreaterLesser := VanGreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
			let VanGrandLesser := VanGrandLesser + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem3Common2LesserSoul ) == 1 ) && ( VanCommonLesser == 0 )
	Player.RemoveItemNS SoulGem3Common2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater2LesserSoul ) == 1 ) && ( VanGreaterLesser == 0 )
	Player.RemoveItemNS SoulGem4Greater2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand2LesserSoul ) == 1 ) && ( VanGrandLesser == 0 )
	Player.RemoveItemNS SoulGem5Grand2LesserSoul 1
endif
; Give the remaining empty soulgems in case when the script was incompleted on the stage 6
; (are you playing on the potato-PC?..)
if ( stage == 6 ) && ( LesserEmpty > 1 )
	Message "The result empty lesser soulgem group is partly defected. Do not keep such big quantity of them in your inventory!" 5
	set LesserEmpty to LesserEmpty - 1
	Player.AddItemNS SoulGemEmpty2Lesser LesserEmpty
	set LesserEmpty to 0
	set stage to 0
endif
let iter := 0
End

 

 

 

SpellID: StandardTransferToSoulGemEmpty3Common

SpellName: Relocation

SpellLevel: Journeyman

SpellCost: 164

ScriptEffectName: Common soul transferring

scn zzSMTransferSoulGemCommonSoul

Short button
Short combo
ref iter
Short GreaterCommonTotal
Short GrandCommonTotal
Short CommonEmpty
Short GreaterCommon
Short GrandCommon
Short CommonEmptyStolen
Short GreaterCommonStolen
Short GrandCommonStolen
Short VanGreaterCommon
Short VanGrandCommon
Short VanGreaterCommonStolen
Short VanGrandCommonStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 )
		if ( iter.GetOwner == 0 )
			let CommonEmpty := CommonEmpty + iter.GetRefCount
		else
			let CommonEmptyStolen := CommonEmptyStolen + iter.GetRefCount
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
		if ( iter.GetOwner == 0 )
			let GreaterCommon := GreaterCommon + iter.GetRefCount
		else
			let GreaterCommonStolen := GreaterCommonStolen + iter.GetRefCount
		endif
		let GreaterCommonTotal := GreaterCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
		if ( iter.GetOwner == 0 )
			let GrandCommon := GrandCommon + iter.GetRefCount
		else
			let GrandCommonStolen := GrandCommonStolen + iter.GetRefCount
		endif
		let GrandCommonTotal := GrandCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
		if ( iter.GetOwner == 0 )
			let VanGreaterCommon := VanGreaterCommon + iter.GetRefCount
		else
			let VanGreaterCommonStolen := VanGreaterCommonStolen + iter.GetRefCount
		endif
		let GreaterCommonTotal := GreaterCommonTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandCommon := VanGrandCommon + iter.GetRefCount
		else
			let VanGrandCommonStolen := VanGrandCommonStolen + iter.GetRefCount
		endif
		let GrandCommonTotal := GrandCommonTotal + iter.GetRefCount
	endif
loop

if ( CommonEmpty == 0 ) && ( CommonEmptyStolen == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty common soulgem" 4
	set stage to -1
elseif ( CommonEmpty > 26 )
;	playsound SPLDestructionFail
	Message "You have more than 26 of the empty common soulgems in your inventory, the spell can not handle such quantity" 4
	set stage to -1
elseif ( GreaterCommonTotal > 0 ) && ( GrandCommonTotal > 0 ) ; DE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the common soul from to the common soulgem", "Cancel", "Greater", "Grand"
elseif ( GreaterCommonTotal > 0 ) ; D
	set combo to 1
	MessageBox "Transfer the common soul from the greater soulgem to the common soulgem?", "Cancel", "Yes"
elseif ( GrandCommonTotal > 0 ) ; E
	set combo to 2
	MessageBox "Transfer the common soul from the grand soulgem to the common soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a common soulgem filled with a common soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty3Common
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		if ( combo == 1 ) ; DX, D
			set stage to 2
		elseif ( combo == 2 ) ; E
			set stage to 3
		endif
	elseif ( button == 2 )
		;( combo == 1 ) XE single case
			set stage to 3
	endif
elseif ( stage == 2 )
	if ( VanGreaterCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterCommon > 1 )
			set VanGreaterCommon to ( VanGreaterCommon - 1 )
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
			iter.SetRefCount VanGreaterCommon
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty4Greater 1
		Player.AddItemNS Gold001 37
	elseif ( VanGreaterCommonStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanGreaterCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGreaterCommonStolen > 1 )
			set VanGreaterCommonStolen to ( VanGreaterCommonStolen - 1 )
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
			iter.SetRefCount VanGreaterCommonStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 37
	elseif ( GreaterCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterCommon > 1 )
			set GreaterCommon to ( GreaterCommon - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterCommon
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty4Greater 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GreaterCommonStolen > 1 )
			set GreaterCommonStolen to ( GreaterCommonStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterCommonStolen
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A common soul has been transferred from the greater soulgem to the empty common one" 4
;	playsound UIItemEnchant
	set stage to 4
elseif ( stage == 3 )
	if (( VanGrandCommon > 0 ) || ( VanGrandCommonStolen > 0 )) && ( Player.GetItemCount Gold001 >= 38 )
		if ( VanGrandCommon > 0 )
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
					if ( iter.GetOwner == 0 )
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandCommon > 1 )
				set VanGrandCommon to ( VanGrandCommon - 1 )
				let iter := CreateTempRef SoulGem5Grand3CommonSoul
				iter.SetRefCount VanGrandCommon
				iter.CopyIR Player
				endif
			Player.AddItemNS SoulGemEmpty5Grand 1
		else
			ForEach iter <- Player
				if ( iter.GetBaseObject == SoulGem5Grand3CommonSoul ) && ( OtherGuy == 0 )
					if ( iter.GetOwner != 0 )
						let VanGrandCommonStolen := iter.GetRefCount
						let OtherGuy := iter.GetOwner
						iter.RemoveMeIR
					endif
				endif
			loop
			if ( VanGrandCommonStolen > 1 )
				set VanGrandCommonStolen to ( VanGrandCommonStolen - 1 )
				let iter := CreateTempRef SoulGem5Grand3CommonSoul
				iter.SetRefCount VanGrandCommonStolen
				iter.SetOwner OtherGuy
				iter.CopyIR Player
			endif
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount 1
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		Player.RemoveItemNS Gold001 38
		Message "A common soul has been transferred from the grand soulgem to the empty common one" 4
;		playsound UIItemEnchant
	elseif ( GrandCommon > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandCommon > 1 )
			set GrandCommon to ( GrandCommon - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandCommon
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Message "A common soul has been transferred from the grand soulgem to the empty common one" 4
;		playsound UIItemEnchant
	elseif ( GrandCommonStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandCommonStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandCommonStolen > 1 )
			set GrandCommonStolen to ( GrandCommonStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandCommonStolen
			iter.SetCurrentSoulLevel 3
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Message "A common soul has been transferred from the grand soulgem to the empty common one" 4
;		playsound UIItemEnchant
	else
		Message "That action requires a 38 golds compensation" 4
		set stage to 0
;		playsound SPLDestructionFail
	endif
	if ( stage != 0 )
		set stage to 4
	endif
elseif ( stage == 4 )
	if ( CommonEmpty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 3
		iter.CopyIR Player
		if ( CommonEmpty > 1 )
			set stage to 5
		endif
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let CommonEmptyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 3
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		if ( CommonEmptyStolen > 1 )
			set CommonEmptyStolen to CommonEmptyStolen - 1
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetRefCount CommonEmptyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
	endif
	if ( stage != 5 )
		set stage to 0
	endif
elseif ( stage == 5 )
	if ( CommonEmpty > 1 )
		Player.AddItemNS SoulGemEmpty3Common 1
		set CommonEmpty to CommonEmpty - 1
	else
		set stage to 0
	endif
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanGreaterCommon to 0
set VanGrandCommon to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
			let VanGreaterCommon := VanGreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
			let VanGrandCommon := VanGrandCommon + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem4Greater3CommonSoul ) == 1 ) && ( VanGreaterCommon == 0 )
	Player.RemoveItemNS SoulGem4Greater3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand3CommonSoul ) == 1 ) && ( VanGrandCommon == 0 )
	Player.RemoveItemNS SoulGem5Grand3CommonSoul 1
endif
; Give the remaining empty soulgems in case when the script was incompleted on the stage 5
; (are you playing on the potato-PC?..)
if ( stage == 5 ) && ( CommonEmpty > 1 )
	Message "The result empty common soulgem group is partly defected. Do not keep such big quantity of them in your inventory!" 5
	set CommonEmpty to CommonEmpty - 1
	Player.AddItemNS SoulGemEmpty3Common CommonEmpty
	set CommonEmpty to 0
	set stage to 0
endif
let iter := 0
End

 

 

 

SpellID: StandardTransferToSoulGemEmpty4Greater

SpellName: Translocation

SpellLevel: Expert

SpellCost: 406

ScriptEffectName: Greater soul transferring

scn zzSMTransferSoulGemGreaterSoul

Short button
ref iter
Short GrandGreaterTotal
Short GreaterEmpty
Short GrandGreater
Short GreaterEmptyStolen
Short GrandGreaterStolen
Short VanGrandGreater
Short VanGrandGreaterStolen
Short stage
ref OtherGuy

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 )
		if ( iter.GetOwner == 0 )
			let GreaterEmpty := GreaterEmpty + iter.GetRefCount
		else
			let GreaterEmptyStolen := GreaterEmptyStolen + iter.GetRefCount
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
		if ( iter.GetOwner == 0 )
			let GrandGreater := GrandGreater + iter.GetRefCount
		else
			let GrandGreaterStolen := GrandGreaterStolen + iter.GetRefCount
		endif
		let GrandGreaterTotal := GrandGreaterTotal + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
		if ( iter.GetOwner == 0 )
			let VanGrandGreater := VanGrandGreater + iter.GetRefCount
		else
			let VanGrandGreaterStolen := VanGrandGreaterStolen + iter.GetRefCount
		endif
		let GrandGreaterTotal := GrandGreaterTotal + iter.GetRefCount
	endif
loop

if ( GreaterEmpty == 0 ) && ( GreaterEmptyStolen == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty greater soulgem" 4
	set stage to -1
elseif ( GreaterEmpty > 26 )
;	playsound SPLDestructionFail
	Message "You have more than 26 of the empty greater soulgems in your inventory, the spell can not handle such quantity" 4
	set stage to -1
elseif ( GrandGreaterTotal > 0 )
	MessageBox "Transfer the greater soul from the grand soulgem to the greater soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have a grand soulgem filled with a greater soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty4Greater
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 0
	elseif ( button == 1 )
		set stage to 2
	endif
elseif ( stage == 2 )
	if ( VanGrandGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGrandGreater > 1 )
			set VanGrandGreater to ( VanGrandGreater - 1 )
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
			iter.SetRefCount VanGrandGreater
			iter.CopyIR Player
			endif
		Player.AddItemNS SoulGemEmpty5Grand 1
		Player.AddItemNS Gold001 112
	elseif ( VanGrandGreaterStolen > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let VanGrandGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( VanGrandGreaterStolen > 1 )
			set VanGrandGreaterStolen to ( VanGrandGreaterStolen - 1 )
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
			iter.SetRefCount VanGrandGreaterStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		Player.AddItemNS Gold001 112
	elseif ( GrandGreater > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandGreater > 1 )
			set GrandGreater to ( GrandGreater - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandGreater
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		Player.AddItemNS SoulGemEmpty5Grand 1
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GrandGreaterStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		if ( GrandGreaterStolen > 1 )
			set GrandGreaterStolen to ( GrandGreaterStolen - 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetRefCount GrandGreaterStolen
			iter.SetCurrentSoulLevel 4
			iter.CopyIR Player
		endif
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.SetOwner OtherGuy
		iter.CopyIR Player
	endif
	Message "A greater soul has been transferred from the grand soulgem to the empty greater one" 4
;	playsound UIItemEnchant
	if ( GreaterEmpty > 0 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 )
				if ( iter.GetOwner == 0 )
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 4
		iter.CopyIR Player
		if ( GreaterEmpty > 1 )
			set stage to 3
		endif
	else
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 ) && ( OtherGuy == 0 )
				if ( iter.GetOwner != 0 )
					let GreaterEmptyStolen := iter.GetRefCount
					let OtherGuy := iter.GetOwner
					iter.RemoveMeIR
				endif
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 4
		iter.SetOwner OtherGuy
		iter.CopyIR Player
		if ( GreaterEmptyStolen > 1 )
			set GreaterEmptyStolen to GreaterEmptyStolen - 1
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetRefCount GreaterEmptyStolen
			iter.SetOwner OtherGuy
			iter.CopyIR Player
		endif
	endif
	if ( stage != 3 )
		set stage to 0
	endif
elseif ( stage == 3 )
	if ( GreaterEmpty > 1 )
		Player.AddItemNS SoulGemEmpty4Greater 1
		set GreaterEmpty to GreaterEmpty - 1
	else
		set stage to 0
	endif
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set VanGrandGreater to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
			let VanGrandGreater := VanGrandGreater + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem5Grand4GreaterSoul ) == 1 ) && ( VanGrandGreater == 0 )
	Player.RemoveItemNS SoulGem5Grand4GreaterSoul 1
endif
; Give the remaining empty soulgems in case when the script was incompleted on the stage 3
; (are you playing on the potato-PC?..)
if ( stage == 3 ) && ( GreaterEmpty > 1 )
	Message "The result empty greater soulgem group is partly defected. Do not keep such big quantity of them in your inventory!" 5
	set GreaterEmpty to GreaterEmpty - 1
	Player.AddItemNS SoulGemEmpty4Greater GreaterEmpty
	set GreaterEmpty to 0
	set stage to 0
endif
let iter := 0
End

 

 

However, as the practics showes, all the scriptally added empty soulgems will be a united stack/stacks in the player's inventory (even if to add them one by one, one piece per frame) at least after the game/savegame load. That 'united stack's behavior is - when the player is capturing the soul, that whole united stack is filling with just that one captured soul becoming a stack of the filled soulgems. I did not find a way to avoid it. Only the empty soulgems which existence in the world is due to the plugins which adds them (...or in theory, scriptally add the one piece of the empty soulgem to some container, save game, load game... but the player HAVE TO get it from it by -him/-herself) - only those soulgems will be not uniting in one stack.

But there is a way to fix that situation - through the quest script and the ability 'spell'.

 

Quest:

Title: zzSMGivenByScriptsEmptySoulGemsOnGameReloadFix

It's script: zzSMGBSESGOGRFQuestSCRIPT

; Fix for the empty soulgems inside the player's inventory to break apart the single stacks in which they
; all can be filled from the one soul capture. The case they are could be a single stack OR the
; group of the objects in which some of them are the stacks with more than one soulgem - the empty
; soulgem was picked up from the game world, the empty soulgems were scriptally added to the player
; (or any other container) in quantity more than one piece per frame, or the scriptally added empty
; soulgems united after the game/savegame was reloaded.
; With this quest script the empty soulgems inside the player's inventory will always can be considered
; as "scriptally added".

ref iter
short ActionNeeded

Begin GameMode

if ( GetGameLoaded == 1 )
	ForEach iter <- Player
		if (( iter.GetBaseObject == SoulGemEmpty1Petty ) || ( iter.GetBaseObject == SoulGemEmpty2Lesser ) || ( iter.GetBaseObject == SoulGemEmpty3Common ) || ( iter.GetBaseObject == SoulGemEmpty4Greater ) || ( iter.GetBaseObject == SoulGemEmpty5Grand )) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 ) && ( ActionNeeded == 0 )
			if ( iter.GetOwner == 0 )
				set ActionNeeded to 1
			endif
		endif
	loop
endif

if ( ActionNeeded == 1 )
	Player.AddSpellNS zzSMGivenByScriptsEmptySoulGemsOnGameReloadFixSpell
	set ActionNeeded to 0
elseif ( ActionNeeded == 2 )
	Player.RemoveSpellNS zzSMGivenByScriptsEmptySoulGemsOnGameReloadFixSpell
	set ActionNeeded to 0
endif

End

 

 

Spell:

ID: zzSMGivenByScriptsEmptySoulGemsOnGameReloadFixSpell

Name: The things to think about

Type: Ability

ScriptEffectName: Dreaminess

Range: Self

School: Illusion

Visuals Effect: None

Effect is Hostile: Unchecked

Script: zzSMGBSESGOGRFSpellSCRIPT

scn zzSMGBSESGOGRFSpellSCRIPT

ref iter
short PettyEmpty
short LesserEmpty
short CommonEmpty
short GreaterEmpty
short GrandEmpty
short BlackEmpty
short WaitTilRemoveMe

Begin ScriptEffectStart

set WaitTilRemoveMe to 0

ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set PettyEmpty to PettyEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set LesserEmpty to LesserEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set CommonEmpty to CommonEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set GreaterEmpty to GreaterEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set GrandEmpty to GrandEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	elseif ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 )
		if ( iter.GetOwner == 0 )
			set BlackEmpty to BlackEmpty + iter.GetRefCount
			iter.RemoveMeIR
		endif
	endif
loop

End

Begin ScriptEffectUpdate

if ( PettyEmpty > 0 ) || ( LesserEmpty > 0 ) || ( CommonEmpty > 0 ) || ( GreaterEmpty > 0 ) || ( GrandEmpty > 0 )
	if ( PettyEmpty > 0 )
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.CopyIR Player
		set PettyEmpty to PettyEmpty - 1
	endif
	if ( LesserEmpty > 0 )
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.CopyIR Player
		set LesserEmpty to LesserEmpty - 1
	endif
	if ( CommonEmpty > 0 )
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.CopyIR Player
		set CommonEmpty to CommonEmpty - 1
	endif
	if ( GreaterEmpty > 0 )
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.CopyIR Player
		set GreaterEmpty to GreaterEmpty - 1
	endif
	if ( GrandEmpty > 0 )
		let iter := CreateTempRef SoulGemEmpty5Grand
		iter.SetRefCount 1
		iter.CopyIR Player
		set GrandEmpty to GrandEmpty - 1
	endif
	if ( BlackEmpty > 0 )
		Player.AddItemNS BlackSoulGem 1
		set BlackEmpty to BlackEmpty - 1
	endif
elseif ( BlackEmpty > 0 )
	let iter := CreateTempRef BlackSoulGem
	iter.SetRefCount 1
	iter.CopyIR Player
	set BlackEmpty to BlackEmpty - 1
else		
	if ( WaitTilRemoveMe == 0 )
		let iter := 0
		set zzSMGivenByScriptsEmptySoulGemsOnGameReloadFix.ActionNeeded to 2
		set WaitTilRemoveMe to 1
	endif
endif

End

 

Edited by Stealth21
Link to comment
Share on other sites

  • 2 months later...

After the experience of creating the NPC soul trap into the white soulgem spell, I rethought those spells, so they becomes smaller, uses lesser variables, goes through ForEach<->Loop as lesser times as possible (all this means that they becomes faster, however, it is not noticeable though), and plus Azura's Star is now included too.

I edited my first post for fixes and improvements so many times, so I decided to leave it untouched for to it be a comparison to see the difference in realization.

SpellID: StandardEmptySoulGem1PettySoul
SpellName: Gap
SpellLevel: Novice
SpellCost: 3
ScriptEffectName: Petty soul voiding

scn zzSMEmptySoulGemPettySoul

Short button
Short combo
ref iter
Short AzuraPetty
Short PettyPetty
Short LesserPetty
Short CommonPetty
Short GreaterPetty
Short GrandPetty
Short ActionDone ;also as an active effect index for the self-dispel
Short stage
ref OtherGuy

short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 1 )
		set AzuraPetty to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 1 )
		let PettyPetty := PettyPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
		let LesserPetty := LesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
		let CommonPetty := CommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
		let GreaterPetty := GreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
		let GrandPetty := GrandPetty + iter.GetRefCount
	endif
loop

if ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZABCDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star",  "Petty", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZABCD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZABCE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZABDE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZACDE
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZBCDE
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABCDE
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ZABC
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZABD
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZABE
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZACD
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZACE
	set combo to 8
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZADE
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZBCD
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZBCE
	set combo to 10
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZBDE
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZCDE
	set combo to 12
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Common", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ABCD
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABCE
	set combo to 13
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABDE
	set combo to 14
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ACDE
	set combo to 15
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BCDE
	set combo to 16
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; ZAB
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Lesser"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ZAC
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZAD
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZAE
	set combo to 17
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ZBC
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZBD
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZBE
	set combo to 18
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZCD
	set combo to 12
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZCE
	set combo to 19
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZDE
	set combo to 20
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ABC
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Common"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ABD
	set combo to 14
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Greater"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABE
	set combo to 21
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ACD
	set combo to 15
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ACE
	set combo to 22
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ADE
	set combo to 23
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; BCD
	set combo to 16
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BCE
	set combo to 24
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BDE
	set combo to 25
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; CDE
	set combo to 26
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) ; ZA
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Petty"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; ZB
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Lesser"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ZC
	set combo to 12
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ZD
	set combo to 20
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ZE
	set combo to 27
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; AB
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Lesser"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; AC
	set combo to 15
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Common"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; AD
	set combo to 23
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Greater"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; AE
	set combo to 28
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Petty", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; BC
	set combo to 16
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Common"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; BD
	set combo to 25
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BE
	set combo to 29
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Lesser", "Grand"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; CD
	set combo to 26
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; CE
	set combo to 30
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; DE
	set combo to 31
	MessageBox "Which soulgem do you want to be voided from the petty soul?", "Cancel", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) ; Z
	set combo to 1
	MessageBox "Void the Azura's Star from the petty soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem1Petty1PettySoul > 0 ) || ( PettyPetty > 0 )) ; A
	set combo to 6
	MessageBox "Void the petty soulgem from the petty soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; B
	set combo to 16
	MessageBox "Void the lesser soulgem from the petty soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; C
	set combo to 26
	MessageBox "Void the common soulgem from the petty soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; D
	set combo to 31
	MessageBox "Void the greater soulgem from the petty soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; E
	set combo to 32
	MessageBox "Void the grand soulgem from the petty soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a petty soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem1PettySoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 8
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 5 ) || ( combo >= 7 ) && ( combo <= 12 ) || ( combo >= 17 ) && ( combo <= 20 ) || ( combo == 27 ) ; ZXXXXX, ZXXXX, ZXXX, ZXX, ZX, Z
			set stage to 2
		elseif ( combo == 6 ) || ( combo >= 13 ) && ( combo <= 15 ) || ( combo >= 21 ) && ( combo <= 23 ) || ( combo == 28 ) ; AXXXX, AXXX, AXX, AX, A
			set stage to 3
		elseif ( combo == 16 ) || ( combo == 24 ) || ( combo == 25 ) || ( combo == 29 ) ; BXXX, BXXX, BXX, BX, B
			set stage to 4
		elseif ( combo == 26 ) || ( combo == 30 ) ; CXX, CX, C
			set stage to 5
		elseif ( combo == 31 ) ; DX, D
			set stage to 6
		elseif ( combo == 32 ) ; E
			set stage to 7
		endif
	elseif ( button == 2 )
		if ( combo >= 1 ) && ( combo <= 4 ) || ( combo >= 7 ) && ( combo <= 9 ) || ( combo == 17 ) ; XAXXXX, XAXXX, XAXX, XAX, XA
			set stage to 3
		elseif ( combo == 5 ) || ( combo == 6 ) || ( combo == 10 ) || ( combo == 11 ) || ( combo == 13 ) || ( combo == 14 ) || ( combo == 18 ) || ( combo == 21 ) ; XBXXX, XBXX, XBX, XB
			set stage to 4
		elseif ( combo == 12 ) || ( combo == 15 ) || ( combo == 16 ) || ( combo == 19 ) || ( combo == 22 ) || ( combo == 24 ) ; XCXX, XCX, XC
			set stage to 5
		elseif ( combo == 20 ) || ( combo == 23 ) || ( combo == 25 ) || ( combo == 26 ); XDX, XD
			set stage to 6
		elseif ( combo >= 27 ) && ( combo <= 31 ) ; XE
			set stage to 7
		endif
	elseif ( button == 3 )
		if ( combo >= 1 ) && ( combo <= 3 ) || ( combo == 7 ) ; XXBXXX, XXBXX, XXBX, XXB
			set stage to 4
		elseif ( combo >= 4 ) && ( combo <= 6 ) || ( combo == 8 ) || ( combo == 10 ) || ( combo == 13 ) ; XXCXX, XXCX, XXC
			set stage to 5
		elseif ( combo == 9 ) || ( combo == 11 ) || ( combo == 12 ) || ( combo >= 14 ) && ( combo <= 16 ); XXDX, XXD
			set stage to 6
		elseif ( combo >= 17 ) && ( combo <= 26 ) ; XXE
			set stage to 7
		endif
	elseif ( button == 4 )
		if ( combo == 1 ) || ( combo == 2 ) ; XXXCXX, XXXCX, XXXC
			set stage to 5
		elseif ( combo >= 3 ) && ( combo <= 6 ) ; XXXDX, XXXD
			set stage to 6
		elseif ( combo >= 7 ) && ( combo <= 16 ) ; XXXE
			set stage to 7
		endif
	elseif ( button == 5 )
		if ( combo == 1 ) ; XXXXDX, XXXXD
			set stage to 6
		elseif ( combo >= 2 ) && ( combo <= 6 ) ; XXXXE
			set stage to 7
		endif
	elseif ( button == 6 )
		;( combo == 1 ) XXXXXE single case
		set stage to 7
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem1Petty1PettySoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 22
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem2Lesser1PettySoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 11
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGem3Common1PettySoul ) && ( Player.GetItemCount Gold001 >= 8 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 8
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGem4Greater1PettySoul ) && ( Player.GetItemCount Gold001 >= 45 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 45
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 7 ) && ( iter.GetBaseObject == SoulGem5Grand1PettySoul ) && ( Player.GetItemCount Gold001 >= 120 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 120
		iter.RemoveMeIR
	elseif ( stage == 7 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "The Azura's Star has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 3 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty1Petty
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem1Petty1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty1Petty
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A petty soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 4 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty2Lesser
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A lesser soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 5 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem3Common1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty3Common
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A common soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 5 ) && ( ActionDone == 0 )
	Message "That action requires a 8 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 8
elseif ( stage == 6 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem4Greater1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A greater soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 6 ) && ( ActionDone == 0 )
	Message "That action requires a 45 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 8
elseif ( stage == 7 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem5Grand1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A grand soulgem has been voided from the petty soul" 4
;	playsound UIItemEnchant
	set stage to 8
elseif ( stage == 7 ) && ( ActionDone == 0 )
	Message "That action requires a 120 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 8
elseif ( stage == 8 )
	set ActionDone to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect ActionDone
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set PettyPetty to 0
set LesserPetty to 0
set CommonPetty to 0
set GreaterPetty to 0
set GrandPetty to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem1Petty1PettySoul )
		let PettyPetty := PettyPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
			let LesserPetty := LesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
			let CommonPetty := CommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
			let GreaterPetty := GreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
			let GrandPetty := GrandPetty + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem1Petty1PettySoul ) == 1 ) && ( PettyPetty == 0 )
	Player.RemoveItemNS SoulGem1Petty1PettySoul 1
endif
if (( Player.GetItemCount SoulGem2Lesser1PettySoul ) == 1 ) && ( LesserPetty == 0 )
	Player.RemoveItemNS SoulGem2Lesser1PettySoul 1
endif
if (( Player.GetItemCount SoulGem3Common1PettySoul ) == 1 ) && ( CommonPetty == 0 )
	Player.RemoveItemNS SoulGem3Common1PettySoul 1
endif
if (( Player.GetItemCount SoulGem4Greater1PettySoul ) == 1 ) && ( GreaterPetty == 0 )
	Player.RemoveItemNS SoulGem4Greater1PettySoul 1
endif
if (( Player.GetItemCount SoulGem5Grand1PettySoul ) == 1 ) && ( GrandPetty == 0 )
	Player.RemoveItemNS SoulGem5Grand1PettySoul 1
endif
let iter := 0
End

 


SpellID: StandardEmptySoulGem2LesserSoul
SpellName: Outlet
SpellLevel: Novice
SpellCost: 3
ScriptEffectName: Lesser soul voiding

scn zzSMEmptySoulGemLesserSoul

Short button
Short combo
ref iter
Short AzuraLesser
Short LesserLesser
Short CommonLesser
Short GreaterLesser
Short GrandLesser
Short ActionDone ;also as an active effect index for the self-dispel
Short stage
ref OtherGuy

short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 2 )
		set AzuraLesser to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 2 )
		let LesserLesser := LesserLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
		let CommonLesser := CommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
		let GreaterLesser := GreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
		let GrandLesser := GrandLesser + iter.GetRefCount
	endif
loop

if ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZBCDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; ZBCD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZBCE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Common", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZBDE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZCDE
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Common", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; BCDE
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; ZBC
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Common"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; ZBD
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZBE
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; ZCD
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Common", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZCE
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Common", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZDE
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; BCD
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; BCE
	set combo to 10
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; BDE
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; CDE
	set combo to 13
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) ; ZB
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Lesser"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; ZC
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Common"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; ZD
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ZE
	set combo to 8
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; BC
	set combo to 9
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Common"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; BD
	set combo to 11
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; BE
	set combo to 12
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Lesser", "Grand"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; CD
	set combo to 13
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; CE
	set combo to 14
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; DE
	set combo to 15
	MessageBox "Which soulgem do you want to be voided from the lesser soul?", "Cancel", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) ; Z
	set combo to 1
	MessageBox "Void the Azura's Star from the lesser soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem2Lesser2LesserSoul > 0 ) || ( LesserLesser > 0 )) ; B
	set combo to 9
	MessageBox "Void the lesser soulgem from the lesser soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; C
	set combo to 13
	MessageBox "Void the common soulgem from the lesser soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; D
	set combo to 15
	MessageBox "Void the greater soulgem from the lesser soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; E
	set combo to 16
	MessageBox "Void the grand soulgem from the lesser soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a lesser soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem2LesserSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 6
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 8 ) ; ZXXXX, ZXXX, ZXX, ZX, Z
			set stage to 2
		elseif ( combo >= 9 ) && ( combo <= 12 ) ; BXXX, BXX, BX, B
			set stage to 3
		elseif ( combo == 13 ) || ( combo == 14 ) ; CXX, CX, C
			set stage to 4
		elseif ( combo == 15 ) ; DX, D
			set stage to 5
		elseif ( combo == 16 ) ; E
			set stage to 6
		endif
	elseif ( button == 2 )
		if ( combo >= 1 ) && ( combo <= 3 ) || ( combo == 5 ) ; XBXX, XBX, XB
			set stage to 3
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 9 ) || ( combo == 10 ) ; XCXX, XCX, XC
			set stage to 4
		elseif ( combo == 7 ) || ( combo == 11 ) || ( combo == 13 ); XDX, XD
			set stage to 5
		elseif ( combo == 8 ) || ( combo == 12 ) || ( combo == 14 ) || ( combo == 15 ) ; XE
			set stage to 6
		endif
	elseif ( button == 3 )
		if ( combo == 1 ) || ( combo == 2 ) ; XXCX, XXC
			set stage to 4
		elseif ( combo == 3 ) || ( combo == 4 ) || ( combo == 9 ); XXDX, XXD
			set stage to 5
		elseif ( combo >= 5 ) && ( combo <= 7 ) || ( combo == 10 ) || ( combo == 11 ) || ( combo == 13 ) ; XXE
			set stage to 6
		endif
	elseif ( button == 4 )
		if ( combo == 1 ) ; XXXD
			set stage to 5
		elseif ( combo >= 2 ) && ( combo <= 4 ) || ( combo == 10 ) || ( combo == 9 ) ; XXXE
			set stage to 6
		endif
	elseif ( button == 5 )
		;( combo == 1 ) XXXXE single case
		set stage to 6
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 41
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem3Common2LesserSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 22
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGem4Greater2LesserSoul ) && ( Player.GetItemCount Gold001 >= 15 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 15
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGem5Grand2LesserSoul ) && ( Player.GetItemCount Gold001 >= 90 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 90
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "The Azura's Star has been voided from the lesser soul" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 3 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem2Lesser2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty2Lesser
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A lesser soulgem has been voided from the lesser soul" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 4 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem3Common2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty3Common
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A common soulgem has been voided from the lesser soul" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 5 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem4Greater2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A greater soulgem has been voided from the lesser soul" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 5 ) && ( ActionDone == 0 )
	Message "That action requires a 15 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 7
elseif ( stage == 6 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem5Grand2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A grand soulgem has been voided from the lesser soul" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 6 ) && ( ActionDone == 0 )
	Message "That action requires a 90 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 7
elseif ( stage == 7 )
	set ActionDone to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect ActionDone
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set LesserLesser to 0
set CommonLesser to 0
set GreaterLesser to 0
set GrandLesser to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem2Lesser2LesserSoul )
			let LesserLesser := LesserLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
			let CommonLesser := CommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
			let GreaterLesser := GreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
			let GrandLesser := GrandLesser + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem2Lesser2LesserSoul ) == 1 ) && ( LesserLesser == 0 )
	Player.RemoveItemNS SoulGem2Lesser2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem3Common2LesserSoul ) == 1 ) && ( CommonLesser == 0 )
	Player.RemoveItemNS SoulGem3Common2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater2LesserSoul ) == 1 ) && ( GreaterLesser == 0 )
	Player.RemoveItemNS SoulGem4Greater2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand2LesserSoul ) == 1 ) && ( GrandLesser == 0 )
	Player.RemoveItemNS SoulGem5Grand2LesserSoul 1
endif
let iter := 0
End

 


SpellID: StandardEmptySoulGem3CommonSoul
SpellName: Drainage
SpellLevel: Novice
SpellCost: 3
ScriptEffectName: Common soul voiding

scn zzSMEmptySoulGemCommonSoul

Short button
Short combo
ref iter
Short AzuraCommon
Short CommonCommon
Short GreaterCommon
Short GrandCommon
Short ActionDone ;also as an active effect index for the self-dispel
Short stage
ref OtherGuy

short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 3 )
		set AzuraCommon to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 3 )
		let CommonCommon := CommonCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
		let GreaterCommon := GreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
		let GrandCommon := GrandCommon + iter.GetRefCount
	endif
loop

if ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; ZCDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Common", "Greater", "Grand"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; ZCD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Common", "Greater"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; ZCE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Common", "Grand"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; ZDE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; CDE
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Greater", "Grand"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) ; ZC
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Common"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; ZD
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; ZE
	set combo to 4
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; CD
	set combo to 5
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; CE
	set combo to 6
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; DE
	set combo to 7
	MessageBox "Which soulgem do you want to be voided from the common soul?", "Cancel", "Greater", "Grand"
elseif ( AzuraCommon > 0 ) ; Z
	set combo to 1
	MessageBox "Void the Azura's Star from the common soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem3Common3CommonSoul > 0 ) || ( CommonCommon > 0 )) ; C
	set combo to 5
	MessageBox "Void the common soulgem from the common soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; D
	set combo to 7
	MessageBox "Void the greater soulgem from the common soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; E
	set combo to 8
	MessageBox "Void the grand soulgem from the common soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a common soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem3CommonSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 6
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 4 ) ; ZXXX, ZXX, ZX, Z
			set stage to 2
		elseif ( combo == 5 ) || ( combo == 6 ) ; CXX, CX, C
			set stage to 3
		elseif ( combo == 7 ) ; DX, D
			set stage to 4
		elseif ( combo == 8 ) ; E
			set stage to 5
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) || ( combo == 2 ) ; XCXX, XCX, XC
			set stage to 3
		elseif ( combo == 3 ) || ( combo == 5 ) ; XDX, XD
			set stage to 4
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 7 ) ; XE
			set stage to 5
		endif
	elseif ( button == 3 )
		if ( combo == 1 ); XXDX, XXD
			set stage to 4
		elseif ( combo == 2 ) || ( combo == 3 ) || ( combo == 5 ) ; XXE
			set stage to 5
		endif
	elseif ( button == 4 )
		;( combo == 1 ) XXXE single case
		set stage to 5
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem3Common3CommonSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 75
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 3 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem4Greater3CommonSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 37
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGem5Grand3CommonSoul ) && ( Player.GetItemCount Gold001 >= 38 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 38
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "The Azura's Star has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 3 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetCurrentSoulLevel 3
		else
			let iter := CreateTempRef SoulGem3Common3CommonSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty3Common
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A common soulgem has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 4 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 3
		else
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A greater soulgem has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 5 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 3
		else
			let iter := CreateTempRef SoulGem5Grand3CommonSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A grand soulgem has been voided from the common soul" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 5 ) && ( ActionDone == 0 )
	Message "That action requires a 38 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 6
elseif ( stage == 6 )
	set ActionDone to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect ActionDone
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set CommonCommon to 0
set GreaterCommon to 0
set GrandCommon to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem3Common3CommonSoul )
			let CommonCommon := CommonCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
			let GreaterCommon := GreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
			let GrandCommon := GrandCommon + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem3Common3CommonSoul ) == 1 ) && ( CommonCommon == 0 )
	Player.RemoveItemNS SoulGem3Common3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater3CommonSoul ) == 1 ) && ( GreaterCommon == 0 )
	Player.RemoveItemNS SoulGem4Greater3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand3CommonSoul ) == 1 ) && ( GrandCommon == 0 )
	Player.RemoveItemNS SoulGem5Grand3CommonSoul 1
endif
let iter := 0
End

 


SpellID: StandardEmptySoulGem4GreaterSoul
SpellName: Soulhole
SpellLevel: Novice
SpellCost: 3
ScriptEffectName: Greater soul voiding

scn zzSMEmptySoulGemGreaterSoul

Short button
Short combo
ref iter
Short AzuraGreater
Short GreaterGreater
Short GrandGreater
Short ActionDone ;also as an active effect index for the self-dispel
Short stage
ref OtherGuy

short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 4 )
		set AzuraGreater to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 4 )
		let GreaterGreater := GreaterGreater + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
		let GrandGreater := GrandGreater + iter.GetRefCount
	endif
loop

if ( AzuraGreater > 0 ) && (( Player.GetItemCount SoulGem4Greater4GreaterSoul > 0 ) || ( GreaterGreater > 0 )) && (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; ZDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the greater soul?", "Cancel", "Azura's Star", "Greater", "Grand"
elseif ( AzuraGreater > 0 ) && (( Player.GetItemCount SoulGem4Greater4GreaterSoul > 0 ) || ( GreaterGreater > 0 )) ; ZD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the greater soul?", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraGreater > 0 ) && (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; ZE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the greater soul?", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater4GreaterSoul > 0 ) || ( GreaterGreater > 0 )) && (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; DE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the greater soul?", "Cancel", "Greater", "Grand"
elseif ( AzuraGreater > 0 ) ; Z
	set combo to 1
	MessageBox "Void the Azura's Star from the greater soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater4GreaterSoul > 0 ) || ( GreaterGreater > 0 )) ; D
	set combo to 3
	MessageBox "Void the greater soulgem from the greater soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; E
	set combo to 4
	MessageBox "Void the grand soulgem from the greater soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a greater soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem4GreaterSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 5
	elseif ( button == 1 )
		if ( combo == 1 ) || ( combo == 2 ) ; ZXX, ZX, Z
			set stage to 2
		elseif ( combo == 3 ) ; DX, D
			set stage to 3
		elseif ( combo == 4 ) ; E
			set stage to 4
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) ; XDX, XD
			set stage to 3
		elseif ( combo == 2 ) || ( combo == 3 ) ; XE
			set stage to 4
		endif
	elseif ( button == 3 )
		;( combo == 1 ) XXE single case
			set stage to 4
		endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 187
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 4 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 112
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "The Azura's Star has been voided from the greater soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 3 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 4
		else
			let iter := CreateTempRef SoulGem4Greater4GreaterSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A greater soulgem has been voided from the greater soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 4 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 4
		else
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A grand soulgem has been voided from the greater soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 5 )
	set ActionDone to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect ActionDone
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set GreaterGreater to 0
set GrandGreater to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem4Greater4GreaterSoul )
			let GreaterGreater := GreaterGreater + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
			let GrandGreater := GrandGreater + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem4Greater4GreaterSoul ) == 1 ) && ( GreaterGreater == 0 )
	Player.RemoveItemNS SoulGem4Greater4GreaterSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand4GreaterSoul ) == 1 ) && ( GrandGreater == 0 )
	Player.RemoveItemNS SoulGem5Grand4GreaterSoul 1
endif
let iter := 0
End

 


SpellID: StandardEmptySoulGem5GrandSoul
SpellName: Arkay's guaranteer
SpellLevel: Novice
SpellCost: 3
ScriptEffectName: Grand soul voiding

scn zzSMEmptySoulGemGrandSoul


Short button
Short combo
ref iter
Short AzuraGrand
Short BlackGrand
Short GrandGrand
Short ActionDone ;also as an active effect index for the self-dispel
Short stage
ref OtherGuy

short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 5 )
		set AzuraGrand to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 5 )
		let GrandGrand := GrandGrand + iter.GetRefCount
	elseif ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 5 )
		let BlackGrand := BlackGrand + iter.GetRefCount
	endif
loop

if ( AzuraGrand > 0 ) && (( Player.GetItemCount BlackSoulGemFilled > 0 ) || ( BlackGrand > 0 )) && (( Player.GetItemCount SoulGem5Grand5GrandSoul > 0 ) || ( GrandGrand > 0 )) ; ZDE
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the grand soul?", "Cancel", "Azura's Star", "Black", "Grand"
elseif ( AzuraGrand > 0 ) && (( Player.GetItemCount BlackSoulGemFilled > 0 ) || ( BlackGrand > 0 )) ; ZD
	set combo to 1
	MessageBox "Which soulgem do you want to be voided from the grand soul?", "Cancel", "Azura's Star", "Black"
elseif ( AzuraGrand > 0 ) && (( Player.GetItemCount SoulGem5Grand5GrandSoul > 0 ) || ( GrandGrand > 0 )) ; ZE
	set combo to 2
	MessageBox "Which soulgem do you want to be voided from the grand soul?", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount BlackSoulGemFilled > 0 ) || ( BlackGrand > 0 )) && (( Player.GetItemCount SoulGem5Grand5GrandSoul > 0 ) || ( GrandGrand > 0 )) ; DE
	set combo to 3
	MessageBox "Which soulgem do you want to be voided from the grand soul?", "Cancel", "Black", "Grand"
elseif ( AzuraGrand > 0 ) ; Z
	set combo to 1
	MessageBox "Void the Azura's Star from the grand soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount BlackSoulGemFilled > 0 ) || ( BlackGrand > 0 )) ; D
	set combo to 3
	MessageBox "Void the black soulgem from the grand soul?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand5GrandSoul > 0 ) || ( GrandGrand > 0 )) ; E
	set combo to 4
	MessageBox "Void the grand soulgem from the grand soul?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any soulgem filled with a grand soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardEmptySoulGem5GrandSoul
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 5
	elseif ( button == 1 )
		if ( combo == 1 ) || ( combo == 2 ) ; ZXX, ZX, Z
			set stage to 2
		elseif ( combo == 3 ) ; DX, D
			set stage to 3
		elseif ( combo == 4 ) ; E
			set stage to 4
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) ; XDX, XD
			set stage to 3
		elseif ( combo == 2 ) || ( combo == 3 ) ; XE
			set stage to 4
		endif
	elseif ( button == 3 )
		;( combo == 1 ) XXE single case
			set stage to 4
		endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == BlackSoulGemFilled ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 525
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == BlackSoulGem ) && ( iter.GetCurrentSoulLevel == 5 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem5Grand5GrandSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 225
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 5 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "The Azura's Star has been voided from the grand soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 3 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef BlackSoulGem
			iter.SetCurrentSoulLevel 5
		else
			let iter := CreateTempRef BlackSoulGemFilled
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef BlackSoulGem
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A black soulgem has been voided from the grand soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 4 ); && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 5
		else
			let iter := CreateTempRef SoulGem5Grand5GrandSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A grand soulgem has been voided from the grand soul" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 5 )
	set ActionDone to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect ActionDone
endif
End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set BlackGrand to 0
set GrandGrand to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == BlackSoulGemFilled )
			let BlackGrand := BlackGrand + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand5GrandSoul )
			let GrandGrand := GrandGrand + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount BlackSoulGemFilled ) == 1 ) && ( BlackGrand == 0 )
	Player.RemoveItemNS BlackSoulGemFilled 1
endif
if (( Player.GetItemCount SoulGem5Grand5GrandSoul ) == 1 ) && ( GrandGrand == 0 )
	Player.RemoveItemNS SoulGem5Grand5GrandSoul 1
endif
let iter := 0
End

 


SpellID: StandardTransferToSoulGemEmpty1Petty
SpellName: Overcarry
SpellLevel: Novice
SpellCost: 42
ScriptEffectName: Petty soul transferring

scn zzSMTransferSoulGemPettySoul

Short button
Short combo ; also as a possibility if there was a stack of the empty soulgems
ref iter
Short PettyEmpty ;also as an active effect index for the self-dispel
Short AzuraPetty
Short LesserPetty
Short CommonPetty
Short GreaterPetty
Short GrandPetty
Short stage
short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn
ref OtherGuy
short ActionDone

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 )
		let PettyEmpty := PettyEmpty + iter.GetRefCount
	elseif ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 1 )
		set AzuraPetty to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 )
		let LesserPetty := LesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 )
		let CommonPetty := CommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 )
		let GreaterPetty := GreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 )
		let GrandPetty := GrandPetty + iter.GetRefCount
	endif
loop

if ( PettyEmpty == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty petty soulgem" 4
	set stage to -1
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABCDE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ABCD
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABCE
	set combo to 2
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABDE
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ACDE
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Common", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BCDE
	set combo to 9
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; ABC
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ABD
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ABE
	set combo to 5
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; ACD
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Common", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ACE
	set combo to 6
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Common", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; ADE
	set combo to 7
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; BCD
	set combo to 9
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BCE
	set combo to 10
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BDE
	set combo to 11
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; CDE
	set combo to 13
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; AB
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Lesser"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; AC
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Common"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; AD
	set combo to 7
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraPetty > 0 ) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; AE
	set combo to 8
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; BC
	set combo to 9
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Common"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; BD
	set combo to 11
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Greater"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; BE
	set combo to 12
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Lesser", "Grand"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; CD
	set combo to 13
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; CE
	set combo to 14
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) && (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; DE
	set combo to 15
	MessageBox "Choose the soulgem you want to transfer the petty soul from to the petty soulgem", "Cancel", "Greater", "Grand"
elseif ( AzuraPetty > 0 ) ; A
	set combo to 1
	MessageBox "Transfer the petty soul from the Azura's Star to the petty soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem2Lesser1PettySoul > 0 ) || ( LesserPetty > 0 )) ; B
	set combo to 9
	MessageBox "Transfer the petty soul from the lesser soulgem to the petty soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem3Common1PettySoul > 0 ) || ( CommonPetty > 0 )) ; C
	set combo to 13
	MessageBox "Transfer the petty soul from the common soulgem to the petty soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater1PettySoul > 0 ) || ( GreaterPetty > 0 )) ; D
	set combo to 15
	MessageBox "Transfer the petty soul from the greater soulgem to the petty soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand1PettySoul > 0 ) || ( GrandPetty > 0 )) ; E
	set combo to 16
	MessageBox "Transfer the petty soul from the grand soulgem to the petty soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a petty soulgem filled with a petty soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty1Petty
	return
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 7
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 8 ) ; AXXXX, AXXX, AXX, AX, A
			set stage to 2
		elseif ( combo >= 9 ) && ( combo <= 12 ) ; BXXX, BXX, BX, B
			set stage to 3
		elseif ( combo == 13 ) || ( combo == 14 ) ; CXX, CX, C
			set stage to 4
		elseif ( combo == 15 ) ; DX, D
			set stage to 5
		elseif ( combo == 16 ) ; E
			set stage to 6
		endif
	elseif ( button == 2 )
		if ( combo >= 1 ) && ( combo <= 3 ) || ( combo == 5 ) ; XBXX, XBX, XB
			set stage to 3
		elseif ( combo == 4 ) || ( combo == 6 ) || ( combo == 9 ) || ( combo == 10 ) ; XCXX, XCX, XC
			set stage to 4
		elseif ( combo == 7 ) || ( combo == 11 ) || ( combo == 13 ); XDX, XD
			set stage to 5
		elseif ( combo == 8 ) || ( combo == 12 ) || ( combo == 14 ) || ( combo == 15 ) ; XE
			set stage to 6
		endif
	elseif ( button == 3 )
		if ( combo == 1 ) || ( combo == 2 ) ; XXCX, XXC
			set stage to 4
		elseif ( combo == 3 ) || ( combo == 4 ) || ( combo == 9 ); XXDX, XXD
			set stage to 5
		elseif ( combo >= 5 ) && ( combo <= 7 ) || ( combo == 10 ) || ( combo == 11 ) || ( combo == 13 ) ; XXE
			set stage to 6
		endif
	elseif ( button == 4 )
		if ( combo == 1 ) ; XXXD
			set stage to 5
		elseif ( combo >= 2 ) && ( combo <= 4 ) || ( combo == 10 ) || ( combo == 9 ) ; XXXE
			set stage to 6
		endif
	elseif ( button == 5 )
		;( combo == 1 ) XXXXE single case
		set stage to 6
	endif
	if ( stage != 0 ) && ( stage != 1 )
		set combo to 0
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem2Lesser1PettySoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 11
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem3Common1PettySoul ) && ( Player.GetItemCount Gold001 >= 8 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 8
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGem4Greater1PettySoul ) && ( Player.GetItemCount Gold001 >= 45 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 45
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGem5Grand1PettySoul ) && ( Player.GetItemCount Gold001 >= 120 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 120
		iter.RemoveMeIR
	elseif ( stage == 6 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 1 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "A petty soul has been transferred from the Azura's Star to the empty petty soulgem" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 3 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty2Lesser
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem2Lesser1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty2Lesser
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A petty soul has been transferred from the lesser soulgem to the empty petty one" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 4 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem3Common1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty3Common
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A petty soul has been transferred from the common soulgem to the empty petty one" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 4 ) && ( ActionDone == 0 )
	Message "That action requires a 8 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 7
elseif ( stage == 5 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem4Greater1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A petty soul has been transferred from the greater soulgem to the empty petty one" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 5 ) && ( ActionDone == 0 )
	Message "That action requires a 45 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 7
elseif ( stage == 6 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 1
		else
			let iter := CreateTempRef SoulGem5Grand1PettySoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A petty soul has been transferred from the grand soulgem to the empty petty one" 4
;	playsound UIItemEnchant
	set stage to 7
elseif ( stage == 6 ) && ( ActionDone == 0 )
	Message "That action requires a 120 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 7
elseif ( stage == 7 )
	set PettyEmpty to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect PettyEmpty
endif

if ( ActionDone == 1 )
	set ActionDone to 0
	let OtherGuy := 0
	ForEach iter <- Player
		if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount == 1 ) && ( ActionDone == 0 )
			iter.SetCurrentSoulLevel 1
			set ActionDone to 1
		elseif ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 ) && ( ActionDone == 0 )
			set combo to 1
		endif
	loop
	if ( ActionDone == 0 ) && ( combo == 1 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty1Petty ) && ( iter.GetCurrentSoulLevel == 0 ) && ( ActionDone == 0 )
				if ( iter.GetOwner != 0 )
					let OtherGuy := iter.GetOwner
				endif
				set ActionDone to 1
				set PettyEmpty to ( iter.GetRefCount - 1 )
				iter.RemoveMeIR
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount PettyEmpty
		iter.SetCurrentSoulLevel 0
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
		let iter := CreateTempRef SoulGemEmpty1Petty
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 1
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	set ActionDone to 0
endif

End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set LesserPetty to 0
set CommonPetty to 0
set GreaterPetty to 0
set GrandPetty to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem2Lesser1PettySoul )
			let LesserPetty := LesserPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem3Common1PettySoul )
			let CommonPetty := CommonPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater1PettySoul )
			let GreaterPetty := GreaterPetty + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand1PettySoul )
			let GrandPetty := GrandPetty + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem2Lesser1PettySoul ) == 1 ) && ( LesserPetty == 0 )
	Player.RemoveItemNS SoulGem2Lesser1PettySoul 1
endif
if (( Player.GetItemCount SoulGem3Common1PettySoul ) == 1 ) && ( CommonPetty == 0 )
	Player.RemoveItemNS SoulGem3Common1PettySoul 1
endif
if (( Player.GetItemCount SoulGem4Greater1PettySoul ) == 1 ) && ( GreaterPetty == 0 )
	Player.RemoveItemNS SoulGem4Greater1PettySoul 1
endif
if (( Player.GetItemCount SoulGem5Grand1PettySoul ) == 1 ) && ( GrandPetty == 0 )
	Player.RemoveItemNS SoulGem5Grand1PettySoul 1
endif

let iter := 0
End

 


SpellID: StandardTransferToSoulGemEmpty2Lesser
SpellName: Dislocation
SpellLevel: Apprentice
SpellCost: 82
ScriptEffectName: Lesser soul transferring

scn zzSMTransferSoulGemLesserSoul

Short button
Short combo ; also as a possibility if there was a stack of the empty soulgems
ref iter
Short LesserEmpty ;also as an active effect index for the self-dispel
Short AzuraLesser
Short CommonLesser
Short GreaterLesser
Short GrandLesser
Short stage
short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn
ref OtherGuy
short ActionDone

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 )
		let LesserEmpty := LesserEmpty + iter.GetRefCount
	elseif ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 2 )
		set AzuraLesser to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 )
		let CommonLesser := CommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 )
		let GreaterLesser := GreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 )
		let GrandLesser := GrandLesser + iter.GetRefCount
	endif
loop

if ( LesserEmpty == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty lesser soulgem" 4
	set stage to -1
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ACDE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Common", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; ACD
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Common", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ACE
	set combo to 2
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Common", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; ADE
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Greater", "Grand"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; CDE
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; AC
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Common"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; AD
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraLesser > 0 ) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; AE
	set combo to 5
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; CD
	set combo to 4
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Greater"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; CE
	set combo to 6
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Common", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) && (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; DE
	set combo to 7
	MessageBox "Choose the soulgem you want to transfer the lesser soul from to the lesser soulgem", "Cancel", "Greater", "Grand"
elseif ( AzuraLesser > 0 ) ; A
	set combo to 1
	MessageBox "Transfer the lesser soul from the Azura's Star to the lesser soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem3Common2LesserSoul > 0 ) || ( CommonLesser > 0 )) ; C
	set combo to 4
	MessageBox "Transfer the lesser soul from the common soulgem to the lesser soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater2LesserSoul > 0 ) || ( GreaterLesser > 0 )) ; D
	set combo to 7
	MessageBox "Transfer the lesser soul from the greater soulgem to the lesser soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand2LesserSoul > 0 ) || ( GrandLesser > 0 )) ; E
	set combo to 8
	MessageBox "Transfer the lesser soul from the grand soulgem to the lesser soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a lesser soulgem filled with a lesser soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty2Lesser
	return
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 6
	elseif ( button == 1 )
		if ( combo >= 1 ) && ( combo <= 3 ) || ( combo == 5 ) ; AXXX, AXX, AX, A
			set stage to 2
		elseif ( combo == 4 ) || ( combo == 6 ) ; CXX, CX, C
			set stage to 3
		elseif ( combo == 7 ) ; DX, D
			set stage to 4
		elseif ( combo == 8 ) ; E
			set stage to 5
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) || ( combo == 2 ) ; XCXX, XCX, XC
			set stage to 3
		elseif ( combo == 3 ) || ( combo == 4 ) ; XDX, XD
			set stage to 4
		elseif ( combo == 5 ) || ( combo == 6 ) || ( combo == 7 ) ; XE
			set stage to 5
		endif
	elseif ( button == 3 )
		if ( combo == 1 ) ; XXDX, XXD
			set stage to 4
		elseif ( combo >= 2 ) && ( combo <= 4 ) ; XXE
			set stage to 5
		endif
	elseif ( button == 4 )
		;( combo == 1 ) XXXE single case
		set stage to 5
	endif
	if ( stage != 0 ) && ( stage != 1 )
		set combo to 0
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem3Common2LesserSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 22
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem4Greater2LesserSoul ) && ( Player.GetItemCount Gold001 >= 15 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 15
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGem5Grand2LesserSoul ) && ( Player.GetItemCount Gold001 >= 90 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 90
		iter.RemoveMeIR
	elseif ( stage == 5 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 2 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "A lesser soul has been transferred from the Azura's Star to the empty lesser soulgem" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 3 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty3Common
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem3Common2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty3Common
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A lesser soul has been transferred from the common soulgem to the empty lesser one" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 4 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem4Greater2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A lesser soul has been transferred from the greater soulgem to the empty lesser one" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 4 ) && ( ActionDone == 0 )
	Message "That action requires a 15 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 6
elseif ( stage == 5 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 2
		else
			let iter := CreateTempRef SoulGem5Grand2LesserSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A lesser soul has been transferred from the grand soulgem to the empty lesser one" 4
;	playsound UIItemEnchant
	set stage to 6
elseif ( stage == 5 ) && ( ActionDone == 0 )
	Message "That action requires a 90 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 6
elseif ( stage == 6 )
	set LesserEmpty to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect LesserEmpty
endif

if ( ActionDone == 1 )
	set ActionDone to 0
	let OtherGuy := 0
	ForEach iter <- Player
		if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount == 1 ) && ( ActionDone == 0 )
			iter.SetCurrentSoulLevel 2
			set ActionDone to 1
		elseif ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 ) && ( ActionDone == 0 )
			set combo to 1
		endif
	loop
	if ( ActionDone == 0 ) && ( combo == 1 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty2Lesser ) && ( iter.GetCurrentSoulLevel == 0 ) && ( ActionDone == 0 )
				if ( iter.GetOwner != 0 )
					let OtherGuy := iter.GetOwner
				endif
				set ActionDone to 1
				set LesserEmpty to ( iter.GetRefCount - 1 )
				iter.RemoveMeIR
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount LesserEmpty
		iter.SetCurrentSoulLevel 0
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
		let iter := CreateTempRef SoulGemEmpty2Lesser
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 2
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	set ActionDone to 0
endif

End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set CommonLesser to 0
set GreaterLesser to 0
set GrandLesser to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem3Common2LesserSoul )
			let CommonLesser := CommonLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem4Greater2LesserSoul )
			let GreaterLesser := GreaterLesser + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand2LesserSoul )
			let GrandLesser := GrandLesser + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem3Common2LesserSoul ) == 1 ) && ( CommonLesser == 0 )
	Player.RemoveItemNS SoulGem3Common2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem4Greater2LesserSoul ) == 1 ) && ( GreaterLesser == 0 )
	Player.RemoveItemNS SoulGem4Greater2LesserSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand2LesserSoul ) == 1 ) && ( GrandLesser == 0 )
	Player.RemoveItemNS SoulGem5Grand2LesserSoul 1
endif

let iter := 0
End

 


SpellID: StandardTransferToSoulGemEmpty3Common
SpellName: Relocation
SpellLevel: Journeyman
SpellCost: 164
ScriptEffectName: Common soul transferring

scn zzSMTransferSoulGemCommonSoul

Short button
Short combo ; also as a possibility if there was a stack of the empty soulgems
ref iter
Short CommonEmpty ;also as an active effect index for the self-dispel
Short AzuraCommon
Short GreaterCommon
Short GrandCommon
Short stage
short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn
ref OtherGuy
short ActionDone

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 )
		let CommonEmpty := CommonEmpty + iter.GetRefCount
	elseif ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 3 )
		set AzuraCommon to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 )
		let GreaterCommon := GreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 )
		let GrandCommon := GrandCommon + iter.GetRefCount
	endif
loop

if ( CommonEmpty == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty common soulgem" 4
	set stage to -1
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; ADE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the common soul from to the common soulgem", "Cancel", "Azura's Star", "Greater", "Grand"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; AD
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the common soul from to the common soulgem", "Cancel", "Azura's Star", "Greater"
elseif ( AzuraCommon > 0 ) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; AE
	set combo to 2
	MessageBox "Choose the soulgem you want to transfer the common soul from to the common soulgem", "Cancel", "Azura's Star", "Grand"
elseif (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) && (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; DE
	set combo to 3
	MessageBox "Choose the soulgem you want to transfer the common soul from to the common soulgem", "Cancel", "Greater", "Grand"
elseif ( AzuraCommon > 0 ) ; A
	set combo to 1
	MessageBox "Transfer the common soul from the Azura's Star to the common soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem4Greater3CommonSoul > 0 ) || ( GreaterCommon > 0 )) ; D
	set combo to 3
	MessageBox "Transfer the common soul from the greater soulgem to the common soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand3CommonSoul > 0 ) || ( GrandCommon > 0 )) ; E
	set combo to 4
	MessageBox "Transfer the common soul from the grand soulgem to the common soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a common soulgem filled with a common soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty3Common
	return
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 5
	elseif ( button == 1 )
		if ( combo == 1 ) || ( combo == 2 ) ; AXX, AX, A
			set stage to 2
		elseif ( combo == 3 ) ; DX, D
			set stage to 3
		elseif ( combo == 4 ) ; E
			set stage to 4
		endif
	elseif ( button == 2 )
		if ( combo == 1 ) ; XDX, XD
			set stage to 3
		elseif ( combo == 2 ) || ( combo == 3 ) ; XE
			set stage to 4
		endif
	elseif ( button == 3 )
		;( combo == 1 ) XXE single case
		set stage to 4
	endif
	if ( stage != 0 ) && ( stage != 1 )
		set combo to 0
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem4Greater3CommonSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 37
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 3 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGem5Grand3CommonSoul ) && ( Player.GetItemCount Gold001 >= 38 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.RemoveItemNS Gold001 38
		iter.RemoveMeIR
	elseif ( stage == 4 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 3 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "A common soul has been transferred from the Azura's Star to the empty common soulgem" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 3 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty4Greater
			iter.SetCurrentSoulLevel 3
		else
			let iter := CreateTempRef SoulGem4Greater3CommonSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty4Greater
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A common soul has been transferred from the greater soulgem to the empty common one" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 4 ) && ( ActionDone == 1 )
	if ( SoulGemsQuantityToReturn > 0 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 3
		else
			let iter := CreateTempRef SoulGem5Grand3CommonSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A common soul has been transferred from the grand soulgem to the empty common one" 4
;	playsound UIItemEnchant
	set stage to 5
elseif ( stage == 4 ) && ( ActionDone == 0 )
	Message "That action requires a 38 golds compensation" 4
;	playsound SPLDestructionFail
	set stage to 5
elseif ( stage == 5 )
	set CommonEmpty to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect CommonEmpty
endif

if ( ActionDone == 1 )
	set ActionDone to 0
	let OtherGuy := 0
	ForEach iter <- Player
		if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount == 1 ) && ( ActionDone == 0 )
			iter.SetCurrentSoulLevel 3
			set ActionDone to 1
		elseif ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 ) && ( ActionDone == 0 )
			set combo to 1
		endif
	loop
	if ( ActionDone == 0 ) && ( combo == 1 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty3Common ) && ( iter.GetCurrentSoulLevel == 0 ) && ( ActionDone == 0 )
				if ( iter.GetOwner != 0 )
					let OtherGuy := iter.GetOwner
				endif
				set ActionDone to 1
				set CommonEmpty to ( iter.GetRefCount - 1 )
				iter.RemoveMeIR
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount CommonEmpty
		iter.SetCurrentSoulLevel 0
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
		let iter := CreateTempRef SoulGemEmpty3Common
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 3
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	set ActionDone to 0
endif

End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set GreaterCommon to 0
set GrandCommon to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem4Greater3CommonSoul )
			let GreaterCommon := GreaterCommon + iter.GetRefCount
	elseif ( iter.GetBaseObject == SoulGem5Grand3CommonSoul )
			let GrandCommon := GrandCommon + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem4Greater3CommonSoul ) == 1 ) && ( GreaterCommon == 0 )
	Player.RemoveItemNS SoulGem4Greater3CommonSoul 1
endif
if (( Player.GetItemCount SoulGem5Grand3CommonSoul ) == 1 ) && ( GrandCommon == 0 )
	Player.RemoveItemNS SoulGem5Grand3CommonSoul 1
endif

let iter := 0
End

 


SpellID: StandardTransferToSoulGemEmpty4Greater
SpellName: Translocation
SpellLevel: Expert
SpellCost: 406
ScriptEffectName: Greater soul transferring

scn zzSMTransferSoulGemGreaterSoul

Short button
Short combo ; also as a possibility if there was a stack of the empty soulgems
ref iter
Short GreaterEmpty ;also as an active effect index for the self-dispel
Short AzuraGreater
Short GrandGreater
Short stage
short SoulGemsQuantityToReturn
short SoulGemsTypeToReturn
ref OtherGuy
short ActionDone

Begin ScriptEffectStart
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 )
		let GreaterEmpty := GreaterEmpty + iter.GetRefCount
	elseif ( iter.GetBaseObject == AzurasStar ) && ( iter.GetCurrentSoulLevel == 4 )
		set AzuraGreater to 1
	elseif ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 )
		let GrandGreater := GrandGreater + iter.GetRefCount
	endif
loop

if ( GreaterEmpty == 0 )
;	playsound SPLDestructionFail
	Message "You have no an empty greater soulgem" 4
	set stage to -1
elseif ( AzuraGreater > 0 ) && (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; AE
	set combo to 1
	MessageBox "Choose the soulgem you want to transfer the greater soul from to the greater soulgem", "Cancel", "Azura's Star", "Grand"
elseif ( AzuraGreater > 0 ) ; A
	set combo to 1
	MessageBox "Transfer the greater soul from the Azura's Star to the greater soulgem?", "Cancel", "Yes"
elseif (( Player.GetItemCount SoulGem5Grand4GreaterSoul > 0 ) || ( GrandGreater > 0 )) ; E
	set combo to 2
	MessageBox "Transfer the greater soul from the grand soulgem to the greater soulgem?", "Cancel", "Yes"
else
;	playsound SPLDestructionFail
	Message "You do not have any more powerful than a greater soulgem filled with a greater soul" 4
	set stage to -1
endif
if ( stage != -1 )
	set stage to 1
else
	let iter := 0
	Player.Dispel StandardTransferToSoulGemEmpty4Greater
	return
endif
End

Begin ScriptEffectUpdate
if ( stage == 1 )
	Set button to GetButtonPressed
	if ( button == 0 )
;		playsound SPLDestructionFail
		set stage to 4
	elseif ( button == 1 )
		if ( combo == 1 ) ; AX, A
			set stage to 2
		elseif ( combo == 2 ) ; E
			set stage to 3
		endif
	elseif ( button == 2 )
		;( combo == 1 ) XE single case
		set stage to 3
	endif
	if ( stage != 0 ) && ( stage != 1 )
		set combo to 0
	endif
endif
ForEach iter <- Player
	if ( stage == 2 ) && ( iter.GetBaseObject == AzurasStar ) && ( ActionDone == 0 )
		iter.SetCurrentSoulLevel 0
		set ActionDone to 1
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set ActionDone to 1
		Player.AddItemNS Gold001 112
		iter.RemoveMeIR
	elseif ( stage == 3 ) && ( iter.GetBaseObject == SoulGemEmpty5Grand ) && ( iter.GetCurrentSoulLevel == 4 ) && ( ActionDone == 0 )
		if ( iter.GetOwner != 0 )
			let OtherGuy := iter.GetOwner
		endif
		set ActionDone to 1
		set SoulGemsQuantityToReturn to ( iter.GetRefCount - 1 )
		set SoulGemsTypeToReturn to 1
		iter.RemoveMeIR
	endif
loop
if ( stage == 2 )
	Message "A greater soul has been transferred from the Azura's Star to the empty greater soulgem" 4
;	playsound UIItemEnchant
	set stage to 4
elseif ( stage == 3 )
	if ( SoulGemsQuantityToReturn > 0 ); && ( ActionDone == 1 )
		if ( SoulGemsTypeToReturn == 1 )
			let iter := CreateTempRef SoulGemEmpty5Grand
			iter.SetCurrentSoulLevel 4
		else
			let iter := CreateTempRef SoulGem5Grand4GreaterSoul
		endif
		iter.SetRefCount SoulGemsQuantityToReturn
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	let iter := CreateTempRef SoulGemEmpty5Grand
	iter.SetCurrentSoulLevel 0
	iter.SetRefCount 1
	if ( OtherGuy != 0 )
		iter.SetOwner OtherGuy
	endif
	iter.CopyIR Player
	Message "A greater soul has been transferred from the grand soulgem to the empty greater one" 4
;	playsound UIItemEnchant
	set stage to 4
elseif ( stage == 4 )
	set GreaterEmpty to GetScriptActiveEffectIndex
	Player.DispelNthActiveEffect GreaterEmpty
endif

if ( ActionDone == 1 )
	set ActionDone to 0
	let OtherGuy := 0
	ForEach iter <- Player
		if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount == 1 ) && ( ActionDone == 0 )
			iter.SetCurrentSoulLevel 4
			set ActionDone to 1
		elseif ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 ) && ( iter.GetRefCount > 1 ) && ( ActionDone == 0 )
			set combo to 1
		endif
	loop
	if ( ActionDone == 0 ) && ( combo == 1 )
		ForEach iter <- Player
			if ( iter.GetBaseObject == SoulGemEmpty4Greater ) && ( iter.GetCurrentSoulLevel == 0 ) && ( ActionDone == 0 )
				if ( iter.GetOwner != 0 )
					let OtherGuy := iter.GetOwner
				endif
				set ActionDone to 1
				set GreaterEmpty to ( iter.GetRefCount - 1 )
				iter.RemoveMeIR
			endif
		loop
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount GreaterEmpty
		iter.SetCurrentSoulLevel 0
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
		let iter := CreateTempRef SoulGemEmpty4Greater
		iter.SetRefCount 1
		iter.SetCurrentSoulLevel 4
		if ( OtherGuy != 0 )
			iter.SetOwner OtherGuy
		endif
		iter.CopyIR Player
	endif
	set ActionDone to 0
endif

End

Begin ScriptEffectFinish
; Clean the soulgem existence after the bugged RemoveMeIR in cases when that soulgem type removed
; completely using that function.
set GrandGreater to 0
ForEach iter <- Player
	if ( iter.GetBaseObject == SoulGem5Grand4GreaterSoul )
			let GrandGreater := GrandGreater + iter.GetRefCount
	endif
loop
if (( Player.GetItemCount SoulGem5Grand4GreaterSoul ) == 1 ) && ( GrandGreater == 0 )
	Player.RemoveItemNS SoulGem5Grand4GreaterSoul 1
endif

let iter := 0
End

 

 

Edited by Stealth21
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...