A lot of questions

Started by Mmgfrcs, October 31, 2015, 11:42:11 PM

Previous topic - Next topic

Mmgfrcs

EDIT
By the way I have more questions

  • How did you create a new medicine? I created mine and it won't heal wounds
  • (C#) How to refer to a ThingDef in XML with C# and used it to refer to that object?
  • Is there a secondary weapon slot? If there is, how to set a weapon as one? If not, how to make this system?
  • How to make a food which can only be stored in the inventory? (Cannot be stored in a stockpile)
  • How to make an inventory object that can only be taken by one colonist?
Be patient with me guys...

Fluffy (l2032)

#1
Use CCL.

edit: OP changed the question, original answer was to a different question.

Mmgfrcs

CCL wouldn't be an option for my independent mod (where all useful mod were packed together at a cost of functionality) except if it can be extracted independently
I don't get the code either as there's no call of the source ThingDef and target ThingDef

SlimeCrusher

You can try checking the code behind ship cryptosleep caskets, as you must place them adjacent to a ship beam, or maybe the hopper's placeworker. Any of those 2 should be a good start.

Rikiki

I have written some custom place workers in my mods.
A good example would be the "M&Co. Alert speaker" which must be placed near a wall (natural or not).

1)Look at the code in the attached file.
2)Here is the code of the referenced CheckIfSupportingWallIsAlive function:

        /// <summary>
        /// Checks if the wall supporting the alert speaker is still alive.
        /// </summary>
        public static bool CheckIfSupportingWallIsAlive(IntVec3 alertSpeakerPosition, Rot4 alertSpeakerRotation)
        {
            IntVec3 wallPosition = alertSpeakerPosition + new IntVec3(0, 0, -1).RotatedBy(alertSpeakerRotation);
           
            // Built wall.
            if (Find.ThingGrid.ThingAt(wallPosition, ThingDefOf.Wall) != null)
            {
                return true;
            }

            // Natural block.
            Thing potentialWall = Find.ThingGrid.ThingAt(wallPosition, ThingCategory.Building);
            if (potentialWall != null)
            {
                if ((potentialWall as Building).def.building.isNaturalRock)
                {
                    return true;
                }
            }
            // No wall.
            return false;
        }
       

3) Don't forget to tell your object to use your custom place worker like this:

  <ThingDef ParentName="BuildingBase">
    <defName>AlertSpeaker</defName>
[...]
    <placeWorkers>
      <li>AlertSpeaker.PlaceWorker_AlertSpeaker</li>
    </placeWorkers>
[...]
  </ThingDef>


[attachment deleted due to age]

Mmgfrcs

#5
Thanks Rikiki, I'll look into more depth of that
EDIT Just found something interesting: The target object is custom, so it didn't have a ThingDefOf to change with

Latta

Use:

ThingDef.Named("Your ThingDef's ID");
//example
ThingDef.Named("Building_SomethingAwesome");

Mmgfrcs

That's awesome! Problem solved for #2!

RawCode

#1 provide your medicine def, cos proper def should be picked by internal routine without any issues.

Typesafe variant for #2
class tz = DefDatabase<class>.GetNamed("name");

3\4\5# there is NO limits, you can make anything, ever first person shooter, sadly you can't make it by flipping single boolean inside XML file, you must write custom implementation self.

This question have same level as "how to drive car?" -
"read carefully local state traffic rules (read c# book),
read auto manual (unity3d manual),
decide you destination (draw some plan),
check area map (read RimWorld source) ,
use wheel and pedals carefully and drive to your destination (write your code).

If you hit something (or someone), call 911 (post on forum with source code included and issue explained).

Mmgfrcs

#9
Quote from: RawCode on November 11, 2015, 10:40:40 AM
#1 provide your medicine def, cos proper def should be picked by internal routine without any issues.

