greyday01 Posted January 4, 2023 Share Posted January 4, 2023 If a container is spawned by PlaceAtMe how can you get rid of it? An on Activate script attached to the container could be used, maybe with a RegisterForSingleUpdate as a timer. Is there any other ways to use a scripted event to disable and then delete the reference to get completely rid of it, preferably while not in sight of the player? Link to comment Share on other sites More sharing options...
maxarturo Posted January 4, 2023 Share Posted January 4, 2023 (edited) There are different ways you can do this, but all depends on what you are trying to accomplish (and how). I'll add 2 ways to achieve it: 1) With 'RegisterForUpdate()'. - The script lives inside the 'Base' container. - We use a 15 sec update loop to not make it unnecessarily system pull heavy. Actor Player AUTO STATE WaitingPlayer EVENT OnActivate(ObjectReference akActionRef) Player = Game.GetPlayer() If ( akActionRef == Player ) RegisterForUpdate(15.0) GoToState("Inactive") EndIf ENDEVENT ENDSTATE STATE Inactive ENDSTATE EVENT OnUpdate() If ( Self.GetParentCell() != Player.GetParentCell() ) UnregisterForUpdate() Self.Disable() Self.Delete() EndIf ENDEVENT 2) With 'OnCellDetach()' - The script lives inside the 'Base' container. - This is a simpler version and way less system pull heavy, but the events OnCellDetach() - OnCellAttach() - OnAttachedToCell() - OnDetachedFromCell() will not fire under certain conditions. AUTO STATE WaitingPlayer EVENT OnActivate(ObjectReference akActionRef) If ( akActionRef == Game.GetPlayer() ) GoToState("Removing") EndIf ENDEVENT ENDSTATE STATE Removing EVENT OnCellDetach() Self.DIsable() Self.Delete() ENDEVENT ENDSTATE Edited January 4, 2023 by maxarturo Link to comment Share on other sites More sharing options...
greyday01 Posted January 4, 2023 Author Share Posted January 4, 2023 Thank you. I'm not quite sure what "Detached" means. Does it mean the container is detached from the parent cell by being moved to a different cell, or does it mean the player is detached from the parent cell by leaving it? Or does it mean the player moved far enough from the parent cell that that cell is no longer loaded so everything in that cell is detached? What is being detached from what? Papyrus terms don't sometimes match what the English word means and it gets confusing. Link to comment Share on other sites More sharing options...
maxarturo Posted January 4, 2023 Share Posted January 4, 2023 It's logical to be confused, in general the wiki is not much of a help regarding in depth explanations and possible issues with Papyrus flaws. 'OnCellDetach()' When the player enters a cell (any cell), all items in there are 'Loaded'. - Now, when the player leaves that cell all objects / actors can run an 'OnCellDetach()' event, because the player does no longer exists in that cell with the object carring the script. - Now, this function can also run on the object / actor (and if the object has in it the script function), once the object moves from that cell to another from where the player and the object / actor commonly shared (they lived in that same cell). I hope I'm clear enough and I'm not confusing any further. Link to comment Share on other sites More sharing options...
greyday01 Posted January 4, 2023 Author Share Posted January 4, 2023 Yes. You are very helpful as always. I think OnCellDetach might work though I can't really control how close to a cell border the thing is spawned at and that might be a problem. Maybe go for a timer instead because the player probably won't be standing around watching it. I really wish that there was an easy way to get the ref ID for things spawned. Link to comment Share on other sites More sharing options...
maxarturo Posted January 5, 2023 Share Posted January 5, 2023 (edited) "I really wish that there was an easy way to get the ref ID for things spawned." You actually can: EVENT SomeEvent.... ObjectReference SpawnContainerREF = Self.PlaceAtMe(MyContainer, 1) SOME FUNCTIONS..... SpawnContainerREF.Disable() SpawnContainerREF.Delete() ENDEVENT EVENT SomeEvent.... Actor SpawnActorREF = Self.PlaceActorAtMe(MyActor) SOME FUNCTIONS..... SpawnActorREF.Kill() SpawnActorREF.SetCriticalStage(3) SpawnActorREF.SetCriticalStage(4) ENDEVENT * Stores the reference's ID for later use* I Use 'Self' assuming that the script is living inside the object / whatever is using the function to spawn the reference. Edited January 6, 2023 by maxarturo Link to comment Share on other sites More sharing options...
greyday01 Posted January 5, 2023 Author Share Posted January 5, 2023 That is really great. It should be added as an example in the creationkit.com scripting reference of PlaceAtMe. I'm sure others have needed that same fragment of script. Link to comment Share on other sites More sharing options...
maxarturo Posted January 6, 2023 Share Posted January 6, 2023 This has nothing to do with Papyrus, it's just programming stuff that you learn by studying. Link to comment Share on other sites More sharing options...
Recommended Posts