Jump to content
ℹ️ Intermittent Download History issues ×

Detect if an item has a specific form type


Recommended Posts

Hi,

 

I am trying to mod the manufacturing sorter to sort items based on the major inventory headings (weapons/junk/misc/etc.) and I am having trouble identifying the underlying form type as they pass through the sorter.

 

I figured I could use a combination of the form type (WEAP/MISC/etc.) as shown in the creation kit and secondary checks for things like identifying junk using GetComponentCount and detached mods by the keyword ObjectTypeLooseMods. The secondary checks seem strait forward (at the moment) but the form type check is doing my head in.

 

I have tried defining a property and assigning a form so I can use the HasForm check but the list of available forms does not seem to have the forms I need.

 

Can anyone give me any pointers on where to look or an alternate way to identify the form type via script?

 

Thanks.

Link to comment
Share on other sites

There's a way for type checks that I know of but it will only work on objectreferences, meaning it probably wont work in containers.

You store the objectreferences' base object to a Form variable and then cast the variable to a type you want to check.

Untested example:

Form myForm = object.GetBaseObject()
if myForm as Weapon
    ; some notification that its true
else
    ; not this type
endif
Link to comment
Share on other sites

Thanks, I will give that a go.

 

EDIT:

After having tried it I can sort some forms without issue but I am having trouble with others.

 

Weapons - baseForm as Weapon

Armor - baseForm as Armor

Ammo - baseForm as Ammo

Aid - baseForm as Potion

 

Misc - baseForm as Book gets the books and notes but misses the holodisks and other misc items

junk - baseForm as MiscObject partially works but I need an array of all components to finalise it

 

Does anyone have a list of the base forms I can use for Misc?

 

Thanks

Edited by mort1111
Link to comment
Share on other sites

I can suggest a workaround on how to iterate through container (check each item's type in container) without making each item object reference . You will need to make extra hidden container, when needed just call removeallitems() on main container and move all items to extra container. That extra cont will have OnItemAdded() event and you just check each item added there and after return back to first container. For example:

;Main Container

function removeItems()
 (self as objectreference).removeallitems(extraContainerProperty, true)
endfunction
;Extra Container

Event OnInit()
 AddInventoryItemFilter(None) ;needed onitemadded to fire
endevent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
 if akbaseitem is weapon   ;I recommend to use is operator, it allows to query the type of a variable without actually casting it.
  debug.trace("isweapon") 
 else 
  debug.trace("something else")
 endif
 (self as objectreference).removeallitems(MainContainerProperty, true)
endEvent 

I can't test it as I don't have access to my PC, but I'm pretty sure this will work. The question is how fast papyrus is with that events and removing, adding items if container has thousands of items. (it was rhetorical question, it's slow)

Edited by shavkacagarikia
Link to comment
Share on other sites

I managed to get it working, thanks for the pointers. Below is the function to handle it.

 

I added all components to the AllComponents array and set the ModKeyword to ObjectTypeLooseMod. Seems to work just need to give it a lot more testing as while debugging I managed to loose 2 mods as they went in one side and did not come out the other.

Component[] Property AllComponents auto
keyword Property ModKeyword auto

int function GetItemType(ObjectReference itemRef)
	debug.trace("item is " + itemRef)
	Form baseForm = itemRef.GetBaseObject()
	debug.trace("base form is " + baseForm)
	int res = 0
	if baseForm as Weapon
		debug.trace("Is Weapon")
		res = 1
	elseif baseForm as Armor
		debug.trace("Is Armor")
		res = 2
	elseif baseForm as Potion
		debug.trace("Is Aid")
		res = 3
	elseif baseForm as Ammo
		debug.trace("Is Ammo")
		res = 4
	else
		MiscObject miscItemToSort = itemRef.GetBaseObject() as MiscObject
		bool isJunk = false
		if miscItemToSort
			int i = 0
			while i < AllComponents.Length && !isJunk
				if miscItemToSort.GetObjectComponentCount(AllComponents[i]) > 0
					isJunk = true
				endif
				i = i + 1
			endWhile
		endif
		if isJunk
			debug.trace("Is junk")
			res = 5
		else
			if itemRef.HasKeyword(ModKeyword)
				debug.trace("Is mod")
				res = 6
			else
				debug.trace("Is misc")
				res = 7
			endif
		endif
	endif
	return res
endFunction
Link to comment
Share on other sites

  • Recently Browsing   0 members

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