New to modding - need help

Started by Rain753, April 13, 2020, 01:09:32 PM

Previous topic - Next topic

Rain753

So i'm new to the modding in Rimworld and for the start of my "career"  i wanted to complete PlagueGun Guide. I copied whole file ( first i wanted to see how it works in game ) but it didn't work . In console it said something about Messages so i deleted them because i didn't know the solution for this . It worked but there is still one error that keeps spamming in console :

Exception ticking TST_Bullet_PlagueGun38080 (at (141, 0, 126)): System.MissingMethodException: string Verse.TranslatorFormattedStringExtensions.Translate(string,Verse.NamedArgument,Verse.NamedArgument)


and here is the rest of the console things ( i dont really know what is this but it appears when i click on the error)
  at Verse.Projectile.ImpactSomething () [0x0014f] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.Projectile.Tick () [0x000ed] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.TickList.Tick () [0x0015c] in <c8e8d421567e4ee5864626a429a27a37>:0
Verse.Log:Error(String, Boolean)
Verse.TickList:Tick()
Verse.TickManager:DoSingleTick()
Verse.TickManager:TickManagerUpdate()
Verse.Game:UpdatePlay()
Verse.Root_Play:Update()

Here is my XML code

<?xml version="1.0" encoding="utf-8" ?>
<Defs>

    <!-- The Class="Plague.ThingDef_PlagueBullet links this XML Def to a Class. -->
    <!-- Our class is named ThingDef_PlagueBullet, and is found in the Plague namespace." -->
    <!-- Tags with an empty comment behind them are changed from their original values. -->

    <ThingDef Class="Plague.ThingDef_PlagueBullet" ParentName="BaseBullet">
        <defName>TST_Bullet_PlagueGun</defName> <!-- -->
        <label>plague bullet</label> <!-- -->
        <graphicData>
            <texPath>Things/Projectile/Bullet_Small</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <projectile>
            <flyOverhead>false</flyOverhead>
            <damageDef>Bullet</damageDef>
            <damageAmountBase>12</damageAmountBase>
            <stoppingPower>1</stoppingPower>
            <speed>55</speed>
        </projectile>
        <!-- The below three lines are added for the C# portion of the mod. -->
        <AddHediffChance>0.05</AddHediffChance>
        <HediffToAdd>Plague</HediffToAdd>
        <thingClass>Plague.Projectile_PlagueBullet</thingClass>
    </ThingDef>

    <ThingDef ParentName="BaseHumanMakeableGun">
        <defName>TST_Gun_PlagueGun</defName> <!-- -->
        <label>plague gun</label> <!-- -->
        <description>A curious weapon notable for its horrible health effects.</description> <!-- -->
        <graphicData>
            <texPath>Things/Item/Equipment/WeaponRanged/Revolver</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <soundInteract>Interact_Revolver</soundInteract>
        <statBases>
            <WorkToMake>4000</WorkToMake>
            <Mass>1.4</Mass>
            <AccuracyTouch>0.80</AccuracyTouch>
            <AccuracyShort>0.75</AccuracyShort>
            <AccuracyMedium>0.45</AccuracyMedium>
            <AccuracyLong>0.35</AccuracyLong>
            <RangedWeapon_Cooldown>1.6</RangedWeapon_Cooldown>
        </statBases>
        <weaponTags>
            <li>SimpleGun</li>
            <li>Revolver</li>
        </weaponTags>
        <costList>
            <Steel>30</Steel>
            <ComponentIndustrial>2</ComponentIndustrial>
        </costList>
        <recipeMaker>
            <skillRequirements>
                <Crafting>3</Crafting>
            </skillRequirements>
        </recipeMaker>
        <verbs>
            <li>
                <verbClass>Verb_Shoot</verbClass>
                <hasStandardCommand>true</hasStandardCommand>
                <defaultProjectile>TST_Bullet_PlagueGun</defaultProjectile> <!-- -->
                <warmupTime>0.3</warmupTime>
                <range>25.9</range>
                <soundCast>Shot_Revolver</soundCast>
                <soundCastTail>GunTail_Light</soundCastTail>
                <muzzleFlashScale>9</muzzleFlashScale>
            </li>
        </verbs>
        <tools>
            <li>
                <label>grip</label>
                <capacities>
                    <li>Blunt</li>
                </capacities>
                <power>9</power>
                <cooldownTime>2</cooldownTime>
            </li>
            <li>
                <label>barrel</label>
                <capacities>
                    <li>Blunt</li>
                    <li>Poke</li>
                </capacities>
                <power>9</power>
                <cooldownTime>2</cooldownTime>
            </li>
        </tools>
    </ThingDef>
