Jump to content

Make Companion use item only when indoors/outdoors


Recommended Posts

Add this code to your companion's script, inside a GameMode block:

 

if YourCompanionRef.IsInInterior || (GetCurrentTime > 19) || (GetCurrentTime < 7)
	if YourCompanionRef.GetEquipped YourGlassesID
		YourCompanionRef.UnequipItem YourGlassesID 1
	endif
elseif YourCompanionRef.GetEquipped YourGlassesID
elseif YourCompanionRef.GetItemCount YourGlassesID
	YourCompanionRef.EquipItem YourGlassesID
endif

Link to comment
Share on other sites

I suspect that Jazz's script would make a mess if there was any advantage to equipping the sunglasses. The companion would keep trying to equip them and the script would keep removing them. I would change it to remove the sunglasses from the inventory entirely. Like so:

 

	short sGlassesCount
set sGlassesCount to YourCompanionRef.getItemCount YourGlassesID
if YourCompanionRef.IsInInterior || (GetCurrentTime > 19) || (GetCurrentTime < 7)
	if YourCompanionRef.GetEquipped YourGlassesID
		YourCompanionRef.RemoveItem YourGlassesID sGlassesCount
	endif
elseif YourCompanionRef.GetEquipped YourGlassesID
elseif YourCompanionRef.getItemCount YourGlassesID >= 1
	YourCompanionRef.equipItem YourGlassesID
else
	YourCompanionRef.addItem YourGlassesID 1
	YourCompanionRef.equipItem YourGlassesID
endif

Link to comment
Share on other sites

Xaranth,

 

Notice that the NoEquipFlag is set:

YourCompanionRef.UnequipItem YourGlassesID 1

That means the actor will not be able to re-equip the item again until EquipItem is called on the same ID. Unless the game-engine overrides it with companions, what you describe should not happen.

Link to comment
Share on other sites

Xaranth,

 

Notice that the NoEquipFlag is set:

YourCompanionRef.UnequipItem YourGlassesID 1

That means the actor will not be able to re-equip the item again until EquipItem is called on the same ID. Unless the game-engine overrides it with companions, what you describe should not happen.

 

 

Actually, the equipitem flag can fail with companions and clothing/armor. When players give them clothing items for the same slot with better DT and/or enchantments a companion may equip the other items over it regardless of the flag. I don't know if it will always happen in every body slot, but it happens in the body slot (or at least it happened routinely in the body slot for me). This isn't true with weapons, the equipitem flag holds an inferior weapon in place for a companion. But since the flag doesn't reliably hold clothing/armor in place, I think additional scripting to do that would be a good idea if it was important to never have that item change out.

 

 

Edit: Oops I answered this backwards. You were highlighting Unequip. Well, that's not necessarily reliable either. Either way you should expect to need some kind of reinforcement to get the appropriate behavior with companions, armor/clothing and equip/unequip and their flags.

Link to comment
Share on other sites

Curious, I went on and tested, and it appears to be working properly with the EyeGlasses slot (I made sure there was no silent infinite loop). However, for obvious reasons, it would probably be wise to first verify there was no equipped item already occupying this slot:

if YourCompanionRef.IsInInterior || (GetCurrentTime > 19) || (GetCurrentTime < 7)
if YourCompanionRef.GetEquipped YourGlassesID
	YourCompanionRef.UnequipItem YourGlassesID 1
endif
elseif YourCompanionRef.GetEquippedObject 11
elseif YourCompanionRef.GetItemCount YourGlassesID
YourCompanionRef.EquipItem YourGlassesID
endif

GetEquippedObject would require NVSE, but that's no big a deal.

Edited by jazzisparis
Link to comment
Share on other sites

  • Recently Browsing   0 members

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