tModLoader Help with Custom Difficulty

unrealcodez

Terrarian
I want to add in a custom difficulty just like the Calamity mod did, but I cant figure out how to access my Custom Properties script with my Custom Boss Script to change the health and damage of it. Any help?

Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.IO;
using Terraria.ModLoader;
using Terraria.Localization;

namespace AldersMod.NPCs
{
    public class AlderBossPH : ModNPC
    {
       
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Alder");
        }

        public override void SetDefaults()
        {
            npc.aiStyle = 94;
            npc.lifeMax = 3250000;
            npc.damage = 360;
            npc.defense = 60;
            npc.knockBackResist = 0f;
            npc.width = 174;
            npc.height = 364;
            npc.boss = true;
            npc.dontTakeDamage = false;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.noGravity = true;
            npc.npcSlots = 0;
            npc.noTileCollide = true;
            NPCID.Sets.MustAlwaysDraw[npc.type] = true;
            music = MusicID.Boss2;
        }

        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 1.65f * bossLifeScale);
            npc.damage = (int)(npc.damage * 1.55f);
            npc.defense = (int)(npc.defense + (numPlayers * 1.5));
        }

        public void NightmareModeStats() //THIS WONT WORK
        {

            if (mProperties.NMM == true) { // This line doesnt work :*(
                npc.lifeMax = (int)(npc.lifeMax * 2.5f);
                npc.damage = (int)(npc.damage * 2.25f);
            }
        }

        public override void BossLoot(ref string name, ref int potiontype)
        {
            if (Main.expertMode)
            {
                potiontype = ItemID.HealingPotion;
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AldersBag"));
            }
            else
            {
                potiontype = ItemID.GreaterHealingPotion;
                if (Main.rand.Next(5) == 0)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AldersSword"));
                }
            }
        }
    }
}
 
Just a guess since I'm new to modding, but you might wanna make it "public virtual void NightmareModeStats()". That's how the other methods like SetDefaults that you override are originally coded in tmodloader.

You might wanna provide more information on what mProperties.NMM is. My guess is that there's a NMM variable in a mProperties.cs file that dictates whether Nightmare mode is active (again, only a guess). Assuming you want this mode to work like Calamity's Revengence mode, you might just want to define a variable in a class that inherits from ModPlayer so that each player's mode is kept track of. Here's a link to the file that tmodloader uses to define ModPlayer:

https://github.com/blushiemagic/tMo...es/tModLoader/Terraria.ModLoader/ModPlayer.cs

In general, only worry about the methods that start with "public virtual". Lines 105 to 120 should be just what you're looking for. Just remember to replace "virtual" with "override" when copying any methods over. One of the methods in the lines I mentioned also returns a value, so be careful. That's all I can really say for now.

Again, I'm new to this, so sorry if this doesn't work, or if I say something wrong or sound condescending.
 
I want to add in a custom difficulty just like the Calamity mod did, but I cant figure out how to access my Custom Properties script with my Custom Boss Script to change the health and damage of it. Any help?

Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.IO;
using Terraria.ModLoader;
using Terraria.Localization;

namespace AldersMod.NPCs
{
    public class AlderBossPH : ModNPC
    {
      
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Alder");
        }

        public override void SetDefaults()
        {
            npc.aiStyle = 94;
            npc.lifeMax = 3250000;
            npc.damage = 360;
            npc.defense = 60;
            npc.knockBackResist = 0f;
            npc.width = 174;
            npc.height = 364;
            npc.boss = true;
            npc.dontTakeDamage = false;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.noGravity = true;
            npc.npcSlots = 0;
            npc.noTileCollide = true;
            NPCID.Sets.MustAlwaysDraw[npc.type] = true;
            music = MusicID.Boss2;
        }

        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 1.65f * bossLifeScale);
            npc.damage = (int)(npc.damage * 1.55f);
            npc.defense = (int)(npc.defense + (numPlayers * 1.5));
        }

        public void NightmareModeStats() //THIS WONT WORK
        {

            if (mProperties.NMM == true) { // This line doesnt work :*(
                npc.lifeMax = (int)(npc.lifeMax * 2.5f);
                npc.damage = (int)(npc.damage * 2.25f);
            }
        }

        public override void BossLoot(ref string name, ref int potiontype)
        {
            if (Main.expertMode)
            {
                potiontype = ItemID.HealingPotion;
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AldersBag"));
            }
            else
            {
                potiontype = ItemID.GreaterHealingPotion;
                if (Main.rand.Next(5) == 0)
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("AldersSword"));
                }
            }
        }
    }
}
Ik this is old but, if you do still have your mod, could you send me the difficulty code? working on a mod and wanted to do one custom difficulty too (sorry if i'm breaking any rules about old posts but i need it)
 
Back
Top Bottom