tModLoader Official tModLoader Help Thread

Greeting. I am currently working on a modded weapon that I wish to add particles to. I used the ExampleMod base to see how exactly I do this, but i continuously get the reoccurring error: error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) Of Course, here's my code. Thanks for any reply!

Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace WondersBlight.Items.Weapons
{
    public class Bloomer : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Bloomer";
            item.damage = 26;
            item.melee = true;
            item.width = 80;
            item.height = 80;
            item.toolTip = "Biomatter makes everything better.";
            item.useTime = 40;
            item.useAnimation = 45;
            item.useStyle = 1;
            item.knockBack = 3;
            item.value = 10000;
            item.rare = 4;
            item.UseSound = SoundID.Item1;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Vine, 10);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.Stinger, 10);
            recipe.AddIngredient(ItemID.JungleSpores, 10);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddIngredient("Gloomer");
            recipe.AddRecipe();
        }

        public override void MeleeEffects(Player player, Rectangle hitbox)
        {
            if (Main.rand.Next(3) == 0)
            {
                int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));
                //Emit dusts when swing the sword
            }
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.Poisned, 60);      //Add Onfire buff to the NPC for 1 second
        }
    }
}
 
Greeting. I am currently working on a modded weapon that I wish to add particles to. I used the ExampleMod base to see how exactly I do this, but i continuously get the reoccurring error: error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) Of Course, here's my code. Thanks for any reply!

Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace WondersBlight.Items.Weapons
{
    public class Bloomer : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Bloomer";
            item.damage = 26;
            item.melee = true;
            item.width = 80;
            item.height = 80;
            item.toolTip = "Biomatter makes everything better.";
            item.useTime = 40;
            item.useAnimation = 45;
            item.useStyle = 1;
            item.knockBack = 3;
            item.value = 10000;
            item.rare = 4;
            item.UseSound = SoundID.Item1;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Vine, 10);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.Stinger, 10);
            recipe.AddIngredient(ItemID.JungleSpores, 10);
            recipe.AddTile(TileID.Anvils);
            recipe.SetResult(this);
            recipe.AddIngredient("Gloomer");
            recipe.AddRecipe();
        }

        public override void MeleeEffects(Player player, Rectangle hitbox)
        {
            if (Main.rand.Next(3) == 0)
            {
                int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));
                //Emit dusts when swing the sword
            }
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.Poisned, 60);      //Add Onfire buff to the NPC for 1 second
        }
    }
}

try putting
Code:
using Microsoft.Xna.Framework;
at the top and tell me it doesnt work.
 
It says this problem here but there is nothing wrong with the file names
 

Attachments

  • 1.PNG
    1.PNG
    8.9 KB · Views: 161
  • 2.PNG
    2.PNG
    26.6 KB · Views: 126
  • 3.PNG
    3.PNG
    27.1 KB · Views: 138
  • 4.PNG
    4.PNG
    19.4 KB · Views: 138
I have this problem with a boss summoning item, where the item is animated and animates fine, however when I use the item it shows the character holding the sprite sheet of 4. Does anybody know a fix, or will I just have to use an unanimated summoning item?
 
Learning how to use tModLoader and in no way experienced with C#, Is there a way to reference another mods NPC? For Example trying to test if the player killed a boss mob:
npc.type == CalamityMod.NPCs.DesertScourge.DesertScourgeHead && !player.killedDesertScourge
I'm calling the Mono.dll from Calamity, but no matter how I word it it doesn't seem to register that I want to test another Mods NPCs.
Same question for items, I would like to make a recipe with items based from other mods. I'm sure I'm missing something super easy
 
What is the magic mirror's property?

accDreamCatcher = true; ??


And what should I use to make this work in my inventory? Because I tried to combine ankh shield and Cell phone and nothing worked when in hotbar but as soon as I put it into the acc slot, at least the antiknockback worked immediately. Now I'll try to combine the phone with grand plan instead. What should I use? Not the UpdateAccessory() , right?
 
Last edited:
How do I make falling projectiles (like star wrath) and homing projectiles?
Thank you
Here's a part of a discussion about homing projectiles that hopefully is useful.

