Jump to content

[Script] Equipping an item with specific modifications - Not the base object


Recommended Posts

I'm wondering whether it's possible to equip an item (more specifically an armour piece) that has specific modifications applied to it. I am asking because I need to have the player automatically equip an item for the duration of an event. Everything I've found points to you only being able to specify a base object, which obviously means you can't have the player equip an item with specific modifications applied to it. I've got the script working fine with the base object.

 

If you're unable to equip an item with specific modifications, then that's a shame, but an answer would be appreciated all the same. If there are workarounds though, any information would be appreciated.

Link to comment
Share on other sites

I would like to be able to do this for weapons, but the equip command needs to point to a weapon base object. You will probably want to make a copy of the armor you want to use (a copy of the base object). Then go in and change the mod to the specific one you want.

Obviously you dont want to edit the original base object unless you're trying to change it everywhere in the game.

Link to comment
Share on other sites

So are you saying the only way to equip an armour piece with specific modifications would be to create a form for each combination of modifications (and this will need to be done again for each legendary effect, etc.)? While that does sound like it would work, that would require thousands of different base objects. This is because I'm looking to have the player automatically equip an armour piece of their choosing, which they already have in their inventory. I'd probably be better off choosing one of the base objects from their inventory and then attaching their existing modifications to it using something like AttachModToInventoryItem, which they'd also have to select. The issue becomes that if I attach modifications to a random base object, this would duplicate those modifications, and the player might not even want that done. I'm currently changing a few other things around in the script, but once I do that I'm going to see if there's some pattern to how the base object is selected (it seems to prioritise unmodified base objects over modified equivalents from my brief testing yesterday), and exploit that to at least increase the chances of the right armour piece being equipped. Hopefully it's not random.

 

Thanks for the reply by the way :)

Link to comment
Share on other sites

This is how Bethesda handles it for vanilla things. They make a copy and use the copy only for that quest/script function. Similar to how all the vanilla companions have a special copy of a base weapon that they use. I suppose another reason specific to the companion weapons, is that they tag them not for player use so you can't take them and modify them and such.

 

After reviewing the papyrus functions it looks like this would be the only way. You cannot specify a ref id which would be nice. So making a copy of the base object specifically for your quest seems to be the only way immediately obvious. You could your script code to add the item to inventory, equip it, do whatever you want, then unequip and remove it when done. This has the benefit that in the base id for the copy you can specify only the mods you want the item to have so when you create it you don't have to check it has the right mods, or add them, you just make it and equip and you're done.

 

*Edit: doh you posted while I was typing. Perhaps I mis-understand what it is you're trying to do.

Edited by BigAndFlabby
Link to comment
Share on other sites

This is what I use to equip an item with modifications attached in my mod:

 

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon)
        
int j = 0
while j < givenMods.getSize()
    newItem.attachMod( givenMods.GetAt( j ) as ObjectMod )
    j += 1
EndWhile

PlayerREF.addItem( newItem, 1, true )

Weapon newBaseItem = newItem.GetBaseObject() as Weapon

PlayerREF.equipItem( newBaseItem, false, true )
givenWeapon here is one of the base Weapon records, and givenMods is a FormList containing the mods I want applied to the weapon.
Link to comment
Share on other sites

So by the sounds of it, the only way to equip an item with specific modifications is to only have one of the base object in your inventory. I'm assuming that Xylozi's method won't work if you already have multiple copies of the base object in your inventory (as it will equip one of the base objects, and not necessarily the item you just applied modifications to). Thanks for the code Xylozi, I might end up using it (and I'll of course credit you for it).

 

@BigAndFlabby - Sorry about not giving you guys any specifics, basically the mod automatically equips your helmet while you're in combat, and removes it once you exit combat. I'm going to include a settings holotape with the mod that allows the user to specify which helmet needs to be equipped during combat, hence my current problem. Thinking about it now, I'll probably have two sets of headgear, what should be worn in combat for defense, and what should be worn outside of combat for aesthetics. I've set it up using the OnCombatStateChanged event. As I don't want to duplicate the helmet each time the user enters combat, my best bet is to exploit how the EquipItem and RemoveItem functions work (which items they prioritise equipping and removing respectively). Though, I might use something along the lines of what Xylozi has done if I can't get anything else to work. While it would be similar, I'd be using global variables instead of form lists, as global variables are the only way I know how to allow the user to change settings.

 

Again, thanks for the replies guys :smile:

Link to comment
Share on other sites

  • 2 weeks later...

Here is a (slight) modification to Xylozi's code that should (don't feel like trying to compile it) make sure your new modified weapon is equipped:

 

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon)
ObjectReference abox = PlayerREF.PlaceAtMe(acontainer)
        
int j = 0
while j < givenMods.getSize()
    newItem.attachMod( givenMods.GetAt( j ) as ObjectMod )
    j += 1
EndWhile

Weapon newBaseItem = newItem.GetBaseObject() as Weapon

if (PlayerREF.GetItemCount(newBaseItem) > 0)
    PlayerREF.RemoveItem(newBaseItem, PlayerREF.GetItemCount(newBaseItem), true, abox)
endif

PlayerREF.addItem( newItem, 1, true )

PlayerREF.equipItem( newBaseItem, false, true )

abox.RemoveAllItems(PlayerREF, false)

abox.Disable()
abox.DeleteWhenAble()
Link to comment
Share on other sites

i would have thought that

PlayerREF.equipitem(newitem, 1, True)

would surely work, provided newitem is a persistent reference. So if you change this line

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon)

to this

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon, 1, TRUE, FALSE, FALSE)

newitem will be persistent and should be equippable as an ObjectReference?

Edited by steve40
Link to comment
Share on other sites

i would have thought that

PlayerREF.equipitem(newitem, 1, True)
would surely work, provided newitem is a persistent reference. So if you change this line

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon)
to this

ObjectReference newItem = PlayerREF.PlaceAtMe(givenWeapon, 1, TRUE, FALSE, FALSE)
newitem will be persistent and should be equippable as an ObjectReference?

 

The problem, I believe, is that EquipItem takes a Form and not an Objectreference. So (again, my understanding) is when you tell it to equip a particular weapon form, it simply chooses at random (from the player's inventory). I've never really tested anything like this, so I can't be certain I'm right in my assumption, though. I don't know if making the item persistent or not would have any effect.

Edited by Reneer
Link to comment
Share on other sites

  • Recently Browsing   0 members

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