Jump to content

[LE] Add item from a list of notes and not get them more than once issue.


Recommended Posts

So I am not sure if there is a way to do this but maybe someone knows.

 

I have a chest that spawn 5 notes. Now I have about 13 notes to choose from and I want the 5 notes to be chosen from that list. I know how to add an item from a formlist/leveledlist/array etc but the problem I am running into is that it might give me the same item multiple time.

 

Is there a way to ask for 5 items from a list and make it so it will not give me a second copy of the item, a bit like making the notes unique? I really want it to be random

Edited by littleork
Link to comment
Share on other sites

Use a FormList, and RemoveAddedForm, perhaps?

 

Have an empty Form List, and on start-up, have a Quest populate it with all of the possible notes, then grab 1 note from the list, and add it to the chest. Not 100% sure on the Script, but something like :

 

 

Function SelectANote()
MyFormList.AddForm(Note001)
;Do for all 13 Notes
 
NoteCount = 0
While ( NoteCount < 5 )
   FormListLength = MyFormList.GetSize()
   FormListLength = ( FormListLength - 1 )
   WhichNote = Utility.RandomInt(0, FormListLength)
   MyNote = MyFormList.GetAt(WhichNote) as Book
   MyChest.AddItem(MyNote, 1, 1)
   MyFormList.RemoveAddedForm(MyNote)
   NoteCount = ( NoteCount + 1 )
EndWhile
EndFunction

 

Depending how you want it to do, you could have it fire on the Chest being Activated, so it would populate it the first time it's opened.

Link to comment
Share on other sites

Use a FormList, and RemoveAddedForm, perhaps?

 

Have an empty Form List, and on start-up, have a Quest populate it with all of the possible notes, then grab 1 note from the list, and add it to the chest. Not 100% sure on the Script, but something like :

Function SelectANote()
MyFormList.AddForm(Note001)
;Do for all 13 Notes
 
NoteCount = 0
While ( NoteCount < 5 )
   FormListLength = MyFormList.GetSize()
   FormListLength = ( FormListLength - 1 )
   WhichNote = Utility.RandomInt(0, FormListLength)
   MyNote = MyFormList.GetAt(WhichNote) as Book
   MyChest.AddItem(MyNote, 1, 1)
   MyFormList.RemoveAddedForm(MyNote)
   NoteCount = ( NoteCount + 1 )
EndWhile
EndFunction

Depending how you want it to do, you could have it fire on the Chest being Activated, so it would populate it the first time it's opened.

Hmmm I will try that! Thanks.

Link to comment
Share on other sites

Maybe the following script is what you want to have? It's a bit different to the approach of CDM_

 

FiveNotesAddToChestScript

 

Scriptname FiveNotesAddToChestScript extends ObjectReference
{written by ReDragon 2017} ; we assume this script is attached to the chest

; https://forums.nexusmods.com/index.php?/topic/5728422-add-item-from-a-list-of-notes-and-not-get-them-more-than-once-issue/
; littleork

  FormList PROPERTY myList auto     ; the list of 13 notes
  Bool bBusy                        ; prevent issues by calling internal events at the same time


; -- EVENTs -- 3

EVENT OnInit()                                ; chest is placed first time in new game or existing savegame
    RegisterForSingleUpdate(10.0)             ; wait 10 seconds, if required adjust 10.0 by a lower number (5.0 for example)
ENDEVENT

EVENT OnReset()                               ; chest will be reseted by game engine
IF ( bBusy )
ELSE
    myF_AddNotes()
ENDIF
ENDEVENT

EVENT OnUpdate()
    myF_AddNotes()
ENDEVENT


; -- FUNCTION --

FUNCTION myF_AddNotes()
;----------------------
IF self.GetBaseObject()
ELSE
    RETURN    ; - STOP -    script instance is invalid
ENDIF
;---------------------
    bBusy = TRUE            ; *T*

    bool[] a = new Bool[13]                      ; bool array of 13 entries, a[0]..a[12]
    int n = myList.GetSize()

IF (n != a.Length)
    Debug.Trace(self+" Error: myF_AddNotes() - formlist has " +n+ "entries != " +a.Length)
    bBusy = False            ; ***
    RETURN    ; - STOP -    formlist size is not 13
ENDIF
;---------------------
    n = n - 1                                    ; formlist of 13 entries, myList.GetAt(0) .. myList.GetAt(12)

int i = 4
    WHILE (i > 0)
        int r = Utility.RandomInt(0, n)          ; get a random number of 0..12
        IF ( a[r] )
            ; this formlist item is already selected
        ELSE
            a[r] = TRUE
            i = i - 1                            ; decrease our loop counter from 4 (3,2,1) downto 0
            form fm = myList.GetAt(r)
            IF (fm as Book)
                   self.AddItem(fm, 1, 1)        ; add the selected note, if formlist entry is of type book
               ENDIF
        ENDIF
    ENDWHILE

    bBusy = False            ; ***
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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