How to add a new MentalStateDefoF from the static class

Started by Instill, May 31, 2016, 09:47:15 PM

Previous topic - Next topic

Instill

Hi

How can i add a new MentalStateOf in the static class MentalStateOf

Quotenamespace RimWorld
{
   public static class MentalStateDefOf
   {
      public static MentalStateDef Berserk;

      public static MentalStateDef DazedWander;

      public static MentalStateDef BingingAlcohol;

      public static MentalStateDef PanicFlee;

      public static MentalStateDef Manhunter;

      public static MentalStateDef ManhunterPermanent;

      public static MentalStateDef SocialFighting;

      public static MentalStateDef GiveUpExit;

                (-- New def here --)

      public static void RebindDefs()
      {
         DefOfHelper.BindDefsFor<MentalStateDef>(typeof(MentalStateDefOf));
      }
   }
pawn.mindState.mentalStateStarter.TryStartMentalState(MentalStateDefOf.-- My new def here --);

thank :P

nethrez1m

#1
IIRC, you don't have to change the original static container of Defs and you can make your own class in your dll with your Defs.


using Verse;
using RimWorld;

namespace MyAwesomeMod
{

  public static class MyMentalStatesDefOf
  {

    public static MentalStateDef Awesomeness;

    public static MentalStateDef NotBeingAwesome;      // Defs, the names should be the same as in your xmls;

    public static void DefBinder()     // Remember to call this method from somewhere you initialize your mod so DefOfHelper will do its magic;
    {
        DefOfHelper.BindDefsFor<MentalStateDef>( typeof( MyMentalStatesDefOf ) );
    }

  }

}


Something like that worked for me when I tried to fool around the bodyparts. Sadly, there was no further use for it and I deleted that solution. But I'm kalmost sure that with that static defof container you can do the same things you can with the original defof container class.

add: And then you can pawn.mindState.mentalStateStarter.TryStartMentalState(MyAwesomeMod.MyMentalStatesDefOf.NotBeingAwesome);

1000101

Of course, you'll need to set MyAwesomeMod.MyMentalStatesDefOf.NotBeingAwesome at some point

MyAwesomeMod.MyMentalStatesDefOf.NotBeingAwesome = DefDatabase<MentalStateDef.GetNamed( "NotBeingAwesome" );

Where "NotBeingAwesome" is the defName of your MentalStateDef.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By

Fluffy (l2032)

I presume that's the  DefOfHelper.BindDefsFor part, E

1000101

Der, I was tired when I wrote that.  I read it then immediately forgot it.

So...shush me...
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By