Jump to content

[LE] Adding an item and equipping it to the player


hubbawubba

Recommended Posts

Hi, so I am still on my quest to familiarize myself with skyrim modding. I want to add an item(armor) from another mod to the player's bag and then equip it. I know I should be using:

 

Game.GetPlayer().AddItem()

Game.GetPlayer().EquipItem()

 

Though, from what I can gather they require you to add the armor within an ESP which I do not want. There is also the option of using Game.GetForm but I do not even know how to equip the item after getting it. What I prefer is a way to get the item by name then equip it. I also want to know if it is possible to check if there is an instance of the item before adding it to the bags, if that is the case, equip the item already available.

 

Thanks for your time.

Link to comment
Share on other sites

Let us see if I got this right.

 

You have an item from Mod A that you want to add and equip in your mod (Mod B)

 

Option #1

  1. Make the plugin of Mod A a parent master of your mod, Mod B.
  2. Start off by 'esmify-ing' the Mod A plugin with Wrye Bash (right click on plugin and choose 'esmify'
  3. Check mark it in the Creation Kit with your Mod B plugin set to be the active plugin.
  4. Apply the following lines to your script (or script fragment):
  5. Armor Property ModA_Armor Auto 
    ;change the ModA_Armor variable name to the Editor ID name of the armor in question and use Auto-fill in the property window to assign the correct data
     
    ;the following lines are to be inside of a function or event
    Actor PlayerRef = Game.GetPlayer()
    If PlayerRef.GetItemCount(ModA_Armor) <= 0
      PlayerRef.AddItem(ModA_Armor,1)
    EndIf
    PlayerRef.EquipItem(ModA_Armor)
    
  6. Fill the propertes
  7. Save your plugin
  8. Use Wrye Bash to "espfiy" the Mod A plugin
  9. Test in game

 

Option #2

  1. Use GetFormFromFile and skip messing with the Mod A plugin
  2. Simply apply the following in your script:
  3. ;everything here needs to go inside a function or event
    ;replace ZZZZZZ with the last 6 digits of the objects Editor ID number
    
    Armor ModA_Armor = Game.GetFormFromFile(0x00ZZZZZZ,"ModA_PluginName.esp")
    Actor PlayerRef = Game.GetPlayer()
    If ModA_Armor ;just a check to ensure we retrieved a valid object -- allows Mod B to work even without Mod A present
      If PlayerRef.GetItemCount(ModA_Armor) <= 0
        PlayerRef.AddItem(ModA_Armor,1)
      EndIf
      PlayerRef.EquipItem(ModA_Armor)
    EndIf
    
  4. Save your plugin
  5. Test in game

Personally, I prefer option #2. There is less room for error, it can work (or at least quietly fail) even if the user did not install Mod A. Whereas with option #1, the user must have Mod A installed or their game will CTD at the main menu.

Link to comment
Share on other sites

Thanks a lot for the information, IsharaMeradin. I decided to go with the second one for simplicity. The code is pretty clear, it is much appreciated. Though, I had a compiling issue until I added "Game.GetFormFromFile(0x00ZZZZZZ,"ModA_PluginName.esp") as armor". Everything is working nicely. Thanks again.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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