GetSummoner

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

A User Function for use with Oblivion Script Extender

Syntax:

(summoner:ref) reference.Call GetSummoner

Returns a reference to whoever summoned the calling actor.

Notes[edit | edit source]

  • This function must be called on a reference (Ref.call <function>)
  • If the summoner is not in the same cell as the summon then it will return 0.
    • Always check to see if a valid reference was found by the function.
    • The very last piece of code has something that scans the player's last cell for the summoner. It should work for 95% of the time when a summon is in a different cell than its summoner.
  • When called on a summon that is in the process of disappearing it will return 0 since the summoning has ended. Use GetDead to determine if a summon is still summoned.


Examples:[edit | edit source]

Getting the actor who summoned the calling a reference (in this case a summon that is stored in the someSummonRef variable).

Let rSummoner := someSummonRef.Call GetSummoner
If rSummoner
	;A valid summoner was found
Endif

Code[edit | edit source]

ScriptName GetSummoner
ref rSummon
array_var arSummons
ref rActor
ref rFollower
long iFollower

Begin Function {}
	let rSummon := GetSelf
	let arSummons := player.GetFollowers
	let iFollower := player.GetNumFollowers
	While iFollower > 0
		let iFollower -= 1
		let rFollower := player.GetNthFollower iFollower
		ar_Erase arSummons (ar_Find rFollower arSummons )
	Loop
	if eval (ar_Find rSummon arSummons) != -99999
		SetFunctionValue player
		let arSummons := ar_Null
	else
		let rActor := GetFirstRef 69 2
		While rActor
			if rActor.GetDead == 0 && rActor.GetDisabled == 0
				let arSummons := rActor.GetFollowers
				let iFollower := rActor.GetNumFollowers
				While iFollower > 0
					let iFollower -= 1
					let rFollower := rActor.GetNthFollower iFollower
					ar_Erase arSummons (ar_Find rFollower arSummons )
				Loop
				if eval (ar_Find rSummon arSummons) != -99999
					SetFunctionValue rActor
				endif
			endif
			let rActor := GetNextRef
		Loop
	endif
	let arSummons := ar_Null
End 

Alternative code for use with GetSummons (to avoid duplicate code).

ScriptName GetSummoner
ref rSummon
array_var arSummons
ref rActor

Begin Function {}
	let rSummon := GetSelf

	let arSummons := player.Call GetSummons
	if eval (ar_Find rSummon arSummons) != -99999
		SetFunctionValue player
		let arSummons := ar_Null
	else
		let rActor := GetFirstRef 69 2
		While rActor
			if rActor.GetDead == 0 && rActor.GetDisabled == 0
				let arSummons := rActor.Call GetSummons
				if eval (ar_Find rSummon arSummons) != -99999
					SetFunctionValue rActor
				endif
			endif
			let rActor := GetNextRef
		Loop
	endif
	let arSummons := ar_Null
End 

Code that also checks the player's last visited cell when it was not found in the current cell (also uses GetSummons).

ScriptName GetSummoner
ref rSummon
array_var arSummons
ref rActor
ref rLast

Begin Function {}
	let rSummon := GetSelf

	let arSummons := player.Call GetSummons
	if eval (ar_Find rSummon arSummons) != -99999
		SetFunctionValue player
		let arSummons := ar_Null
	else
		let rActor := GetFirstRef 69 2
		While rActor
			if rActor.GetDead == 0 && rActor.GetDisabled == 0
				let arSummons := rActor.Call GetSummons
				if eval (ar_Find rSummon arSummons) != -99999
					SetFunctionValue rActor
				endif
			endif
			let rActor := GetNextRef
		Loop
		if rActor == 0
			let rLast := GetPlayersLastActivatedLoadDoor 
			if rLast 
				let rLast := rLast.GetParentCell
				if rLast
					let rActor := GetFirstRefInCell rLast 69 2
					While rActor
						if rActor.GetDead == 0 && rActor.GetDisabled == 0
							let arSummons := rActor.Call GetSummons
							if eval (ar_Find rSummon arSummons) != -99999
								SetFunctionValue rActor
								Break
							endif
						endif
						let rActor := GetNextRef
					Loop
				endif
			endif
		endif
	endif
	let arSummons := ar_Null
End 

See Also[edit | edit source]