Jump to content

[LE] Delete objects in quest script


inomoz

Recommended Posts

Skyrim SE, Newbie in mod making, quest script:


Hi, I'm trying find way to temprorary place objects (alchemy items, like cheese), then wait some time, then delete them.


This code works:



ObjectReference cheese1 = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x00064b33))
....
ObjectReference cheese3 = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x00064b33))

utility.wait(5)

cheese1.Delete()
...
cheese3.Delete()

It's laggy and not optimal..



I tryed use some like this



ObjectReference cheeses = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x00064b33), 50)
utility.wait(5)
;cheeses.Disable()
cheeses.Delete()

Not working, objects not deleting, as I undesrtand this objects become not unic and I can't delete them?



I tried use arrays - no success...


Edited by inomoz
Link to comment
Share on other sites

You cannot store a stack of objects within a single variable. If you are wanting to spawn 50 of an object and then delete them, you'll need to do a different approach.

 

Here is an untested array approach.

 

 

;property and variable declarations
ObjectReference[] CheeseArray

;events and functions
Event OnInit()
  CheeseArray = new ObjectReference[50]
EndEvent

;some event
SpawnAndStoreInArray(Game.GetFormFromFile(0x00064b33,"Skyrim.esm"),50)
Utility.wait(5)
DeleteAndRemoveFromArray(50)
;end some event

Function SpawnAndStoreInArray(Form MyObj, Int Total)
  Int Index = 0
  While Index < Total
    CheeseArray[Index] = Game.GetPlayer().PlaceAtMe(MyObj)
    Index += 1
  EndWhile
EndFunction

Function DeleteAndRemoveFromArray(Int Total)
  Int Index = 0
  While Index < Total
    ObjectReference CheeseObj = CheeseArray[Index]
    CheeseObj.Delete()
    CheeseArray[Index] = NONE
    Index += 1
  EndWhile
EndFunction

Creates the array in the OnInit event

Retrieves the desired object from the game and sends it along with desired amount to the SpawnAndStoreInArray function

Assigns a new instance of the object to each index of the array.

waits some time

Sends the desired amount to the DeleteAndRemoveFromArrray function

Retrieves the desired object reference from the array and deletes it

Finally, gives the current entry an empty value

 

 

EDIT: See later post for reason.

Edited by IsharaMeradin
Link to comment
Share on other sites

Realized that I had a mistake in there right before going to bed but I had already turned the computer off. Decided to wait till morning to correct it. Seems you've already resolved it as that is exactly what I needed to correct.

 

Editing the above post anyway...

Link to comment
Share on other sites

  • Recently Browsing   0 members

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