Jump to content

[Script] Remove Misc Items


Zorkaz

Recommended Posts

I have a script like this:

Function RemoveMisc()
    Actor PlayerRef = Game.GetPlayer()
    Int iWaponCount = PlayerRef.GetItemCount(ObjectTypeWeapon)
EndFunction

 

I want to remove all misc items.

The issue is that I don't find a keyword for misc items. Any ideas?

Link to comment
Share on other sites

I'm wondering if these might help:

https://ck.uesp.net/wiki/GetType_-_Form

https://ck.uesp.net/wiki/GetIsFormType

 

I am assuming that the list in the first link would be the one to use in the second, and that kMisc = 32 from that list is in fact a misc item:)

 

diziet

 

edit: except that's Skyrim and this is the F4 forum, both tabs next to each other in my browser:)  Arrrgh!

  • Like 1
Link to comment
Share on other sites

I haven't tested this code but something like this should work in vanilla:

Container Property TempContainerBase Auto Const

Function RemoveAllMiscItems(ObjectReference theRef)
	If !theRef
		Return None
	EndIf
	; create a temporary container
	ObjectReference tempContainerRef = theRef.PlaceAtMe(TempContainerBase)
	If !tempContainerRef
		Return None
	EndIf
	; transfer all items from theRef to the temp container
	theRef.RemoveAllItems(tempContainerRef)
	If tempContainerRef.GetItemCount() == 0
		Return None
	EndIf
	Int iMaxRunCount = 1000
	Int Index = 0
	; drop and check each object reference of the items
	While Index < iMaxRunCount && Index < tempContainerRef.GetItemCount()
		ObjectReference DroppedRef = tempContainerRef.DropFirstObject()
		; presumably, tempContainerRef is now empty
		If !DroppedRef
			Index = iMaxRunCount
		Else
			Form ItemBase = DroppedRef.GetBaseObject()
			If ItemBase
				; add the items which are not Misc Items back to the inventory of theRef
				If !(ItemBase as MiscObject)
					theRef.AddItem(DroppedRef)
				; otherwise, remove
					DroppedRef.Delete()
				EndIf
			EndIf
		EndIf
		Index = Index + 1
	EndWhile
	; optional, move everything back to theRef's inventory that happens to be in the temp container, just in case
	tempContainerRef.RemoveAllItems(theRef)
	; delete the temp container
	tempContainerRef.Delete()
EndFunction

 

Link to comment
Share on other sites

21 hours ago, Zorkaz said:

I have a script like this:

Function RemoveMisc()
    Actor PlayerRef = Game.GetPlayer()
    Int iWaponCount = PlayerRef.GetItemCount(ObjectTypeWeapon)
EndFunction

 

I want to remove all misc items.

The issue is that I don't find a keyword for misc items. Any ideas?

There's no specific keyword for misc items, but you can loop through the player's inventory and check item types. Try using FormList or filtering by exclusion (i.e., not weapons, armor, etc.). Another option is checking for specific EditorIDs if you have a known list.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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