Detect Player Cell Change (Without Polling)
Jump to navigation
Jump to search
A method to track every cell change the player makes, including cell changes in open wilderness cells.
- Place a copy of the WorldObjects -- Static -- XMarker somewhere in the world. Doesn't matter where, it just needs to have a specific reference that we can access later when we set up our condition.
- Set up a new Magic Effect in the CK: Script -- Constant Effect -- Self -- Hide in UI
- Attach this script to your new magic effect, and makes sure to fill both properties:
Scriptname TrackInSameCell extends ActiveMagicEffect
{ability that will be activated when player is not in the same cell as invisibleObject}
Actor property playerRef auto
FunctionScript property FunctionQuest auto
ObjectReference property invisibleObject auto
Event OnEffectStart(Actor akTarget, Actor akCaster)
debug.notification("player changed cells")
Utility.Wait(0.1) ; Required.
invisibleObject.MoveTo(playerRef)
FunctionQuest.FunctionContainingCodeWeWantToRun
EndEvent
- Now make a new spell: Ability -- Constant Effect -- Self
- Add your scripted magic effect as an entry to the spell.
- Now add a condition to your spell entry, it should look like this:
- Your object should be the reference chosen in the condition.
- Add your new ability to the player, probably the easiest way is through a reference alias (that's what I did)
- Finally, we need a fallback method that will work if the player enters/leaves a city or crosses multiple cell boundaries in quick succession (see talk page).
- You can achieve this by attaching the following script to the XMarker reference you dropped somewhere in the world (not the XMarker form under WorldObjects -- Static):
Scriptname XMarkerReferenceScript extends ObjectReference
FunctionScript property FunctionQuest auto
Event OnCellDetach()
debug.notification("XMarker cell detached")
Utility.Wait(0.1) ;maybe not necessary
MoveTo(playerRef)
FunctionQuest.FunctionContainingCodeWeWantToRun
EndEvent
Now head in game and test it out, you'll notice that you see the debug every time the player changes cells anywhere.
The nice thing is this is very resource friendly, and it doesn't require any sort of polling.