Difference between revisions of "User:Candlemaster/Item Sorter"
imported>Candlemaster |
imported>Candlemaster |
||
(2 intermediate revisions by the same user not shown) | |||
Line 117: | Line 117: | ||
Will have to use GetObjectType codes. | Will have to use GetObjectType codes. | ||
After testing using RemoveMe, no items were moved to the container. Will have to find an alternate way to preserve reference variables. | |||
After converting the script to a potion sorter, it worked just fine, moving player-made potions. However, 3 potions were left behind, out of a large number of potions. Running the sorter again sorted them as desired. This is likely a bug in the actual script, or possibly in RemoveItemNS. Needs further investigation. | |||
==References== | ==References== | ||
Line 139: | Line 143: | ||
*[[IsSoulGem]] | *[[IsSoulGem]] | ||
*[[IsWeapon]] | *[[IsWeapon]] | ||
==[[GetObjectType]] codes== | |||
<pre> | |||
19 Apparatus | |||
20 Armor | |||
21 Book | |||
22 Clothing | |||
25 Ingredient | |||
26 Light ;includes torches | |||
27 Misc | |||
33 Weapon | |||
34 Ammo | |||
38 Soul Gem | |||
39 Key | |||
40 Alchemy Item ;AKA Potions | |||
42 Sigil Stone | |||
</pre> |
Latest revision as of 17:18, 12 May 2010
Item Sorter[edit | edit source]
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[edit | edit source]
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.
After testing this script, nothing happens when "Sort Ingredients" is chosen, but "Open Container" works fine.
It appears that the problem may have been "GetObjectType". Instead, I'll try using OBSE's "IsIngredient" function.
I've replaced GetObjectType with IsIngredient and nothing happens. The problem must be elsewhere.
Second Attempt[edit | edit source]
scn HVHGTSorterScriptIngredients long InvPos long Quantity short Button short CheckOnce ref pInvObj Begin OnActivate if ( GetActionRef == Player ) MessageBox "What would you like to do?" "Sort Ingredients" "Open Container" "Nevermind" set CheckOnce to 0 else Activate endif End Begin GameMode set Button to GetButtonPressed if ( Button == -1 ) Return elseif ( Button == 0 ) ;Sort Ingredients if ( HVHGTOBSE.HasObse ) if ( CheckOnce == 0 ) ;Only go through the player's inventory once PrintToConsole "Begun the search for ingredients" array_var each ForEach each <- player.GetItems 25 ; 25 = Ingredients PrintToConsole "Found an Ingredient" let pInvObj := each["Value"] if eval !(IsQuestItem pInvObj) let Quantity := player.GetItemCount pInvObj player.RemoveItemNS pInvObj Quantity AddItemNS pInvObj Quantity PrintToConsole "Item Moved" endif Loop PrintToConsole "LoopEnd" endif else ;Non-OBSE sorting script goes here endif set CheckOnce to 1 elseif ( Button == 1 ) ;Open Container Activate elseif ( Button == 2 ) ;Nevermind return endif End
Uses code given by tejon on the official forums. This script works flawlessly, sorting every ingredient in the player's inventory flawlessly. Only amendment I can think of is to move the items in such a way that retains the item's variables, including health, charge, player enchantment, and stolen status. Will look into using RemoveMe. Needs to be tested on potions to see if it work with player-made potions.
Will have to use GetObjectType codes.
After testing using RemoveMe, no items were moved to the container. Will have to find an alternate way to preserve reference variables.
After converting the script to a potion sorter, it worked just fine, moving player-made potions. However, 3 potions were left behind, out of a large number of potions. Running the sorter again sorted them as desired. This is likely a bug in the actual script, or possibly in RemoveItemNS. Needs further investigation.
References[edit | edit source]
- IsAlchemyItem
- IsAmmo
- IsApparatus
- IsArmor
- IsBook
- IsClonedForm
- IsClothing
- IsContainer
- IsFood
- IsIngredient
- IsKey
- IsLight
- IsLightCarriable
- IsPlayable
- IsPoison
- IsQuestItem (important)
- IsScripted
- IsSigilStone
- IsSoulGem
- IsWeapon
GetObjectType codes[edit | edit source]
19 Apparatus 20 Armor 21 Book 22 Clothing 25 Ingredient 26 Light ;includes torches 27 Misc 33 Weapon 34 Ammo 38 Soul Gem 39 Key 40 Alchemy Item ;AKA Potions 42 Sigil Stone