Add item to ThingDefOf for spawning.

Started by EzraN, August 26, 2016, 11:33:12 PM

Previous topic - Next topic

EzraN

I am working on a mod with multiple items and have created a building that when it is spawned will place a new item I made from the mod beside it. The trouble is with getting the item to spawn since when using GenSpawn you need a thingdef, but I am not too sure on how to reference that item or locate it. How can I find that item and then place it into GenSpawn or a similar method to make it spawn into the game world?

Lockdown

If I understand correctly, you want your mod to to spawn an item from another mod? The simplest way is probably to add the other mod as a library reference, like you've done for Assembly-CSharp.dll and UnityEngine.dll, which will allow your mod's class to reference the intended item directly. If you want to do it without a mod dependency, I don't know how to help, but CCL might have a way of making that happen.

EzraN

#2
Oh I didn't mean that I meant like spawning an item from my own project. I'll change the main question. Sorry

RemingtonRyder

#3
Use ThingDef.Named("thisThingHere") instead.

Obviously this isn't an awesome way of doing things, it's just for illustration. If you have a lot of thingdefs that need to be named you'll probably want to have a section with string constants so that if you need to change a defName you only need to do it in one place.

Master Bucketsmith

      <li Class="CompProperties_Spawner">
        <thingToSpawn></thingToSpawn>
        <spawnCount></spawnCount>
        <spawnIntervalRange>
          <min></min>
          <max></max>
        </spawnIntervalRange>
        <spawnMaxAdjacent></spawnMaxAdjacent>
        <spawnForbidden></spawnForbidden>
      </li>

You can also use this to spawn stuff, but I haven't found a way to give it more criteria through XML.