tModLoader Official tModLoader Help Thread

New to coding guys. I am making a Pet and I have the actual pet coded correctly, but the summon item and buff codes keep giving me an error and I can't figure it out.
It keeps telling me the tooltip, bufftip and name definitions don't exist. If anyone knows what I'm am doing wrong , I'd appreciate the help.

View attachment 183670 View attachment 183671
Look at examplemod. Where did you get that code? it's outdated and should be avoided.
 
Another Issue....Ive been stuck on this for 2 hours and I cant figure it out. I know its something small too but i cant find it.
 

Attachments

  • Screenshot (36).png
    Screenshot (36).png
    144 KB · Views: 132
  • Screenshot (34).png
    Screenshot (34).png
    146.2 KB · Views: 136
  • Screenshot (37).png
    Screenshot (37).png
    127.1 KB · Views: 109
  • Screenshot (35).png
    Screenshot (35).png
    138.5 KB · Views: 118
  • Screenshot (38).png
    Screenshot (38).png
    134.2 KB · Views: 119
  • Screenshot (30).png
    Screenshot (30).png
    151.9 KB · Views: 139
  • Screenshot (31).png
    Screenshot (31).png
    142.9 KB · Views: 123
  • Screenshot (32).png
    Screenshot (32).png
    140.2 KB · Views: 104
  • Screenshot (33).png
    Screenshot (33).png
    149 KB · Views: 118
  • Screenshot (40).png
    Screenshot (40).png
    498 KB · Views: 184
Another Issue....Ive been stuck on this for 2 hours and I cant figure it out. I know its something small too but i cant find it.
Your error has nothing to do with code, it has to do with the fact that tmodloader can't guess where your texture files is. Click that Open Web Help button and read carefully.
 
Another Issue....Ive been stuck on this for 2 hours and I cant figure it out. I know its something small too but i cant find it.
Make sure that all the names are constant for the files/classes. I got stuck on it for a few hours before I realized I was missing an 'i' in a class name.
 
I went through and made sure I had the textures correctly named and in the right locations. I even renamed some of the folders just to make sure the folder names weren't somehow conflicting with it. I also made sure all the class namespaces were spelled correctly, but I still get the error.

Note: I also completely removed the SoulofFire from the Items folder and tried it but it did the same error with the SoulofIce item as well.
 
I need a bit of help. I want a boss NPC to drop a ore, but not just one. somewhere in the 30-50 range. How does one do that?

Here is my code:

Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
//By Al0n37      www.youtube.com/Al0n37
namespace OddsAndEnds.NPCs.MegaHarpy
{
    public class MegaHarpy : ModNPC
    {

    public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("The Mega Harpy");
            Main.npcFrameCount[npc.type] = 4;
        }

        public override void SetDefaults()
        {
            npc.aiStyle = 14;  //5 is the flying AI
            npc.lifeMax = 3000;   //boss life
            npc.damage = 38;  //boss damage
            npc.defense = 7;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 80;
            npc.height = 52;
            animationType = NPCID.Harpy;
            aiType = NPCID.Harpy;        //this boss will behavior like the DemonEye
            npc.value = Item.buyPrice(0, 40, 75, 45);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit8;
            npc.DeathSound = SoundID.NPCDeath8;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SkyOre"), 30-50); //Here

            if (Main.rand.Next(3) == 0) // For items that you want to have a chance to drop
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SkyBar"), 5-10); //And Here
                }

        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.65f * bossLifeScale);  //boss life scale in expertmode
            npc.damage = (int)(npc.damage * 0.7f);  //boss damage increase in expermode
        }
        public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;
            npc.ai[1]++;
            if (npc.ai[1] >= 230)  // 230 is projectile fire rate
            {
                float Speed = 20f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 32;  //projectile damage
                int type = mod.ProjectileType("AirBlast");  //put your projectile
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
           
            if (npc.ai[0] % 600 == 0)  //Npc spown rate
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("Zumbie"));  //NPC name
            }

            if (npc.life <= 2000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
        }
  
    }
}
 
I need a bit of help. I want a boss NPC to drop a ore, but not just one. somewhere in the 30-50 range. How does one do that?

Here is my code:

Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
//By Al0n37      www.youtube.com/Al0n37
namespace OddsAndEnds.NPCs.MegaHarpy
{
    public class MegaHarpy : ModNPC
    {

    public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("The Mega Harpy");
            Main.npcFrameCount[npc.type] = 4;
        }