Code for new Medicine
<ThingDef ParentName="ResourceBase">
    <defName>IntensiveMedKit</defName>
    <label>Intensive medical kit</label>
    <description>A medicine with a greater potency than a regular medicine, made by combining herbal medicine with ordinary medicine.</description>
    <graphicData>
      <texPath>Things/Item/Resource/IMK</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>Silver_Drop</soundInteract>
    <soundDrop>Silver_Drop</soundDrop>
    <statBases>
      <MaxHitPoints>180</MaxHitPoints>
      <MarketValue>115</MarketValue>
      <MedicalPotency>1.15</MedicalPotency>
    </statBases>
    <stackLimit>10</stackLimit>
    <thingCategories>
      <li>Manufactured</li>
      <li>Medicine</li>
    </thingCategories>
  </ThingDef>


The medicine was regarded successfully as means of healing, but colonists are just standing when they just heal wounds, without healing the wounds itself

Quote from: RawCode on November 11, 2015, 10:40:40 AM
3\4\5# there is NO limits, you can make anything, ever first person shooter, sadly you can't make it by flipping single boolean inside XML file, you must write custom implementation self.

This question have same level as "how to drive car?" -
"read carefully local state traffic rules (read c# book),
read auto manual (unity3d manual),
decide you destination (draw some plan),
check area map (read RimWorld source) ,
use wheel and pedals carefully and drive to your destination (write your code).

If you hit something (or someone), call 911 (post on forum with source code included and issue explained).

I asked the question because I'm stuck already on starting, how could I provide source codes? I don't even know what code should I put in
Manuals are technical and there's no manual for RimWorld C# (unless if you can provide one)
Nothing in the Defs said about Inventory and C# only provide means of detecting inventory items

Fluffy (l2032)

There's no RW C#. C# is a general purpose language, used in a lot of software (and games). There's plenty of help resources online.

The RW wiki has some articles to get you started on C#/dll modding, there's also a tutorial on this forum. I'ld suggest you start there, and try to work your way up. As it stands, you might as well ask for a mod in the suggestions forum - because you're basically asking people to do it for you - this is not the point of the help subforum.

Make sure to get a decompiler so you can take a look at the vanilla code and other mod's code (ILSpy does the job and is free). A good IDE will make your life a lot easier as well, most of the code in the game has rather descriptive names that work great with intelliSense.

Once you've tried to actually make it work yourself and have a specific problem you need help with, we might be able to give you an actual answer.

RawCode

You must try self before asking for help.

ps. remove Manufactured tag


Mmgfrcs

Right... I tried it and immediately scrapped it as all non-inventory objects are then no longer haulable
The code? exactly the same as the Core but a tag is added: <canBeSpawningInventory> (XML)
In C# i found a member called PutCarriedThingInInventory, but I don't think this is the solution
public static Toil PutCarriedThingInInventory()
{
Toil toil = new Toil();
toil.initAction = delegate
{
Pawn actor = toil.GetActor();
if (actor.carrier.CarriedThing != null)
{
if (actor.inventory.container.TryAdd(actor.carrier.CarriedThing))
{
actor.carrier.container.Clear();
}
else
{
Thing thing;
actor.carrier.TryDropCarriedThing(actor.Position, actor.carrier.CarriedThing.stackCount, ThingPlaceMode.Near, out thing);
}
}
};
return toil;
}


I learned by doing; never in this post I mentioned for you to do this for me. That's why it's in Help, not Suggestions
What I'm asking for is a clue to the solution like

  • XML-Only or C# override required?
  • If C# override required, what C# class governed this?
  • Can all types of objects behave the same with the same code?
  • Is there any additional functionalities I needed to code for this to work?
When I got permanently stuck in coding, that's the time I'll link this into Suggestions
Before that time arrived, no
For the DIY and 'make it work yourself' part, I'll try to do that, but I begged for clues right now

RawCode

please define your understanding of "Inventory", since there is no chests in RimWorld, if you disallow storing food in stockpiles, there is no way to store it at all.