Ludeon Forums

RimWorld => Mods => Help => Topic started by: Galothan on May 06, 2014, 02:45:10 AM

Title: Building produces something by itself
Post by: Galothan on May 06, 2014, 02:45:10 AM
Hello Tynan, hello Rimworld Com,

i want to ask you how to implement a building that produces something on its own.
I have understood that this might have to be implemented by a .dll.
Let's say a mining drill that mines iron every few seconds.
Maybe i have to reference the mining code so the building calls this code every few seconds and spit out something? Or something totaly different :)
Can you guide me in the right direction please? :)

Thank you.

I wonder why no one has asked this before, or i have not found the topic where this has been discussed.
Best regards from Germany, so be kind if my english isnt that good ;)
Title: Re: Building produces something by itself
Post by: Haplo on May 06, 2014, 03:14:02 AM
You can use the Ticker or TickerRare to do so.
In principle the Ticker is, when activated, a function that is called 60 times per second.
So you can do some program, that updates an internal counter every tick.
If the counter is done, call your SpawnItem-function and you have your result.
The TickerRare (or RareTicker? don't remember right now.) is called every 250 ticks.
Normally prefer this one as it doesn't need a faster counter and it will be better for the performance.
With this you can make it so that lets say coal is produced every x seconds.
And you can integrate a random counter target and don't have a fixed time :)
Title: Re: Building produces something by itself
Post by: Galothan on May 06, 2014, 03:39:16 AM
Thank you that helps alot.

How can i spawn something? Sorry but i dont know where to start here. I think i have to call a function from the core?

And how can i define where to place it.
Can i reference a tile from the builduing?
Lets say its a 3x3 tile wide building.
Maybe i can say its on a spot beside, above or ontop of it.
XXX
XXX
XXX
  O

or inside it
XXX
XXX
XOX
Title: Re: Building produces something by itself
Post by: WorldOfIllusion on May 06, 2014, 04:36:07 AM
Look at the ThingMaker class, specifically methods of its that reference spawn. As for the location, you specify that when you spawn an item (rimworld effectively uses 2 axis for the positions).
Title: Re: Building produces something by itself
Post by: lub4095 on May 06, 2014, 05:50:04 AM
Thank you for looking at this. It will be very helpful for me because I will be implementing this in my mod as well. If I manage to figure it out I will let you know. 
Title: Re: Building produces something by itself
Post by: dannyepsin on May 06, 2014, 05:56:32 AM
so basically copying industrial rims iron mine?
Title: Re: Building produces something by itself
Post by: Celthric Aysen on May 06, 2014, 06:05:07 AM
Quote from: dannyepsin on May 06, 2014, 05:56:32 AM
so basically copying industrial rims iron mine?
wow... slow down there, as long as its his code its not an exact copy.
Title: Re: Building produces something by itself
Post by: Cala13er on May 06, 2014, 06:12:14 AM
Quote from: Blackjack1000K on May 06, 2014, 06:05:07 AM
Quote from: dannyepsin on May 06, 2014, 05:56:32 AM
so basically copying industrial rims iron mine?
wow... slow down there, as long as its his code its not an exact copy.

Aye to that.
Title: Re: Building produces something by itself
Post by: Architect on May 06, 2014, 08:46:32 AM
If we are going by copying he would be 'copying' any one of several different mods :P Pretty sure there's only one way to do it anyway, something like:
ThingMaker.Spawn(ThingDef.Named("Def"), IntVec3 place);
Though I can't remember exactly, and I'm currently away from my desktop to look properly. :P
Title: Re: Building produces something by itself
Post by: Galothan on May 06, 2014, 10:03:39 AM
thank you all

ThingMaker sounds good, i will look deeper into this.

I dont want to copy industrial rim :)
Just implement something new with a similar effect.
Heck i myself dont know exactly what i want to implement, but to spawn something is realy the key to do so much things and i thought it would be nice to know. ;)