        public override void SetDefaults()
        {
            npc.aiStyle = 14;  //5 is the flying AI
            npc.lifeMax = 3000;   //boss life
            npc.damage = 38;  //boss damage
            npc.defense = 7;    //boss defense
            npc.knockBackResist = 0f;
            npc.width = 80;
            npc.height = 52;
            animationType = NPCID.Harpy;
            aiType = NPCID.Harpy;        //this boss will behavior like the DemonEye
            npc.value = Item.buyPrice(0, 40, 75, 45);
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.HitSound = SoundID.NPCHit8;
            npc.DeathSound = SoundID.NPCDeath8;
            npc.buffImmune[24] = true;
            music = MusicID.Boss2;
            npc.netAlways = true;
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.HealingPotion;   //boss drops
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SkyOre"), 30-50); //Here

            if (Main.rand.Next(3) == 0) // For items that you want to have a chance to drop
                {
                    Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SkyBar"), 5-10); //And Here
                }

        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax = (int)(npc.lifeMax * 0.65f * bossLifeScale);  //boss life scale in expertmode
            npc.damage = (int)(npc.damage * 0.7f);  //boss damage increase in expermode
        }
        public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;
            npc.ai[1]++;
            if (npc.ai[1] >= 230)  // 230 is projectile fire rate
            {
                float Speed = 20f;  //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 32;  //projectile damage
                int type = mod.ProjectileType("AirBlast");  //put your projectile
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
        
            if (npc.ai[0] % 600 == 0)  //Npc spown rate
            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("Zumbie"));  //NPC name
            }

            if (npc.life <= 2000)  //when the boss has less than 70 health he will do the charge attack
                npc.ai[2]++;                //Charge Attack
            if (npc.ai[2] >= 20)
            {
                npc.velocity.X *= 0.98f;
                npc.velocity.Y *= 0.98f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width * 0.5f), npc.position.Y + (npc.height * 0.5f));
                {
                    float rotation = (float)Math.Atan2((vector8.Y) - (Main.player[npc.target].position.Y + (Main.player[npc.target].height * 0.5f)), (vector8.X) - (Main.player[npc.target].position.X + (Main.player[npc.target].width * 0.5f)));
                    npc.velocity.X = (float)(Math.Cos(rotation) * 12) * -1;
                    npc.velocity.Y = (float)(Math.Sin(rotation) * 12) * -1;
                }
                //Dust
                npc.ai[0] %= (float)Math.PI * 2f;
                Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
                Main.PlaySound(2, (int)npc.position.X, (int)npc.position.Y, 20);
                npc.ai[2] = -300;
                Color color = new Color();
                Rectangle rectangle = new Rectangle((int)npc.position.X, (int)(npc.position.Y + ((npc.height - npc.width) / 2)), npc.width, npc.width);
                int count = 30;
                for (int i = 1; i <= count; i++)
                {
                    int dust = Dust.NewDust(npc.position, rectangle.Width, rectangle.Height, 6, 0, 0, 100, color, 2.5f);
                    Main.dust[dust].noGravity = false;
                }
                return;
            }
        }

    }
}
Right now you are dropping 30 minus 50 bars, which would amount to -20 bars. That's not going to work. ;)

The easiest way to do this is to drop 30 bars plus a random amount between 0 and 20, which would give you your desired range. To do this, replace the 30 - 50 with this:
Code:
30 + Main.rand.Next(21)

The 21 is exclusive, so it will generate a maximum of 20 extra ore.

Same principle for your bars:
Code:
5 + Main.rand.Next(6)

Let me know if this works for you. ;)
 
I need help.
I've googled and googled and can't find this out. I want a custom tile to be able to convert nearby tiles into itself, or "spread", like corruption and crimson blocks. I have attempted to make it spread but it's not working..
Here's the code.

Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace Erilipah.Tiles
{
    public class ShadaineStone : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolid[Type] = true;
            Main.tileMergeDirt[Type] = true;
            Main.tileBlockLight[Type] = true;  //true for block to emit light
            Main.tileLighted[Type] = true;
            drop = mod.ItemType("ShadaineStone");   //put your CustomBlock name
            AddMapEntry(new Color(10, 10, 15));
            mineResist = 1f;
            minPick = 100;
            soundType = 21;
            soundStyle = 2;
        }

      public virtual void RandomUpdate(int i, int j)
        {
            int X = i + Main.rand.Next(-1, 1);
            int Y = i + Main.rand.Next(-1, 1);
            WorldGen.Convert(X, Y, mod.TileType("ShadaineStone"));
            /// <param name="i">The x position in tile coordinates.</param>
            /// <param name="j">The y position in tile coordinates.</param>
        }


        public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b)   //light colors
        {
            r = 0f;
            g = 0f;
            b = 0f;
        }
    }
}
 
Last edited:
Hello and good time of day.
Its possible to turn on Old One's Army event rules for normal game outside of event?

Or create guard npc.
Searching the ways to do tower defence survival.

Found a way to boost monster spawn rates. Though it need to be applied only during the night.
In addition that will be fine is it possible to spawn monsters near player if area not lighted.

Found a tutorial how to do custom sentry. Though with current sentry state outside of event this is not an option.
And seems mobs here cant attack blocks like mobs in DigOrDie.
 
