Difference between revisions of "Detect Player Cell Change (Without Polling)"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Egocarib
(added category)
imported>XJDHDR
(Made some improvements based on my testing and suggestions on talk page)
 
Line 1: Line 1:
A method to track every cell change the player makes, including cell changes in open wilderness cells.
A method to track every cell change the player makes, including cell changes in open wilderness cells.


*Make a new object in the CK. I made a MiscObject based on BasicFork, though I am thinking something static (without any havok) would be even better. Make sure your object is small and give it an invisible texture (Edit the Model path and change all entries to NullTextureSet). Uncheck the playable flag.
*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.
*Place your object 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
*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:
*Attach this script to your new magic effect, and makes sure to fill both properties:
Line 10: Line 9:


     Actor property playerRef auto
     Actor property playerRef auto
    FunctionScript property FunctionQuest auto
     ObjectReference property invisibleObject auto
     ObjectReference property invisibleObject auto


     Event OnEffectStart(Actor akTarget, Actor akCaster)
     Event OnEffectStart(Actor akTarget, Actor akCaster)
         debug.notification("player changed cells")
         debug.notification("player changed cells")
         Utility.Wait(0.1) ;maybe not necessary
         Utility.Wait(0.1) ; Required.
         invisibleObject.MoveTo(playerRef)
         invisibleObject.MoveTo(playerRef)
        FunctionQuest.FunctionContainingCodeWeWantToRun
     EndEvent
     EndEvent
</source>
</source>
Line 25: Line 26:
*Your object should be the reference chosen in the condition.
*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)
*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:Detect_Player_Cell_Change_(Without_Polling)|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):
<source lang="papyrus">
    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
</source>





Latest revision as of 15:44, 4 January 2019

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:

CellTracker.jpg

  • 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.