Jump to content

Deleting a placed Ref when player leaves a cell?


Hoamaii

Recommended Posts

Hi guys,

 

What would be the surest way to delete a reference created with "PlaceAtMe" once the player has left the cell where this object was created?

 

Use "OnCellDetach"? "OnUnload"? Both (to be safe)? According to the CKwiki, both have serious liability limitations...

Link to comment
Share on other sites

You could create an initially disabled trigger outside of the cell that disables the reference I think. Not 100% as I have not tried it myself. In the cell where the reference is spawned you could create another trigger that enables the outside trigger
Link to comment
Share on other sites

Yeah, thanks, that'd work - though actually if it was limited to cell boundaries, "OnCellDetach" would work fine.

 

The thing is - I should have mentioned it, sorry - that I'm trying to find a reliable way to do that not just in a few cells, but for all of Skryim world.

Link to comment
Share on other sites

Thanks man, my experience though is that "DeleteWhenAble" can cause a script to stall and following functions to be seriously delayed. "Delete()" works fine for the purpose I have. My main issue is to find a workaround the limitations of "OnUnload()" (like if you make a savegame before the 3D has had time to unload and that save is later loaded - then that 3D never unloads because it never was "loaded" by that save game) or "OnCellDeatch()" which can be triggered by crossing exterior cell boundaries even though the object is still in sight of the player -- maybe I should try something like "OnLostLOS"...

Link to comment
Share on other sites

Couple of ways to work around it maybe.

Maybe instead of OnUnload() do OnCellLoad() and check the TempRef cell against the player cell eg:

Event OnCellLoad()
    If TempRef
        If (!TempRef.Is3DLoaded()) && (TempRef.GetParentCell() != Game.GetPlayer().GetParentCell())
            TempRef.Delete()
            TempRef = none
        EndIf
    EndIf
EndEvent

If you need to cache those TempRef for deletion due to there may be more then one delete needed:

ObjectReference[] Property TempRef Auto ;Set your array property to the size you think suites.

Function YourFunction()
    Int i = TempRef.Find(none)
    If i >= 0
        TempRef[i] = Game.GetPlayer().PlaceAtMe(SomeForm)
    Else
        Debug.Notification("Hit TempRef Cache Limit")
    EndIf
EndFunction

Event OnCellLoad()
    Int i = 0
    While i < TempRef.Length
        If TempRef[i]
            If (!TempRef[i].Is3DLoaded()) && (TempRef[i].GetParentCell() != Game.GetPlayer().GetParentCell())
                TempRef[i].Delete()
                TempRef[i] = none
            EndIf
        EndIf
        i += 1
    EndWhile
EndEvent
Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

  • Recently Browsing   0 members

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