Jump to content

[LE] "if in inventory, unequip two specific armor pieces" and vice versa


Recommended Posts

You want some code to trigger when two separate objects are unequippepd? Not possible for a misc object. You'll need more that one script to achieve this. It could be done with one script on an actor alias but if you specifically want a misc object to run specific code, then you will need two scripts at minimum.

 

Quest record with an alias pointing to the actor (could be player or desired NPC)

Attach script to the alias record, would be something like this:

 

 

Scriptname MultiObjectUnequipAliasScript Extends ReferenceAlias

FormList Property myObjectList 	Auto 
;this list contains all objects to be checked

GlobalVariable Property myObjectsUnequipped Auto 
;this global keeps track of how many equipped / unequipped
;start value should match the total number of items in the formlist

Int Property TotalNumPieces Auto 
;this value must match total number of items in formlist

myMiscObjectScript Property myObjectScript Auto 
;this will point to the object holding the target script
;the object type name (far left) must be identical to the target script name. Variable name can be anything.

Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
	Int index = myObjectList.GetSize() - 1
	While index >= 0
		Form Entry = myObjectList.GetAt(index)
		If Entry == akBaseObject
			myObjectsUnequipped.Mod(1) ;add one for each unequipped
		EndIf
		index -= 1
	EndWhile
EndEvent

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
	Int index = myObjectList.GetSize() - 1
	While index >= 0
		Form Entry = myObjectList.GetAt(index)
		If Entry == akBaseObject
			myObjectsUnequipped.Mod(-1) ;remove one for each equipped
		EndIf
		index -= 1
	EndWhile
EndEvent

Function GetIfAllUnequipped(GlobalVariable myGV)
	If (myGV.GetValue() as Int) == TotalNumPieces
;Tell the other script to run a specific function
		myObjectScript.TargetItemsUnequipped() 

	ElseIf (myGV.GetValue() as Int) < TotalNumPieces
;statement in the log indicating not enough have been removed -- can be removed after testing
		Debug.Trace("Not enough pieces unequipped yet.") 

	ElseIf (myGV.GetValue() as Int) > TotalNumPieces
;statement in the log indicating too many have been removed -- can be removed after testing
		Debug.Trace("Something went wrong too many") 
	EndIf
EndFunction

 

 

Create the form list and global variable records to fill those properties. The form list must have each item that needs to be unequipped. The global needs to start off with a non-constant value of zero.

Finally attach a script to the misc object that you want to actually run the code.

Something like:

 

 

Scriptname myMiscObjectScript Extends ObjectReference

Function TargetItemsUnequipped()
	;do something
EndFunction

 

 

Ensure that all properties are properly filled before testing in-game.

 

Please note, neither script has been tested for compilation or function. It should also be noted that this was written to be able to handle more than just two items. If one wanted to track whether five different items were all unequipped after having been equipped, they could.

Link to comment
Share on other sites

slight misunderstanding. i want to make it so, when the miscitem is picked up, it forcefully unequips two pieces of armor. and when the item is removed, it also re equips the two pieces of armor. preferably make it so it can only activate on a specific actor

Link to comment
Share on other sites

Then state clearly what you want the first time...

 

 

 

ScriptName myObjectScript Extends ObjectReference
 
FormList Property myGearList Auto
;formlist containing all get intended to be equipped / unequipped
 
Actor Property TargetActor Auto
;the target actor
 

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
  If akNewContainer && akNewContainer as Actor == TargetActor
    Int index = myGearList.GetSize() - 1
    While index >= 0
      Form Entry = myGearList.GetAt(index)
      If TargetActor.GetItemCount(Entry) > 0 ;actually have the item
        If TargetActor.IsEquipped(Entry)
          TargetActor.UnEquipItem(Entry)
        EndIf
      EndIf
      index -= 1
    EndWhile
  ElseIf akOldContainer && akOldContainer as Actor == TargetActor
    Int index = myGearList.GetSize() - 1
    While index >= 0
      Form Entry = myGearList.GetAt(index)
      If TargetActor.GetItemCount(Entry) > 0 ;actually have the item
        If !(TargetActor.IsEquipped(Entry))
          TargetActor.EquipItem(Entry)
        EndIf
      EndIf
      index -= 1
    EndWhile
  EndIf
EndEvent

 

 

Not tested for function or compilation. Unequips items in list if present and equipped when moved into the target actor's inventory. Equips the items in the list if present when removed from the target actor's inventory. Note that any player added enchantments will not take affect. Enchantments attached to the base record via the CK will take affect.
You can explicitly define the items to be equipped / unequipped. Using a formlist, however, gives room for growth without rewriting the code if at some point you wish to include more than the initial two items.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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