Jump to content

[HELP] Array script help


saintgrimm92

Recommended Posts

I did some reading on the CK wiki about arrays but I don't really understand them yet, and the final boss in a mod I'm working on needs to use them (I think?).

 

I'm using a script on the boss that registers for a (single) update when the boss enters combat, and every 5 seconds it checks the boss's HP.

 

When the boss is under a certain HP, I want the updates to start casting a spell and this is where the arrays come in and I can't figure out what I need to do.

I need the boss to cast the spell at random X markers (the random part is what I can't figure out how to do). I need the script to randomly select 4/9 X markers to target the spell at.

 

What would I add to the script to make it randomly choose 4 of possible X markers?

Edited by saintgrimm92
Link to comment
Share on other sites

For this, I would use a combination of formlists and an array. The reason being formlists are more dynamic, you can remove / add things to them and their sizes will update. Keep in mind that you can only remove forms from formlists that are added via script. You can't remove those that are added in the creation kit.

 

Example Script:

 

 

 

Formlist Property AllMarkersA Auto ;fill this formlist with all your xmarkers in the Creation Kit 
Formlist Property AllMarkersB Auto ;keep this list empty. 
Spell Property MySpell Auto 
Actor Property Boss Auto

Event OnInit() 
    Int M = AllMarkersA.GetSize() 
    While M > 0 
        M -= 1 
        AllMarkersB.AddForm(AllMarkersA.GetAt(M)) ;add all markers from list A to List B so they can be removed later.
    EndWhile 
    
    RegisterForSingleUpdate(5)
EndEvent 

Event OnUpdate() 
    Int M = AllMarkersB.GetSize() - 1 ;max entry for random range 
    
    Int I = 0 
    ObjectReference[] RandomMarkers = New ObjectReference[4] ;initalize array with 4 possible entries 
    While I < 4
        Int R = Utility.RandomInt(0, M) 
        RandomMarkers[I] = AllMarkersB.GetAt(R) as ObjectReference ;store random x marker in array 
        AllMarkersB.RemoveAddedForm(RandomMarkers[I]) ;remove xmarker from formlist to prevent repeats 
        M -= 1 ;subract 1 from the max range of the formlist 
        I += 1 
    EndWhile 
    
    I = 0 
    While I < 4 
        MySpell.Cast(Boss, RandomMarkers[I]) ;boss casts spell on x marker 
        I += 1
    EndWhile 
    
    I = 0 
    While I < 4 
        AllMarkersB.AddForm(RandomMarkers[I]) ;add xmarkers back to the formlist 
        I += 1 
    EndWhile 
    RegisterForSingleUpdate(5)
EndEvent

Link to comment
Share on other sites

No problem. You can think of an array as just a list, or folder that holds items. Then instead of using properties directly, you can just use the array with it's entry number. This is handy because you can iterate through the list with a while loop or use integers to get properties in the array. As a simple example, these three scripts do exactly the same thing:

 

1:

 

 

ObjectReference Property XMarker0 Auto 
ObjectReference Property XMarker1 Auto
ObjectReference Property XMarker2 Auto
ObjectReference Property XMarker3 Auto

Event OnInit()
    RegisterForSingleUpdate(5)
EndEvent 

Event OnUpdate() 
    XMarker0.Enable() 
    XMarker1.Enable() 
    XMarker2.Enable() 
    XMarker3.Enable() 
EndEvent

2:

ObjectReference Property XMarker0 Auto 
ObjectReference Property XMarker1 Auto
ObjectReference Property XMarker2 Auto
ObjectReference Property XMarker3 Auto

ObjectReference[] Property XMarkers Auto 

Event OnInit() 
    XMarkers = New ObjectReference[4] ;Make the XMarkers array have a length of 5, clearing any previous entries in the array. 
    XMarkers[0] = XMarker0 ;The first [0] slot is set to XMarker0
    XMarkers[1] = XMarker1
    XMarkers[2] = XMarker2 
    XMarkers[3] = XMarker3
    RegisterForSingleUpdate(5)
EndEvent 

Event OnUpdate() 
    XMarkers[0].Enable() ;Enable the ObjectReference in slot 0 which is XMarker0 
    XMarkers[1].Enable() 
    XMarkers[2].Enable() 
    XMarkers[3].Enable() 
EndEvent

3:

ObjectReference Property XMarker0 Auto 
ObjectReference Property XMarker1 Auto
ObjectReference Property XMarker2 Auto
ObjectReference Property XMarker3 Auto

ObjectReference[] Property XMarkers Auto 

Event OnInit() 
    XMarkers = New ObjectReference[4] ;Make the XMarkers array have a length of 5, clearing any previous entries in the array. 
    XMarkers[0] = XMarker0 ;The first [0] slot is set to XMarker0
    XMarkers[1] = XMarker1
    XMarkers[2] = XMarker2 
    XMarkers[3] = XMarker3
    RegisterForSingleUpdate(5)
EndEvent 

Event OnUpdate() 
    Int I = 0 
    While I < 4 
        XMarkers[I].Enable()
        I += 1
    EndWhile
EndEvent

 

You can fill your array in the script as I showed above, or you can fill it directly in the creation kit when setting the property. Formlists are easier to fill because you just drag and drop forms into it, while arrays you have to set each entry separately.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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