</Defs>



And here C# code :

amespace Plague
{
    public class Projectile_PlagueBullet : Bullet
    {
        #region Properties
        public ThingDef_PlagueBullet Def;
       
        #endregion

        #region Overrides
        protected override void Impact(Thing hitThing)
        {
            /* This is a call to the Impact method of the class we're inheriting from.
             * You can use your favourite decompiler to see what it does, but suffice to say
             * there are useful things in there, like damaging/killing the hitThing.
             */
            base.Impact(hitThing);

            /*
             * Null checking is very important in RimWorld.
             * 99% of errors reported are from NullReferenceExceptions (NREs).
             * Make sure your code checks if things actually exist, before they
             * try to use the code that belongs to said things.
             */
            if (Def != null && hitThing != null && hitThing is Pawn hitPawn) //Fancy way to declare a variable inside an if statement. - Thanks Erdelf.
            {



                //This checks to see if the character has a heal differential, or hediff on them already.
                var plagueOnPawn = hitPawn.health.hediffSet.GetFirstHediffOfDef(Def.HediffToAdd);
                var randomSeverity = Rand.Range(0.15f, 0.30f);
                    if (plagueOnPawn != null)
                    {
                        //If they already have plague, add a random range to its severity.
                        //If severity reaches 1.0f, or 100%, plague kills the target.
                        plagueOnPawn.Severity += randomSeverity;
                    }
                    else
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hediff.Severity = randomSeverity;
                        hitPawn.health.AddHediff(hediff);
                    }
                }
               
            }
        }
        #endregion Overrides
    }






Like i  said i deleted some stuff cause  when it was there it was creating errors and i just don't need those messages .


So guys , if you could tell me what i did wrong or maybe ( it would be a dream honestly ) rewrite the  PlagueGun guide because it seems outdated i would be really gratefull because  there aren't any  working guides on how to make mods in this great game .



LWM

Has that tutorial been udpated to 1.1?  Does it specify C# .Net 3.5 or 4.7.2?

Rain753

#2
Quote from: LWM on April 13, 2020, 01:25:20 PM
Has that tutorial been udpated to 1.1?  Does it specify C# .Net 3.5 or 4.7.2?
I think it's not updated to 1.1 . It specify .Net 3.5.
I know that i could just use Rimworld 1.0 or something but i don't see a point in doing that because mods will be outdated and no one will use them .


Link for the PlagueGun guide :
https://ludeon.com/forums/index.php?topic=33219.0

LWM

Okay!

Well, that's the first problem you're going to run into there ><

In the RimWorld folder on your computer, there's a text document on updating mods (ModUpdating.txt) - that covers the basics of what needs to be updated...most importantly, switch to 4.7.2.

Rain753

Quote from: LWM on April 13, 2020, 01:35:53 PM
Okay!

Well, that's the first problem you're going to run into there ><

In the RimWorld folder on your computer, there's a text document on updating mods (ModUpdating.txt) - that covers the basics of what needs to be updated...most importantly, switch to 4.7.2.

I already switched to 4.7.2 and  i think it's not the version issue  but the coding issue . Im saying this because everything compiles and i don't have any errors when loading the mod .  If im wrong tell me please . I spent 8 hours today on trying to fix that so im pretty tired  .
I wrote to so many  people today that ehh...  the fact that english is not my first language complicates everything twice or more :c

