Ludeon Forums

RimWorld => Mods => Help => Topic started by: ItchyFlea on June 04, 2014, 01:40:08 AM

Title: C# ThingMaker - How do I....
Post by: ItchyFlea on June 04, 2014, 01:40:08 AM
How do I tell ThingMaker to not only make a certain number of a thing, but also how do I tell it where to place said thing?

Basically I'm trying to make something where a colonist places sawdust in a hopper connected to a building, and after a set period of time, 10 units of sawdust is removed from the hopper, and 10 units of compost is placed next to the building.
Everything in my code seems to work (No errors, and the correct number of sawdust is removed from the hoppers at the correct interval, just nothing appears.)

Closest thing I know of that acts similar to what I'm trying to make is the metal smelter in IndustrialRIM.
Title: Re: C# ThingMaker - How do I....
Post by: Justin C on June 04, 2014, 02:40:59 AM
ThingMaker used to be used to spawn things into the world, but that has changed in Alpha 4. The new way of spawning things is with GenSpawn.
GenSpawn.Spawn(Thing, Location);

Just to be clear, you still have to make the items with ThingMaker first. But then you need to tell the game to actually spawn that item in the world with GenSpawn.

And in case you don't yet know how to find a place for them to spawn, you can use GenSquareFinder to find spawn points for you.
IntVec3 loc = GenSquareFinder.RandomStandableLOSSquareNear(SpawnLocationCenter, Radius);

I think that should be everything you need to know to accomplish that.
Title: Re: C# ThingMaker - How do I....
Post by: ItchyFlea on June 04, 2014, 03:58:04 AM
When it comes to C#, I quite literally know how to read/understand German better than I can read/understand code.
All the code I do make is pretty much taken directly from assembly-csharp.dll with ILSpy.

How do I get it to set the 'SpawnLocationCenter' as where the building is? I tried this.loc but it says: Keyword 'this' not available in current context.

Also, how do I get GenSpawn to make 10 of the item in one go, or will I need to have GenSpawn run 10 times?
Title: Re: C# ThingMaker - How do I....
Post by: Haplo on June 04, 2014, 04:32:03 AM
If you want to spawn a stack of resources you can do:

IntVec3 pos = this.Position;
GenSpawn.Spawn(thingDef, pos).stackCount = 10;


or in single steps

Thing thing = GenSpawn.Spawn(thingDef, this.Position);
thing.stackCount = 10;


this.Position should work as long as you call it from inside an Building class or Thing class as they always have the property Position.
Title: Re: C# ThingMaker - How do I....
Post by: ItchyFlea on June 04, 2014, 07:05:11 AM
I think this is why I should leave programming up to people who actually know what they're doing, because I'm clearly not one of those people. :)
Thank you for the help.
Title: Re: C# ThingMaker - How do I....
Post by: Justin C on June 05, 2014, 03:51:40 AM
Quote from: ItchyFlea on June 04, 2014, 07:05:11 AM
I think this is why I should leave programming up to people who actually know what they're doing, because I'm clearly not one of those people. :)
Thank you for the help.
None of us who do know what we're doing started out that way. :P

Just keep at it and you will get the hang of it.