Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Array Scripting Help...


Malonn
 Share

Recommended Posts

I'm trying to better familiarize myself with arrays.  So, I'm attempting to use an array in a situation where I know I could easily accomplish what I'm trying to do without an array.  I want to understand arrays.  They seem to open up a lot of options and possibilities with simplifying scripts and such.  Anyway, here's the script:

 

Let BodySlots := ar_Construct Array
Let BodySlots[0] := Player.GetEquippedObject 2
Let BodySlots[1] := Player.GetEquippedObject 3
Let BodySlots[2] := Player.GetEquippedObject 5
Let BodySlots[3] := Player.GetArmorType...<--Stuck here

I'm just trying to determine if the items equipped in the body, legs, and feet slots are heavy armor.  That's it for now.  But I'm stuck on the syntax for "GetArmorType" within an array.  GetArmorType requires an ObjectID::Ref.  How do I pass that ref within the element of an array?  I've tried the following (don't laugh :))

 

Let BodySlots[3] := Player.GetArmorType BodySlots

...Compiles, but produces an OBSE error during runtime

 

Let BodySlots[3] := Player.GetArmorType BodySlots[0]

...Won't compile. 

I'd really appreciate any help getting past this point.  Like I said, I can do it no problem using the traditional vanilla style scripting.  But I want to better understand arrays, so am practising with them.

Thanks for any help.

  • Upvote 1
Link to comment
Share on other sites

  • 2 years later...

Should Malonn still be interested in making that happen, it might be possible to turn all of player's equipped items into an array and then go through all of them with ForEach, doing something when an item of interest is found. This is how I would probably do it. Or at least how I would try to do it, as I have not checked whether it really works, but something like it should (if using CSE, it will automatically highlight errors and report wrong syntax, so it will be easy to fix the possible mistakes).

 

The variables

Array_var aItems
Array_var aTemp
ref       rTemp

And the main thing

let aTemp    := ar_Construct Array
let aItems   := Player.GetItems 20

ForEach aTemp <- aItems
    let rTemp := *aTemp
    If ( Player.GetEquipped rTemp ) && ( GetEquipmentSlot rTemp == 2 ) && ( GetArmorType rTemp == 1 )
        ; This heavy armour piece occupies upper body
    ElseIf ( Player.GetEquipped rTemp ) && ( GetEquipmentSlot rTemp == 3 ) && ( GetArmorType rTemp == 1 )
        ; This heavy armour piece occupies lower body
    ElseIf ( Player.GetEquipped rTemp ) && ( GetEquipmentSlot rTemp == 5 ) && ( GetArmorType rTemp == 1 )
        ; This heavy armour piece occupies feet
    EndIf
Loop

let aTemp    := ar_Null
let aItems   := ar_Null

Something like that. The Item variable is a reference, and it stays the same until Loop command, after which it is set to the next equipped item.

Hopefully that helps a little.

 

Edit: Added initialisation for aTemp (also lines to empty the arrays), as a similar script of mine reported error with <- operator, and that seemed to fix it. Also made it more like what you might want it to be (check the specified body slots). If it works.

 

Edit 2: Changed GetEquipped to GetItems for making it possible to use type filtering. Also changed the syntax to be one used for base objects, as I think GetItems returns base objects. Something like that worked about that way in a script I made just yesterday, so I suppose that one should work now, too. I have not yet tested it, though. Sorry for the confusion. :)

Edited by PhilippePetain
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...