Need help with modding

Started by Rain753, April 14, 2020, 11:47:39 AM

Previous topic - Next topic

Rain753

Hello guys! i need your help. Im working on the new event mod . I already made XML but im stuck at C# part.

here is my code :

{
    public class Incident_Worker : IncidentWorker
    {

        protected override bool TryExecuteWorker(IncidentParms parms )
        {
            IntVec3 spot;

            spot = CellFinder.RandomCell(map: Map);
           
           
           
        }
    }
}



What i want is take a random place on player map and make geyser .

LWM

Look in Verse.GenStep_ScatterThing - it's what the base game uses to place SteamGeysers.  ScatterAt() is probably what you want - look for what it does with 'thingDef' (that would be the steam geyser for you) and follow its creation.

Rain753

i can't do that , im starting to think that RimWorld modding is nearly impossible if someone that has experience didnt  explain it to you .

LWM

It's complicated, that's for sure, but it's doable.

Have you decompiled the dll?  There are instructions on the wiki, and they're still correct (the tutorial on the wiki isn't yet....)  That will get let you look at code that runs RimWorld.  Then you can go find Verse/GenStep_ScatterThing.cs and look inside (I recommend Notepad++ on Windows, but searching online can give other good options for looking at code).

Once inside GenStep_ScatterThing, you can go find the method I specified and just try reading through it (is English your 1st language?) to get a general idea.

There's a discord server for RW that's another good resource for "hey, I'm lost!"

Rain753

Quote from: LWM on April 14, 2020, 03:36:58 PM
It's complicated, that's for sure, but it's doable.

Have you decompiled the dll?  There are instructions on the wiki, and they're still correct (the tutorial on the wiki isn't yet....)  That will get let you look at code that runs RimWorld.  Then you can go find Verse/GenStep_ScatterThing.cs and look inside (I recommend Notepad++ on Windows, but searching online can give other good options for looking at code).

Once inside GenStep_ScatterThing, you can go find the method I specified and just try reading through it (is English your 1st language?) to get a general idea.

There's a discord server for RW that's another good resource for "hey, I'm lost!"


My first language isn't English but i understand it so it's not the case ( in most situations) . I decompiled the code but my question is what do i do with the code i got ? I copied it but this didnt work . How can i use it ?

let's assume that i want to create event where in some random position there is explosion and then geyser spawns . I have everything setup including random position but i dont have 
1. Explosion
2. Geyser Spawning

I just need practical version of this code which i can use , or someone who will tell me how exactly this should be transformed to the usable version.

LWM

How to use the code?  Look through it, see how vanilla RimWorld does it.

GenStep_ScatterThings.cs's ScatterAt() has some very useful bits in it:

If it needs clear space, make clear space - do you need to do that? Probably...

// Figuring out how to make a 2x2 or 4x4 square of cells is
// an exercise left to the reader
// Hint: try to find GridShapeMaker.cs and look for something useful!
foreach (IntVec3 c in My2x2or4x4 square) {
  Building edifice = c.GetEdifice(map); // get a building - probably rock
  if (edifice != null) // if it is a building (probably rock) ...
    {
      edifice.Destroy(DestroyMode.Vanish); //...destroy it!
    }
}

Then it makes the thing:

//I don't know if this works: look at MakeThing to make sure it's cool?  Or try it!   8)
//Look in ThingDefOf.cs for SteamGeyser just to make sure it's there -
// ThingDefOf gets automagically filled with correct defs.
Thing thing = ThingMaker.MakeThing(ThingDefOf.SteamGeyser, null);

Next, it checks if it's an "item" - geysers are not items, so:

GenSpawn.Spawn(thing, loc/*fill this in*/, map, rot/*Rot4.North is probably fine*/, WipeMode.Vanish, false);


Done!

Wait, you wanted an explosion first?

There's a file called DebugToolsGeneral.cs that has everything from that Debug Actions window - which includes explosions, so go find something :)

Hope that helps?

Rain753

Quote from: LWM on April 14, 2020, 05:19:06 PM
How to use the code?  Look through it, see how vanilla RimWorld does it.

GenStep_ScatterThings.cs's ScatterAt() has some very useful bits in it:

If it needs clear space, make clear space - do you need to do that? Probably...

// Figuring out how to make a 2x2 or 4x4 square of cells is
// an exercise left to the reader
// Hint: try to find GridShapeMaker.cs and look for something useful!
foreach (IntVec3 c in My2x2or4x4 square) {
  Building edifice = c.GetEdifice(map); // get a building - probably rock
  if (edifice != null) // if it is a building (probably rock) ...
    {
      edifice.Destroy(DestroyMode.Vanish); //...destroy it!
    }
}

Then it makes the thing:

//I don't know if this works: look at MakeThing to make sure it's cool?  Or try it!   8)
//Look in ThingDefOf.cs for SteamGeyser just to make sure it's there -
// ThingDefOf gets automagically filled with correct defs.
Thing thing = ThingMaker.MakeThing(ThingDefOf.SteamGeyser, null);

Next, it checks if it's an "item" - geysers are not items, so:

GenSpawn.Spawn(thing, loc/*fill this in*/, map, rot/*Rot4.North is probably fine*/, WipeMode.Vanish, false);


Done!

Wait, you wanted an explosion first?

There's a file called DebugToolsGeneral.cs that has everything from that Debug Actions window - which includes explosions, so go find something :)

Hope that helps?


Thank you so much ,you are the best really . Im really grateful that there is someone like you on this forum .
Anyway  i will check everything tommorow becauce rn im  tired  :)