Tiziano74 Posted March 26, 2022 Share Posted March 26, 2022 Hi allI would like to assign a variable to an object present in a form list, if this object is in the player's inventory.Figuring out if the item is in inventory is a simple thing, but how can I assign a specific variable to that item?Maybe let me explain better with some code: WEAPON Property InventoryWeapon AutoFormList Property WeaponList Auto Event OnActivate(ObjectReference akActionRef) If Game.GetPlayer().GetItemCount(WeaponList) >= 1InventoryWeapon = ***what should i enter here?***EndIfEndEvent Thanks in advance to those who will answer! Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 26, 2022 Share Posted March 26, 2022 If you want to assign the first weapon in the form list found in the player inventory to a specific variable, do the following: Weapon InventoryWeapon FormList Property WeaponList Auto Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Int index = 0 While index < WeaponList.GetSize() Weapon Entry = WeaponList.GetAt(index) as Weapon If Entry ; make sure we got a valid value If akActionRef.GetItemCount(Entry) > 0 InventoryWeapon = Entry index = WeaponList.GetSize() ; got a valid result - exit while loop EndIf EndIf index += 1 EndWhile EndIf EndEvent You can also go in reverse. Which may be helpful if your formlist is ordered in a specific way. Reverse method would be as follows: Weapon InventoryWeapon FormList Property WeaponList Auto Event OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() Int index = WeaponList.GetSize() - 1 While index >= 0 Weapon Entry = WeaponList.GetAt(index) as Weapon If Entry ; make sure we got a valid value If akActionRef.GetItemCount(Entry) > 0 InventoryWeapon = Entry index = 0 ; got a valid result - exit while loop EndIf EndIf index -= 1 EndWhile EndIf EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts