Recipe = Produces random count of product?

Started by erdrik, January 13, 2015, 11:22:58 PM

Previous topic - Next topic

erdrik

How do I set a recipe to create a random amount of the desired product?

Something like the HarvestYeildRange of plants?

      <harvestYieldRange>
        <min>2</min>
        <max>4</max>
      </harvestYieldRange>


EDIT:
While Im at it is there a way to modify the product based on ingredients without .dll coding?
Basically I would like the stove to produce a secondary product based on whether there was meat involved.

erdrik

Nevermind.

I don't want to use dll modding for this project, but I do know how.
So I looked at thingCount to see what the problem was, and found this:


public void LoadDataFromXmlCustom (XmlNode xmlRoot)
{
if (xmlRoot.ChildNodes.Count != 1) {
Log.Error ("Misconfigured ThingCount: " + xmlRoot.OuterXml);
return;
}
CrossRefLoader.RegisterObjectWantsCrossRef (this, "thingDef", xmlRoot.Name);
this.count = (int)ParseHelper.FromString (xmlRoot.FirstChild.Value, typeof(int));
}


Can't have more than one childnode.
The first childnode's value must contain the int.

Poo. :(



JuliaEllie

#2
There are a few ways to do this but the easiest way in my opinion and what I did in my early modding experience was to make a "helper thing". Basically only a ThingDef which had a Def a Label and a ThingClass to execute.

You can set this as a product in your RecipeDef and on SpawnSetup it gets destroyed immediately and OnDestroy it executes some code. In your case spawning a random number of Things.

If you need further help on this I can see if I still find my old code or could quickly make up a new example.