Tes4Mod:Cobl/Modding/Alchemical Sorter

COBL (Common Oblivion) contains an alchemical sorter by PhoenixAmon (nee Daleth) and updated by haama.



Features
Store all of your ingredients with the click of a button.
Retrieve ingredients by effect - you'll be given a list of effects that you can make with your ingredients, select as many as you want and the ingredients that have that effect (corrected for Alchemy rank) will be moved to the player.
With OBSE v12, will work with any ingredient from any mod and an expanded set of effects (v1.16).
Also, two buttons have been added to make it easier to create potions on the fly. These allow the player to open the Alchemy menu while the Effects list is still open, create their potions, then reset the list of effects and see what other potions they can make (v1.48).
With OBSE v11, will also work with potions and scrolls (v1.48).
If the player is using a mod with COBL's dinner plate, this can also open a menu with only food items (v1.26).

Modder Basics
Simplest usage by modders is to drop one of the existing alchemical sorter containers in their mod. These are single containers that have the appearance of a shelf of containers (i.e., although the mesh looks like several different containers, it's actually just one.) You'll find these under containers -- their editors ids start with cobAlsShelf (LC, MC and UC indicate Lower Class, Middle Class and Upper Class respectively).

If you want to use a different container mesh (standard chest, standard cabinet, etc.) just create the container object as desired, and set its script to cobAlsTriggerOS. (Note: Make sure that the container is not set to respawn.)

Most likely, that's all you'll need to do. However, if you want to do more (create portable sorters, use multiple containers, etc.), then read on...

Tip: If you would like the shelves to look like they're built into the wall, you might use cobAlsShelfMC and push it back into the wall until the backing is hidden. If the backing sticks out slightly to the side of a narrow wall, then try changing the scale of the reference to shrink it.

Remote Access
The Trigger script has been updated (v1.48) to allow remote access without the need for a new script - meaning your Alchemical Sorter will have all future features and updates. The new system can also work during MenuMode so you can use inventory items as "Alchemy Bags". Details:

 with an appropriate EditorID (i.e., "ModNameAlsTriggerObj") and attach the trigger script (cobAlsTriggerFAS) to it.
 and give it a Reference Editor ID (i.e., "ModNameAlsTrigger") and check "Persistent Reference" and "Initially Disabled".
 - if you don't mind the normal chest open/close sound you can use cobGenChest. If you need to use a different opening/closing sound you can use cobGenChest as a base.
Create your object or item and apply this script (note this will work for both inventory items in Journal mode and objects in the game mode)
 

Pre-v1.48
By default, the sorter stores all ingredients in one container and all 3 of its functions are triggered by that container. If you want to use that default behavior, you only need to add your own storage container using whatever mesh you like, make sure it is not set to respawn, and attach the Trigger script.

You can set this up differently, and the trigger script is commented more heavily than you probably need. :) The main thing you need to know is if you want objects or actors other than the storage bin to trigger the effects, you needs your storage container to be a Persistent Reference with a unique name. You'll then need to clone the parts of the trigger script you want to use and replace "GetSelf" with the name of your container reference. Note that you must create a new script instead of editing COBL's, and that by doing so the script will not be updated when/if there is a COBL update (i.e., won't have v1.48's potion and scroll sorting).

Multiple Containers
If you want to use multiple containers to store your alchemy ingredients, you need to do a bit more work. I'll do my best to explain that here. First off, you still need a main storage container. This container should be placed in the gameworld somewhere outside of the player's sight (the way merchant containers are). Make sure it is not set to respawn. Once it's placed, make it a Persistent Reference and give it a unique name. In my samples, I'll call it "MyMainContainerRef".

You will need an object or actor to trigger the Storage part of the sorter, with a trimmed-down version of the trigger script mentioned above. If you look at the trigger script, it'll be easy to see what you need.

At this point you can choose to use a separate container for each ingredient name or a separate container for each potion effect.

Separate Containers by Ingredient
You need one container for every ingredient name. There are several sets you can download or you can make your own. You do not need to make these containers persistent references. Each container needs to have a script like the following:

 

Each script only needs 3 things changed: the script name, the ingredient reference and the container reference. Now after your trigger object or actor has put the ingredients away into the main storage container, the player can activate the small containers to take ingredients out by name.

Separate Containers by Effect
You need one container for every potion effect the player can make. I don't know of any downloadable sets for this. You do not need to make these containers persistent. Each container needs to have a script like the following:

 
Each script only needs 3 things changed: the script name, the container reference and the effect. If you'd like to use this for potions or scrolls, change the ItemType number and make sure to test for the proper OBSE version with
 ...
	set cobAlsSorterFAR.inItemType to 25 ;For Ingredients, set to 40 for Potions or 21 for Scrolls
	SetStage cobSigSE 0
	if (cobSigSE.Version  

Also, be sure the player is using at least COBL v1.53 before using this. You can check in an init script or here with
 ...
	SetStage cobSigSE 0
	if (cobSigSE.VersionCOBL  
Pre-v1.53 and Post-v1.47
 
Same instructions as with the Post-v1.52 system. The system is fully backwards compatible, and this method continues to work with v1.53.

Pre-v1.48
It's strongly advised to use one of the above systems because v1.48 adds a lot to the Alchemical Sorter. However, if you do decide to use this system - The system is fully backwards compatible, and this method continues to work with v1.48 and all later versions.
 
scn AlchContBurdenScr

short bActive
short bEmpty
float Timer

Begin OnActivate
  if (IsActionRef player)
	;Change these to suit your script
	set cobAlsCounter1.rContainer to MyMainContainerRef ;Set this to the Reference Editor ID of your container
	set cobAlsSorter1.iBurden to 1 ;Set to the effect, see below for the list

	set cobAlsCounterVars.bEffectContainers to 1
	set cobAlsCounter1.iAlchSkill to player.GetBaseAV Alchemy
	set cobAlsSorter1.fQuestDelayTime to 0.01
	set bActive to 1
	StartQuest cobAlsSorter1
  endif
End

Begin GameMode
    If bActive
      If Timer  

That might look a little horrid, but you only need to change a few things for each effect container. Each needs its own script name. Each needs "MyMainContainerRef" changed to the name of your main container reference.

The only other line to worry about is "set cobAlsSorter1.iBurden to 1". In that line, you need to change "Burden" to the name of the effect for the particular container. Remove any spaces or dashes (-) from the effect name, like the ones listed below.

In that same line, you need to set the right quest name for the effect you're working on. I tried to put all those variables in a single script, but it didn't work as I'd hoped so I had to split them up. The correct quest names are as follows:

Effects