setting a max of 1 copy of an object

Started by Igabod, November 24, 2014, 07:47:53 PM

Previous topic - Next topic

Igabod

I wanted to make a mod which adds a new piece of furniture, but I only want one of them to exist on the map at a time. Is there a simple way to do this in the xml? or is it only possible through a .dll? or is it even possible at all?

JuliaEllie

#1
You need to write a Placement_Restrictor- look at the Geothermal Generator Placement_Restrictor. Its pretty simple to do basically you only have to override AcceptanceReport and return true on a special condition you want. In your case something like
if ( !Find.Map.listerThings.AllThings.Contains(ThingMaker.MakeThing(DefDatabase<ThingDef>.GetNamed("YourThing")))) { return true;} return new AcceptanceReport("Rejected because of reasons");

if this doesnt work (dont forget to use System.Linq) you can also foreach through the lister:

foreach (Thing thing in  Find.Map.listerThings.AllThings) { if (thing.def.defName.equals("YourThing") { return new AceptanceReport("Rejected be cause of reasons.. (biatch)");}} return true;

please dont paste/copy this because I wrote it from memory and might have some major errors but I hope it helps a bit to give you an idea how it "should" work

EDIT: Instead of ListerThings you can even use listerBuildings.allBuildingsColonist which is (should be) way more resource friendly.

Igabod

ugh! that's 2 projects of mine that are going to require some .dll work. I don't even know how to use visual studio and Haplo's tutorial for .dll modding is kinda useless if you can't even use visual studio. I'm going to need to seek out a partner for this. Unfortunately everybody who knows how to do .dll mods is busy with their own projects.

Thanks for the response JuliaEllie. I'm going to put this particular project on the back burner for now. Still going to continue my other project though because I'm already almost done with it. I just have to define 2 more objects and do the .dll work.

skullywag

Im sure one of us can throw you one together for this, if you get the rest of the mod running. If nobody else can, I will.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

mipen

If you send me the defname of the furniture piece, I can knock one up for you :)

Igabod

Quote from: mipen on November 26, 2014, 05:52:22 AM
If you send me the defname of the furniture piece, I can knock one up for you :)

I haven't gotten past the planning stages of that mod just yet. I posted this just to see if it was possible to do before I even get started on it. I've already talked with skullywag about it in a PM though and he agreed to do it when I get around to it. I appreciate the offer though.

I love the collaboration between modders that happens here. I have a friend who mods other games but he has a hard time finding anybody who can help him so he often sends me messages on facebook for help even though I'm not that great at scripting languages which he uses for his mods.