I need help on this:

I want to make a gun, but I want to be able to control the amount of bullets it shoots per trigger pull and how frequently. Can someone please help?
 
TmodLoader stopped working! HELP!
Every time TmodLoader says "Setting Up..." it crashes right before it can finish. I looked in the logs and found the following.
Code:
Parameter name: sampleRate   at Microsoft.Xna.Framework.Audio.DynamicSoundEffectInstance..ctor(Int32 sampleRate, AudioChannels channels)

If you have any help, please tell me. I have Steam Terraria.
view

view
 
Last edited:
Right now you are dropping 30 minus 50 bars, which would amount to -20 bars. That's not going to work. ;)

The easiest way to do this is to drop 30 bars plus a random amount between 0 and 20, which would give you your desired range. To do this, replace the 30 - 50 with this:
Code:
30 + Main.rand.Next(21)

The 21 is exclusive, so it will generate a maximum of 20 extra ore.

Same principle for your bars:
Code:
5 + Main.rand.Next(6)

Let me know if this works for you. ;)

So sorry I didn't reply sooner, I was on a camping trip. Thanks a lot for the help, It worked perfectly! Thank you.
 
Is it possible for worldgen to replace EVERY time it finds a stone for another block (Stone would be unobtainable)

Help
[doublepost=1506333896,1506333629][/doublepost]HELP??

HELP??? :mad:
[doublepost=1506335432,1506334965][/doublepost]I NEED HELP!!! :mad: :mad:
 
Last edited by a moderator:
hi, i keep getting this error when i try launching my mod:

c:\Users\John\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Mharadium.cs(15,18) : error CS0117: 'Terraria.Main' does not contain a definition for 'buffName'

c:\Users\John\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Mharadium.cs(17,18) : error CS0117: 'Terraria.Main' does not contain a definition for 'buffTip'

i have this code:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace MyMod.Items
{
public class Mharadium : ModBuff
{

public override void SetDefaults()
{
Main.buffName[Type] = "Mharadium";
Main.buffNoTimeDisplay[Type] = true;
Main.buffTip[Type] = "You have a weird feeling, it may be the radioactivity";
Main.buffNoSave[Type] = true;
Main.debuff[Type] = true;
this.canBeCleared = false;
}
}
}
 
hi, i keep getting this error when i try launching my mod:

c:\Users\John\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Mharadium.cs(15,18) : error CS0117: 'Terraria.Main' does not contain a definition for 'buffName'

c:\Users\John\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\Mharadium.cs(17,18) : error CS0117: 'Terraria.Main' does not contain a definition for 'buffTip'

i have this code:

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace MyMod.Items
{
public class Mharadium : ModBuff
{

public override void SetDefaults()
{
Main.buffName[Type] = "Mharadium";
Main.buffNoTimeDisplay[Type] = true;
Main.buffTip[Type] = "You have a weird feeling, it may be the radioactivity";
Main.buffNoSave[Type] = true;
Main.debuff[Type] = true;
this.canBeCleared = false;
}
}
}
buffName and buffTip are deprecated. Refer to this example for how to assign names and tooltips to your buffs.
 
Very green and new to modding. I've already spent a decent amount of time searching all over for this with no luck. Here Goes:

Goal = Make the player disappear when riding a certain mount. Disappear visually.
Help = What class/method would I use to make the player invisible? I've tried invis and stealth but they affect the mount. A couple of draw methods have done me no good.

Thanks in advance!
 
Very green and new to modding. I've already spent a decent amount of time searching all over for this with no luck. Here Goes:

Goal = Make the player disappear when riding a certain mount. Disappear visually.
Help = What class/method would I use to make the player invisible? I've tried invis and stealth but they affect the mount. A couple of draw methods have done me no good.

Thanks in advance!
You can use the hook ModifyDrawLayers in the ModPlayer Class to hide individual layers, then create a loop to hide all of the layers that you want. I'd suggest hiding them by name so that it won't matter if another mod alters the PlayerLayers.

Here's an example:
Code:
public override void ModifyDrawLayers(List<PlayerLayer> layers)
{
    if (Main.gameMenu || !player.active)
        return; //don't modify the player when in the main menu or while the player is dead
    if (/*my condition*/)
    {
        for (int i = 0; i < layers.Count - 1; i++)
        {
            if (layers[i].Name == "Skin" || layers[i].Name == "Hair" || layers[i].Name == "Face" /*etc...*/) //Hide these layers
                layers[i].visible = false;
        }
    }
}
Actually... because you want to hide most layers, it would be easier to specify which ones you don't want to hide.
Code:
if (layers[i].Name != "MountBack" || layers[i].Name != "MountFront" ) //Hide none of these layers
                layers[i].visible = false;
Hope that makes sense.
 
Back
Top Bottom