Standalone [1.3] tModLoader - A Modding API

Sorry if this is a stupid question, but I'm trying to make a projectile heal the player, but I get this error:
  • c:\Users\---\Documents\My Games\Terraria\ModLoader\Mod Sources\TGEM\Projectiles\LifeBolt.cs(18,21) : error CS1518: Expected class, delegate, enum, interface, or struct
Can anyone help? Here is the code:

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

namespace TGEM.Projectiles
{
    public class LifeBolt : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(27);
            projectile.name = "Life Bolt";
            aiType = 27;
        }
    }

    public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
    {
        player.statLife += 2;
        player.HealEffect(10);
    }
}
 
Sorry if this is a stupid question, but I'm trying to make a projectile heal the player, but I get this error:
  • c:\Users\---\Documents\My Games\Terraria\ModLoader\Mod Sources\TGEM\Projectiles\LifeBolt.cs(18,21) : error CS1518: Expected class, delegate, enum, interface, or struct
Can anyone help? Here is the code:

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

namespace TGEM.Projectiles
{
    public class LifeBolt : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(27);
            projectile.name = "Life Bolt";
            aiType = 27;
        }
    }

    public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
    {
        player.statLife += 2;
        player.HealEffect(10);
    }
}
Check your opening and closing. The OnHitNPC function is put outside your class, while you want to put it inside it.
 
Check your opening and closing. The OnHitNPC function is put outside your class, while you want to put it inside it.
Thanks for helping, but I did that, and now I'm getting a different error:
  • c:\Users\---\Documents\My Games\Terraria\ModLoader\Mod Sources\TGEM\Projectiles\LifeBolt.cs(17,30) : error CS0115: 'TGEM.Projectiles.LifeBolt.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
Code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGEM.Projectiles
{
    public class LifeBolt : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(27);
            projectile.name = "Life Bolt";
            aiType = 27;
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            player.statLife += 2; //10 is the heal amount
            player.HealEffect(10);
        }
    }
}
 
If I remember correctly, Equals and == do the same thing. They're more relaxed than a reference equality, so that should be good.
Also, if you're using mod.GetTexture instead of ModLoader.GetTexture, the MyMod/ part shouldn't be necessary.
Thanks! Also, if you don't need to put in MyMod/ for mod.GetTexture, you should say so in the documentation.
I tried this out and now my log looks like this:
Code:
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? True
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? False
Does texture match armor texture? True
Does texture match armor texture? False
Does texture match armor texture? False
Looks about right to me!
 
Thanks for helping, but I did that, and now I'm getting a different error:
  • c:\Users\---\Documents\My Games\Terraria\ModLoader\Mod Sources\TGEM\Projectiles\LifeBolt.cs(17,30) : error CS0115: 'TGEM.Projectiles.LifeBolt.OnHitNPC(Terraria.Player, Terraria.NPC, int, float, bool)': no suitable method found to override
Code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TGEM.Projectiles
{
    public class LifeBolt : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(27);
            projectile.name = "Life Bolt";
            aiType = 27;
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            player.statLife += 2; //10 is the heal amount
            player.HealEffect(10);
        }
    }
}
You'll probably want to do:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
    Player player = Main.player[projectile.owner];
    player.statLife += 2; //10 is the heal amount
    player.HealEffect(10);
}
 
You'll probably want to do:
Code:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
    Player player = Main.player[projectile.owner];
    player.statLife += 2; //10 is the heal amount
    player.HealEffect(10);
}
It works! Thank you so much!
 
OK, now I have a new problem: I can access the Main.playerDrawInfo information for my armor, but changing it doesn't do anything. Where would I have to edit the information so that it occurs pre-draw?
 
I've been trying to achieve an "explosion" effect around the player, and I figured the best way to do this would be to spawn dust particles around them. However, (and I'm sure this is stupid of me) I can't for the life of me figure out how to spawn more than one particle using Dust.NewDust
Surely there's a way to do it without using tons of instances of Dust.NewDust, right?
 
I've been trying to achieve an "explosion" effect around the player, and I figured the best way to do this would be to spawn dust particles around them. However, (and I'm sure this is stupid of me) I can't for the life of me figure out how to spawn more than one particle using Dust.NewDust
Surely there's a way to do it without using tons of instances of Dust.NewDust, right?
You can use a for loop for this kind of stuff. Ex:
Code:
for(int i = 0; i < 5; ++i)
{
    // This will trigger 5 times in one update.
}
Think you can work with that?
 
How can I make an ore spawn when a boss is killed?
I would've searched for it but ore is too short
I picked this code up somewhere along the way.
Call this method when your boss dies:
Code:
private void SpawnOre()
{
    int minX = 200;
    int maxX = Main.maxTilesX - 200;
    int minY = (int)Main.worldSurface;
    int maxY = Main.maxTilesY - 200;

    int x = WorldGen.genRand.Next(minX, maxX);
    int y = WorldGen.genRand.Next(minY, maxY);

    int minSpread = 2;
    int maxSpread = 8;

    int minFreq = 6;
    int maxFreq = 8;

    int s = WorldGen.genRand.Next(minSpread, maxSpread + 1);
    int f = WorldGen.genRand.Next(minFreq, maxFreq + 1);

    for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
    {
        WorldGen.OreRunner(x, y, s, f, (ushort)mod.TileType("MyModOre"));
    }
}
 
