IsNearPlayer - ObjectReference

From the CreationKit Wiki
Jump to navigation Jump to search

Member of: ObjectReference Script

A function that checks to see if this reference can be safely enabled/disabled/moved with confidence that the player won't see us messing around with the world.

Syntax[edit | edit source]

bool Function IsNearPlayer()
	Actor player = Game.GetPlayer()
	Cell targetCell = self.GetParentCell()
	Cell playerCell = player.GetParentCell()
	if (targetCell != playerCell)
		if (targetCell && targetCell.IsInterior() || playerCell && playerCell.IsInterior())
			return false
		else
			if (player.GetDistance(self) > 3000)
				return false
			else
				return true
			endif
		endif
	else
		return true
	endif
endFunction

Parameters[edit | edit source]

None.

Return Value[edit | edit source]

Whether this object is too close to the player to safely unload. Will err on the side of caution -- might return true in cases where you could monkey about with the object without the player seeing it, but will only return false if it is definitely safe to monkey with the object because the player will not see it.

Examples[edit | edit source]

; Disable the box, but only if the player isn't nearby
if (!Box.IsNearPlayer())
  Box.Disable()
endif

See Also[edit | edit source]