Jump to content

Unequipping Items


ahab5920

Recommended Posts

Posted

Hey,

 

I'm working on a mod with some similar functionality to Combat Strip Lite and I'm trying to unequip an armor piece and prevent it from being re-equipped. Based on Creation Kit it should be as simple as PlayerRef.UnequipItem(*Item*, True) but this hasn't been working for me.  After unequipping the item, it can be re-equipped from the pipboy with no issues. Here's the script I have:

 

Function StripPlayer()
	VM_Debug("Stripping Player", Module)
	Int[] ArmoredSlots = GetFilledSlots(VM_Armor)
	Int[] ClothedSlots = GetFilledSlots(VM_Clothing)
	If ArmoredSlots.Length > 0
		Int Index = Utility.RandomInt(0,ArmoredSlots.Length - 1)
		Int Slot = ArmoredSlots[Index]
		Form Item = GetArmor(Slot)
		If Item != none && !DD_List.HasForm(Item)
			StrippedItem NewStrippedItem = New StrippedItem
			NewStrippedItem.ItemRef = Item
			NewStrippedItem.Slot = Slot
			StrippedItems.Insert(NewStrippedItem,0)
			PlayerRef.UnequipItem(Item, true, true)
		EndIf
	ElseIf ClothedSlots.Length > 0
		Int Index = Utility.RandomInt(0,ClothedSlots.Length - 1)
		Int Slot = ClothedSlots[Index]
		Form Item = GetArmor(Slot)
		If Item != none && !DD_List.HasForm(Item)
			StrippedItem NewStrippedItem = New StrippedItem
			NewStrippedItem.ItemRef = Item
			NewStrippedItem.Slot = Slot
			StrippedItems.Insert(NewStrippedItem,0)
			PlayerRef.UnequipItem(Item, true, true)
		EndIf
	Else
		VM_Debug("Nothing To Strip",Module)
	EndIf
	StartTimer(StripRegenTimer,4)
EndFunction

 

Any ideas on what I'm doing wrong here that may be interrupting the prevention? Any help is greatly appreciated!

 

Thanks!

Posted

The abPreventEquip option doesn't work, at least on the player. 

 

Since you are storing the stripped items in an array, you can make an OnItemEquipped event handler, and search the array for a StrippedItem whose Item matches the akBaseObject parameter of the event handler.  If one is found, you can then unequip the item again.  Something like this:

 

RegisterForRemoteEvent(PlayerRef, "OnItemEquipped")

Event Actor.OnItemEquipped(Actor akSender, Form akBaseObject, ObjectReference akReference)
	Int i = StrippedItems.Length
	While (i > 0)
		i -= 1
		If (StrippedItems[i].ItemRef == akBaseObject)
			akSender.UnequipItem(akBaseObject, false, true)
			return
		EndIf
	EndWhile
EndEvent

 

I'm assuming that GetArmor() calls GetWornItem() and returns WornItem.Item if it is an Armor.  Note that WornItem.Item is a base object (Armor or Weapon) and not an ObjectReference,  I only point this out because you are storing Item in StrippedItem.ItemRef, which implies reference.

 

Posted

Thanks! I was unaware that it didn't work for the player. The OnEquip event handler sounds like a great way to handle this for my purposes. 

 

Also, thanks for pointing out the referencing issue. I am aware of this (Had some issues in previous iterations of this mod that resulted in a lot of annoyance at the creation engine's structure). I'll probably go through and clean up my variable names once I get it working properly.

 

Thanks for the help!

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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