User:Candlemaster/Item Sorter

< User:Candlemaster
Revision as of 02:15, 12 May 2010 by imported>Candlemaster (→‎First Attempt)

Item Sorter

The goal of this script is to search the player's inventory for certain items, and place them into a special container. This has been accomplished in a number of oblivion mods (see COBL's alchemy sorter), so it should not be too difficult to find reference scripts.

I wish to make separate scripts for each item type; One for ingredients, one for potions, one for books (possible to interact with the book sorter?), one for scrolls, one for Blade weapons, one for Blunt weapons, one for Marksman weapons, one for Light armor, one for Heavy armor, one for Keys, one for Soul Gems, and one for Misc. items (Ores, gems, hides, etc.)

Without using OBSE, I suspect that I'll need to add checks for every item in the game. This method will be easy to make exceptions, and make it impossible to sort quest items. I'd like to add optional OBSE functionality which will sort mod-added items, and add buttons for the ingredient, potion, and magic scroll sorters which will allow you to withdraw items by effect.

All that I want to do with this script has been done in COBL's alchemy sorter script, so most likely I'll copy the backbone of said script. If you have any advice or tips for this endeavor, please post them here.

First Attempt

scn HVHGTSorterScriptIngredients

long InvPos
long Quantity
short Button
short CheckOnce
ref pInvObj
ref pCont


Begin OnActivate
	MessageBox "What would you like to do?" "Sort Ingredients" "Open Container" "Nevermind"
	set CheckOnce to 0
End

Begin GameMode
	set Button to GetButtonPressed
	if ( Button == -1 )
		Return
	elseif ( Button == 0 ) ;Sort Ingredients
		if ( HVHGTOBSE.HasObse == 1 )
			if ( CheckOnce == 0 ) ;Only go through the player's inventory once
				set pCont to PlayerRef
				set InvPos to 0
				Label
				set pInvObj to (pCont.GetInventoryObject InvPos)
				if pInvObj
					if ( pInvObj.GetObjectType == 25 ) ;If the item is an ingredient
						if ( pInvObj.IsQuestItem == 0 ) ;Don't do anything to a quest item
							set Quantity to pCont.GetItemCount pInvObj
							pCont.RemoveItemNS pInvObj Quantity
							AddItemNS pInvObj Quantity
						endif
					endif
					set InvPos to (InvPos + 1)
					Goto
				endif
				set CheckOnce to 1
			endif
		endif
	elseif ( Button == 1 ) ;Open Container
		Activate
	elseif ( Button == 2 ) ;Nevermind
		return
	endif
End

This is my first rendition of an OBSE-using ingredient sorter. Notice "GetObjectType == 25" which checks if the object is, in fact, an ingredient. For more codes like this, see [GetObjectType]. Useful codes (For this purpose) seem to be:

After testing this script, nothing happens when "Sort Ingredients" is chosen, but "Open Container" works fine.

19   Apparatus
20   Armor
21   Book
22   Clothing
25   Ingredient
26   Light ;Including Torches?
27   Misc
33   Weapon
34   Ammo
38   Soul Gem
39   Key
40   Alchemy Item ;I'm pretty sure this means Potion
42   Sigil Stone