You'll probably need to write your own AI then, but I can show you some code snippets to get you started. When I wanted to make a homing projectile of my own, I started by writing a function that iterates through all NPCs to select which one to target.
//Find the nearest NPC
public NPC FindNearest(Vector2 pos)
{
NPC nearest = null;
float oldDist = 1001;
float newDist = 1000;
for (int i = 0; i < Terraria.Main.npc.Length - 1; i++) //Do once for each NPC in the world
{
if (Terraria.Main.npc.friendly == true)//Don't target town NPCs
continue;
if (Terraria.Main.npc.active == false)//Don't target dead NPCs
continue;
if (Terraria.Main.npc.damage == 0)//Don't target non-aggressive NPCs
continue;
if (nearest == null) //if no NPCs have made it past the previous few checks
nearest = Terraria.Main.npc; //become the nearest NPC
else
{
oldDist = Vector2.Distance(pos, nearest.position);//Check the distance to the nearest NPC that's earlier in the loop
newDist = Vector2.Distance(pos, Terraria.Main.npc.position);//Check the distance to the current NPC in the loop
if (newDist < oldDist)//If closer than the previous NPC in the loop
nearest = Terraria.Main.npc;//Become the nearest NPC
}
}
return nearest; //return the npc that is nearest to the vector 'pos'
}
Then I'd simply need to write "NPC nearestNPC = FindNearest(projectile.Center);" in my AI to find which NPC is nearest to the projectile's center. But recently I looked through the games code, and found the following code snippet.
int num3;
for (int num33 = 0; num33 < 200; num33 = num3 + 1)
{
if (Main.npc[num33].CanBeChasedBy(this, false))
{
float num34 = Main.npc[num33].position.X + (float)(Main.npc[num33].width / 2);
float num35 = Main.npc[num33].position.Y + (float)(Main.npc[num33].height / 2);
float num36 = Math.Abs(this.position.X + (float)(this.width / 2) - num34) + Math.Abs(this.position.Y + (float)(this.height / 2) - num35);
if (num36 < 800f && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num33].position, Main.npc[num33].width, Main.npc[num33].height))
{
num31 = num34;
num32 = num35;
flag = true;
}
}
num3 = num33;
}
This uses NPC.CanBeChasedBy() to exclude any NPC's that you don't want to target and Collision.CanHit() to check if it has line of sight with each NPC, which my function didn't.

Once I know which NPC I'm targeting, I like to spawn dust at it's location simply so that I have a visual indication of which NPC is being targeted.

Also, here's some code that makes a projectile home in on the mouse's position. It's not quite self contained, but there's enough there to work with.
//mPos = Main.mouseWorld;//get the mouses position in the world
targPos = findTarget(); //Find the thing I want to home in on -- use your target's position instead
toMouse = (float)Math.Atan2(targPos.Y - projectile.position.Y, targPos.X - projectile.position.X); //calculate a bearing to that thing

if (Main.player[projectile.owner].gravDir == -1f) //if my player is upside down
targPos.Y = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY;//reverse the vertical position of my mouse

//accelerate towards my target
projectile.velocity.X += (float)Math.Cos(toMouse) * acel * randVel; //acel is a float that controls how fast the projectile accelerates. randVel is a random modifier to the acceleration.
projectile.velocity.Y += (float)Math.Sin(toMouse) * acel * randVel;

if (Math.Sqrt(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y) > maxSpeed) //if going too fast
{
//Main.NewText("Max!");
projectile.velocity *= 1 - (acel / maxSpeed); //slow down a little bit
}
None of this code is going to work straight off, it will all need work to suit your needs. But I hope you find it helpful.

Edit: huh, looks like spoiler tags aren't the things to put code into.
 
Thanks a lot
So do I simply put that code inside the projectiles.cs?
Well, no. The bottom spoiler contains code that belongs in a AI hook and requires a function to find what to home in on. The top spoiler contains a function that searches through the NPC array and finds the nearest one to the projectile. This requires some programming understanding to get working.
 
also how do I make worm type enemy spawn naturally? I never tried it but I have a feeling that it will only spawn the head. . .
I will also like to make that enemy to be a bit rare
 
can somebody help me?
I want to do a pet, but it fails and this apparears:
Buffs/PetBuff
en Terraria.ModLoader.Mod.GetTexture(String name)
en Terraria.ModLoader.ModLoader.GetTexture(String name)
en Terraria.ModLoader.Mod.SetupContent()
en Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
 
can somebody help me?
I want to do a pet, but it fails and this apparears:
Buffs/PetBuff
en Terraria.ModLoader.Mod.GetTexture(String name)
en Terraria.ModLoader.ModLoader.GetTexture(String name)
en Terraria.ModLoader.Mod.SetupContent()
en Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
Well it means it cant find the texture for the pet buff, is the pet buff png named the same as the buff .cs file?
 
Done but now this apparears:
The tile WBName does not exist in the mod YourModName.
If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).
en Terraria.ModLoader.ModRecipe.AddTile(Mod mod, String tileName)
en YourModName.Items.PetCall.AddRecipes() en c:\Users\hp\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Items\PetCall.cs:línea 22
en Terraria.ModLoader.RecipeHooks.AddRecipes()
Sorry if im Bothering to much, but this is my first mod
 
Done but now this apparears:
The tile WBName does not exist in the mod YourModName.
If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).
en Terraria.ModLoader.ModRecipe.AddTile(Mod mod, String tileName)
en YourModName.Items.PetCall.AddRecipes() en c:\Users\hp\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Items\PetCall.cs:línea 22
en Terraria.ModLoader.RecipeHooks.AddRecipes()
Sorry if im Bothering to much, but this is my first mod
Can you post the code of that file in code tags for easier viewing.
 
Back
Top Bottom