On Tmodloader's current state for multiplayer, is it normal for the server to lag a lot every 3 or 5 minutes for the other players?

The host connection is fine and on his end so is the server (other than blocks broken by the other players not being pickable for a while)

Is there anyway to fix this at all, as it seems connection is OK on all ends.

Edit: Also the "start-tModLoaderServer-steam-friends" file from the latest version doesn't open at all here, so I'm using the .11 version, simply because it works. (In case it is that)
 
Last edited:
I think something might be wrong with my game? When I started it up just now it said my game had crashed. I hit okay and it seemed fine. Then when I try to open the mod browser it locks up. Sometimes it'll go through but then downloading a mod takes AGES compared to how fast it should be going. Is this a bug or something?
 

Code:
public override void NPCLoot()
        {
            if (Main.rand.Next(4) == 3)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
            if (Main.rand.Next(4) == 2)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
            if (Main.rand.Next(4) == 1)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
           
            if (Main.expertMode)
            {
                npc.DropBossBags();
            }
           
            private void SpawnOre()
            {
                int minX = 200;
                int maxX = Main.maxTilesX - 200;
                int minY = (int)Main.worldSurface;
                int maxY = Main.maxTilesY - 200;

                int x = WorldGen.genRand.Next(minX, maxX);
                int y = WorldGen.genRand.Next(minY, maxY);

                int minSpread = 2;
                int maxSpread = 8;

                int minFreq = 6;
                int maxFreq = 8;

                int s = WorldGen.genRand.Next(minSpread, maxSpread + 1);
                int f = WorldGen.genRand.Next(minFreq, maxFreq + 1);

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.OreRunner(x, y, s, f, (ushort)mod.TileType("OreName"));
                }
            }
        }
Probably missing something really obvious here, but it says (61,5) error CS1513: } expected, but there's a } on line 61 so I'm confused
 
Code:
public override void NPCLoot()
        {
            if (Main.rand.Next(4) == 3)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
            if (Main.rand.Next(4) == 2)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
            if (Main.rand.Next(4) == 1)
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("irrelevant"));
            }
          
            if (Main.expertMode)
            {
                npc.DropBossBags();
            }
          
            private void SpawnOre()
            {
                int minX = 200;
                int maxX = Main.maxTilesX - 200;
                int minY = (int)Main.worldSurface;
                int maxY = Main.maxTilesY - 200;

                int x = WorldGen.genRand.Next(minX, maxX);
                int y = WorldGen.genRand.Next(minY, maxY);

                int minSpread = 2;
                int maxSpread = 8;

                int minFreq = 6;
                int maxFreq = 8;

                int s = WorldGen.genRand.Next(minSpread, maxSpread + 1);
                int f = WorldGen.genRand.Next(minFreq, maxFreq + 1);

                for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
                {
                    WorldGen.OreRunner(x, y, s, f, (ushort)mod.TileType("OreName"));
                }
            }
        }
Probably missing something really obvious here, but it says (61,5) error CS1513: } expected, but there's a } on line 61 so I'm confused
SpawnOre is a method and should be treated as such, meaning that you do not want to put the whole method itself in the NPCLoot function, just a call to it.
Move the SpawnOre outside the NPCLoot method, but inside your NPC class and call 'SpawnOre();' in the NPCLoot method instead.
 
SpawnOre is a method and should be treated as such, meaning that you do not want to put the whole method itself in the NPCLoot function, just a call to it.
Move the SpawnOre outside the NPCLoot method, but inside your NPC class and call 'SpawnOre();' in the NPCLoot method instead.
Alright, thanks, it spawns now, but at a ridiculous rarity. After shredding up a small world with the drill mount, I found one vein of ore. I killed the boss about 20+ times, but my guess would be it is only spawning one vein per kill, judging from the rarity.
 
Alright, thanks, it spawns now, but at a ridiculous rarity. After shredding up a small world with the drill mount, I found one vein of ore. I killed the boss about 20+ times, but my guess would be it is only spawning one vein per kill, judging from the rarity.
Hmmm, instead of OreRunner, you could also try using TileRunner:
Code:
WorldGen.TileRunner(x, y, s, f, mod.TileType("MyOre"), false, 0f, 0f, false, true);
 
Hmmm, instead of OreRunner, you could also try using TileRunner:
Code:
WorldGen.TileRunner(x, y, s, f, mod.TileType("MyOre"), false, 0f, 0f, false, true);
That appears to be the same, but quick question, does the max/min stuff at the top confine it between certain X and Y values?

On a side note, how do I get custom boss music to work?
 
That appears to be the same, but quick question, does the max/min stuff at the top confine it between certain X and Y values?

On a side note, how do I get custom boss music to work?
Yes, it does. The X coordinate makes sure the ore vein is not spawned in the Ocean biome and the Y makes sure it's no spawned in hell.
 
Back
Top Bottom