If someone have any idea please write it down here .

LWM

What your native language?


Exception ticking TST_Bullet_PlagueGun38080 (at (141, 0, 126)): System.MissingMethodException: string Verse.TranslatorFormattedStringExtensions.Translate(string,Verse.NamedArgument,Verse.NamedArgument)
  at Verse.Projectile.ImpactSomething () [0x0014f] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.Projectile.Tick () [0x000ed] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.TickList.Tick () [0x0015c] in <c8e8d421567e4ee5864626a429a27a37>:0
Verse.Log:Error(String, Boolean)
Verse.TickList:Tick()
Verse.TickManager:DoSingleTick()
Verse.TickManager:TickManagerUpdate()
Verse.Game:UpdatePlay()
Verse.Root_Play:Update()


What that tells us is that there was an Exception "Tick"ing (tick as in "clock ticks"), where it couldn't find a method.  It happened when the projectile hit something (ImpactSomething), as the projectile was flying along (Tick), during the game's normal play (everything below that).

That's a really weird error, but it appears the error happened in "Verse.Projectile.ImpactSomething" - which implies it happened in "base.Impact(hitThing)"?  But there is no call to "Translate()" there?

Which is weird.

The weirdness of the error (and the type of error) makes me say:  make sure you are compiling against the correct version of RimWorld?

The other thing the weirdness makes me say: "Did you lose a line of the 'at Verse.....'"?

And also "What were the other errors before you deleted them?  They might have been important?"

The final bit of advice I would have:

namespace Plague
{
    public class Projectile_PlagueBullet : Bullet
    {
        #region Properties
        public ThingDef_PlagueBullet Def;
       
        #endregion

        #region Overrides
        protected override void Impact(Thing hitThing)
        {
Log.Message("Plague bullet just impacted something: "+(hitThing!=null?hitThing.ToString():"NULL OBJECT"));
            /* This is a call to the Impact method of the class we're inheriting from.
             * You can use your favourite decompiler to see what it does, but suffice to say
             * there are useful things in there, like damaging/killing the hitThing.
             */
            base.Impact(hitThing);
Log.Message("Base Impact finished, now applying special effects");
            /*
             * Null checking is very important in RimWorld.
             * 99% of errors reported are from NullReferenceExceptions (NREs).
             * Make sure your code checks if things actually exist, before they
             * try to use the code that belongs to said things.
             */
            if (Def != null && hitThing != null && hitThing is Pawn hitPawn) //Fancy way to declare a variable inside an if statement. - Thanks Erdelf.
            {
Log.Message("Plague bullet hit pawn "+hitPawn); // keep adding log messages, then see where it breaks.


                //This checks to see if the character has a heal differential, or hediff on them already.
                var plagueOnPawn = hitPawn.health.hediffSet.GetFirstHediffOfDef(Def.HediffToAdd);
                var randomSeverity = Rand.Range(0.15f, 0.30f);
                    if (plagueOnPawn != null)
                    {
                        //If they already have plague, add a random range to its severity.
                        //If severity reaches 1.0f, or 100%, plague kills the target.
                        plagueOnPawn.Severity += randomSeverity;
                    }
                    else
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hediff.Severity = randomSeverity;
                        hitPawn.health.AddHediff(hediff);
                    }
                }
               
            }
        }
        #endregion Overrides
    }


Haplo

Normally this error occures if you've compiled your source against the RimWorld 1.0 dll and use the result in RimWorld 1.1.
Make sure that your assigned Assembly-CSharp.dll is of version 1.1.xxx and not 1.0.xxx.

Rain753

Quote from: LWM on April 13, 2020, 03:05:12 PM
What your native language?


