dizietemblesssma Posted September 23, 2020 Share Posted September 23, 2020 To fill an array with weapons and spells do I need the following: Form[] weapons_spells weapons_spells = New Form[6] weapons_spells[0] = aRef.GetEquippedWeapon(True) As Form ;left hand weapon weapons_spells[1] = aRef.GetEquippedWeapon(False) As Form ;right hand weapon weapons_spells[2] = aRef.GetEquippedSpell(0) As Form ;left hand spell weapons_spells[3] = aRef.GetEquippedSpell(1) As Form ;right hand spell weapons_spells[4] = aRef.GetEquippedSpell(2) As Form ;other spell weapons_spells[5] = aRef.GetEquippedSpell(3) As Form ;instant spell Or can I miss out the casting?I'm trying to avoid having an array each for weapons and spells diziet Link to comment Share on other sites More sharing options...
Evangela Posted September 24, 2020 Share Posted September 24, 2020 That's the only way to do it for arrays. Alternatively you can use a Formlist instead and not cast at all. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted September 24, 2020 Author Share Posted September 24, 2020 Thanks for replying, while waiting I had a brainwave, after I got up off the floor I decided to check it. Given that I already had a formlist for equipped items; assuming my brainwave - that if I first filled the formlist with the weapons and spells in a particular order, I would always know which one was in which position of the formlist and be able to reapply.Seems to be working so far! My problem now seems to be that if the formlist at, say (0), is empty; then using equipitemex doesn't replace with no weapon (in this case) but leaves the current one (if there is one): If dz_mcm.weapons_include_toggle == True the_npc.EquipItemEx(outfit_formlist.GetAt(0) As Weapon,2,False,True) the_npc.EquipItemEx(outfit_formlist.GetAt(1) As Weapon,1,False,True) the_npc.EquipSpell(outfit_formlist.GetAt(2) As Spell,0) the_npc.EquipSpell(outfit_formlist.GetAt(3) As Spell,1) the_npc.EquipSpell(outfit_formlist.GetAt(4) As Spell,2) While i < Items.Length ;loop through the stored items If Items[i] As Ammo ;restore ammo this_npc.EquipItemEx(Items[i],0,False,True) ;re-equip them EndIf i = i + 1 EndWhile EndIf Is there an efficient way to check for the formlist at (i) being empty? diziet Link to comment Share on other sites More sharing options...
Evangela Posted September 25, 2020 Share Posted September 25, 2020 I don't have experience with formlists and work primarily with arrays. https://www.creationkit.com/index.php?title=GetAt_-_FormList You want to use the second code example I believe. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 25, 2020 Share Posted September 25, 2020 FormLists do not have empty entries. There might be none of the object at a given entry in the target container / inventory. But the formlist itself still has an entry. To check if the item exists in the target container / inventory use GetItemCount. You can use HasSpell to ensure the target knows the spell before equipping in case you do not want the target to learn the spell automatically with EquipSpell Adapting your posted code to show an example: If dz_mcm.weapons_include_toggle == True If the_npc.GetItemCount(outfit_formlist.GetAt(0) as Weapon) >= 1 the_npc.EquipItemEx(outfit_formlist.GetAt(0) As Weapon,2,False,True) EndIf If the_npc.GetItemCount(outfit_formlist.GetAt(1) as Weapon) >= 1 the_npc.EquipItemEx(outfit_formlist.GetAt(1) As Weapon,1,False,True) EndIf If the_npc.HasSpell(outfit_formlist.GetAt(2) as Spell) the_npc.EquipSpell(outfit_formlist.GetAt(2) As Spell,0) EndIf If the_npc.HasSpell(outfit_formlist.GetAt(3) as Spell) the_npc.EquipSpell(outfit_formlist.GetAt(3) As Spell,1) EndIf If the_npc.HasSpell(outfit_formlist.GetAt(3) as Spell) the_npc.EquipSpell(outfit_formlist.GetAt(4) As Spell,2) EndIf While i < Items.Length ;loop through the stored items If Items[i] As Ammo ;restore ammo If this_npc.GetItemCount(Items[i] as Ammo) >= 1 this_npc.EquipItemEx(Items[i],0,False,True) ;re-equip them EndIf EndIf i += 1 EndWhile EndIf Link to comment Share on other sites More sharing options...
dizietemblesssma Posted September 25, 2020 Author Share Posted September 25, 2020 FormLists do not have empty entries. There might be none of the object at a given entry in the target container / inventory. But the formlist itself still has an entry.Ah, thankyou for the clarification.Well in theory the stored spell should be one of the target's own but the check is a good idea, in my last array loop though, is : If this_npc.GetItemCount(Items[i] as Ammo) >= 1necessary? Since I have immediately prior: If Items[i] As AmmoAnd why >= and not just = ? also this compiles, would this not work? If (outfit_formlist.GetAt(0) as Weapon) the_npc.EquipItemEx(outfit_formlist.GetAt(0) As Weapon,2,False,True) EndIfsince it wouldn't be ' as Weapon' if there was nothing there, right? diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 25, 2020 Share Posted September 25, 2020 A formlist is a list of forms. They can consist of any object type that has a plugin record. A cast will ensure that the form entry is of a certain type else skip it. It still does not ensure that there is actually an instance of that object in the target container / inventory. GetItemCount ensures that there is an instance of that listed object. ">= 1" allows there to be one or more instance of said object"== 1" requires that there be only one instance of said object For ammo there will almost always be more than one in a given stack. Better to be safe and check if the quantity on hand is greater or equal to one. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted September 25, 2020 Author Share Posted September 25, 2020 A formlist is a list of forms. They can consist of any object type that has a plugin record. A cast will ensure that the form entry is of a certain type else skip it. It still does not ensure that there is actually an instance of that object in the target container / inventory. GetItemCount ensures that there is an instance of that listed object. ">= 1" allows there to be one or more instance of said object"== 1" requires that there be only one instance of said object For ammo there will almost always be more than one in a given stack. Better to be safe and check if the quantity on hand is greater or equal to one.I am being obtuse, I can feel it, as HAL said:)Isn't outfit_formlist.GetAt(0)just one form? So how could the count be more than one, my entire logic is based around the '(0)' referencing just one particular position in the formlist, so if I'm wrong I have much bigger problems! As for the ammo, I'm not worried about how much of an ammo there is, just whether the array element Items is Ammo and to equip it if it is. Sorry to prolong this query:) diziet Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 25, 2020 Share Posted September 25, 2020 Yes GetAt(0) points to a single entry in the list. The entry will ALWAYS be in the formlist unless script added and Revert is ran on the list at some point. But you want to EQUIP the item. If the NPC / Player does not have the item it will not be equipped when using the EquipItemEX function. Using GetItemCount to ensure the item is in the target inventory allows the EquipItemEX to actually equip the item. If you used the simple EquipItem function, the game will create an instance if necessary and equip it. The same thing with Ammo, cast an entry as Ammo and if it returns true. Great, its an ammo! Again it cannot be equipped if it does not exist in the target inventory especially if using EquipItemEX. You are getting hung up on: does the formlist entry exist VS does at least one instance of the formlist entry exist for me to manipulate it. Link to comment Share on other sites More sharing options...
dizietemblesssma Posted September 26, 2020 Author Share Posted September 26, 2020 Right, I have been slow.My mistake is in not reading about GetItemCount and just making assumptions. I thought it to be a query about the formlist, not a query about the target - duh!My original issue was finding out whether outfit_formlist.GetAt(0) was itself a weapon/spell or other, not whether the target had one!You see if there is no weapon/spell to equip (and thus replace the existing weapon) I need to 'empty' any existing weapons/spells so that what is equipped on the target matches what is stored in the first 6 elements?indexes?positions? of the formlist. The formlist's first six positions are always filled with weapons/spells or nothing in the same order, weapons left then right, then spells 0 through 4 (does anyone ever use 4?)However you have pointed out to me a mistake in my logic, where after storing in a formlist an item that the target posesses, the target may get rid of the item before the formlist is re-applied, and I do need your suggestion to check this.But can I still use If (outfit_formlist.GetAt(0) as Weapon)to see if the formlist position has a weapon?Then I can use your snippet to check the target still has it before equipping; or remove anything already equipped in that weapon/spell slot if the formlist position does not hold a weapon/spell. diziet Link to comment Share on other sites More sharing options...
Recommended Posts