Jump to content

[LE] Recognize an object in a form list and assign it a variable


Recommended Posts

Hi all

I 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 Auto

FormList Property WeaponList Auto

 

Event OnActivate(ObjectReference akActionRef)

 

If Game.GetPlayer().GetItemCount(WeaponList) >= 1

InventoryWeapon = ***what should i enter here?***

EndIf

EndEvent

 

 

 

Thanks in advance to those who will answer!

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

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