Exception ticking TST_Bullet_PlagueGun38080 (at (141, 0, 126)): System.MissingMethodException: string Verse.TranslatorFormattedStringExtensions.Translate(string,Verse.NamedArgument,Verse.NamedArgument)
  at Verse.Projectile.ImpactSomething () [0x0014f] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.Projectile.Tick () [0x000ed] in <c8e8d421567e4ee5864626a429a27a37>:0
  at Verse.TickList.Tick () [0x0015c] in <c8e8d421567e4ee5864626a429a27a37>:0
Verse.Log:Error(String, Boolean)
Verse.TickList:Tick()
Verse.TickManager:DoSingleTick()
Verse.TickManager:TickManagerUpdate()
Verse.Game:UpdatePlay()
Verse.Root_Play:Update()


What that tells us is that there was an Exception "Tick"ing (tick as in "clock ticks"), where it couldn't find a method.  It happened when the projectile hit something (ImpactSomething), as the projectile was flying along (Tick), during the game's normal play (everything below that).

That's a really weird error, but it appears the error happened in "Verse.Projectile.ImpactSomething" - which implies it happened in "base.Impact(hitThing)"?  But there is no call to "Translate()" there?

Which is weird.

The weirdness of the error (and the type of error) makes me say:  make sure you are compiling against the correct version of RimWorld?

The other thing the weirdness makes me say: "Did you lose a line of the 'at Verse.....'"?

And also "What were the other errors before you deleted them?  They might have been important?"

The final bit of advice I would have:

namespace Plague
{
    public class Projectile_PlagueBullet : Bullet
    {
        #region Properties
        public ThingDef_PlagueBullet Def;
       
        #endregion

        #region Overrides
        protected override void Impact(Thing hitThing)
        {
Log.Message("Plague bullet just impacted something: "+(hitThing!=null?hitThing.ToString():"NULL OBJECT"));
            /* This is a call to the Impact method of the class we're inheriting from.
             * You can use your favourite decompiler to see what it does, but suffice to say
             * there are useful things in there, like damaging/killing the hitThing.
             */
            base.Impact(hitThing);
Log.Message("Base Impact finished, now applying special effects");
            /*
             * Null checking is very important in RimWorld.
             * 99% of errors reported are from NullReferenceExceptions (NREs).
             * Make sure your code checks if things actually exist, before they
             * try to use the code that belongs to said things.
             */
            if (Def != null && hitThing != null && hitThing is Pawn hitPawn) //Fancy way to declare a variable inside an if statement. - Thanks Erdelf.
            {
Log.Message("Plague bullet hit pawn "+hitPawn); // keep adding log messages, then see where it breaks.


                //This checks to see if the character has a heal differential, or hediff on them already.
                var plagueOnPawn = hitPawn.health.hediffSet.GetFirstHediffOfDef(Def.HediffToAdd);
                var randomSeverity = Rand.Range(0.15f, 0.30f);
                    if (plagueOnPawn != null)
                    {
                        //If they already have plague, add a random range to its severity.
                        //If severity reaches 1.0f, or 100%, plague kills the target.
                        plagueOnPawn.Severity += randomSeverity;
                    }
                    else
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hediff.Severity = randomSeverity;
                        hitPawn.health.AddHediff(hediff);
                    }
                }
               
            }
        }
        #endregion Overrides
    }







Ok so my native language is Polish .  Altought i checked the version once , i will do this again , if it will be correct i will use your  code and i will tell you if anything happens.

Rain753

Bruh

it's for  1.0

...

8 hours of work



my life...



Okey guys im just dumb . I have last question . Are there any plaguegun-like mods available on the internet? i didnt find anything like that

LWM

I think you are looking at the only one...

...

Feel free to update the wiki as you think appropriate!

Rain753

Quote from: LWM on April 13, 2020, 05:05:40 PM
I think you are looking at the only one...

...

Feel free to update the wiki as you think appropriate!

Maybe in the future , remember that you are talking to the guy that was figuring out that he has wrong version of the game for 8 hours :)

LWM