• PC NEWS: 1.4.2.3 update is out! More info here. Report bugs here
  • CONSOLE 1.4 NEWS: The current plan is to have Terraria: Journey's End out for Xbox and PlayStation in Q3 2021 (Jul-Sep). Switch will follow shortly afterwards. More info here. Stay up to date with console news here
  • MOBILE NEWS: Stay up to date with the latest mobile news here. Report mobile bugs here

tModLoader Official tModLoader Help Thread

VaalAlves

Terrarian
Hey, i'm working on a weapon for my mod and i'm having trouble finding a way to do this.
Basically, my weapon has 3 modes that can be changed by right clicking.
I also want to change the weapon's sprite when the mode changes.
Is there something like "item.texture = (texture path)"?
If not, how should i go about doing this?
Thanks
 

Arceus Gamer

Terrarian
Did anyone know how to create Custom Grass seed? It's because i want to do a Biome whit the Grass seed like Hallow and Curroption/Crimson, but just appear in Post-Moon Lord.
 
Last edited:

willcocobo

The Destroyer
having a very weird problem. everything worked fine and out of nowhere it isnt anymore.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Modding2.Items.TrustDamagePlayer;
using Modding2.Projectiles.SpearProjectiles;


namespace Modding2.Items.Spears.PreHardMode
{
// This class handles everything for our custom damage class
// Any class that we wish to be using our custom damage class will derive from this class, instead of ModItem
public abstract class CopperSpear : ModItem
{
public virtual void SafeSetDefaults()
{
item.melee = false;
item.ranged = false;
item.magic = false;
item.thrown = false;
item.summon = false;
}
public sealed override void SetStaticDefaults()
{
}
public override void ModifyWeaponDamage(Player player, ref float add, ref float mult, ref float flat)
{
add += TrustDamagePlayer.TrustDamagePlayer.ModPlayer(player).TrustDamageAdd;
mult *= TrustDamagePlayer.TrustDamagePlayer.ModPlayer(player).TrustDamageMult;
}
public override void GetWeaponKnockback(Player player, ref float knockback)
{
knockback += TrustDamagePlayer.TrustDamagePlayer.ModPlayer(player).TrustKnockback;
}
public override void ModifyTooltips(List<TooltipLine> tooltips) the red is the part that is working
{
TooltipLine tt = tooltips.FirstOrDefault(x => x.Name == "Damage" && x.mod == "Terraria");
if (tt != null)
{
string[] splitText = tt.text.Split(' ');
string damageValue = splitText.First();
string damageWord = splitText.Last();
tt.text = damageValue + " Trust " + damageWord;
}
}
public override void SetDefaults()
{
item.damage = 12;
item.width = 28;
item.height = 28;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = ItemUseStyleID.HoldingOut;
item.shootSpeed = 2.9f;
item.knockBack = 3;
item.value = 10000;
item.rare = 3;
item.UseSound = SoundID.Item1;

item.noMelee = true;
item.noUseGraphic = true;
item.shoot = ModContent.ProjectileType<CopperSpearProjectile>();
}
}
}

it is on every spear that ive made. never had this problem until now.
i highlighted the part thats not working in red.
i have no idea how to fix it
 
Last edited:

tifey

Terrarian
1606578952668.png
what i do wrong? anybody can help me? im trying to make custom yoyo
1606579112749.png
 

Nekomancer08

Terrarian
Hello, I'd like to know how one would go about making accessories that function similar to the Fire Gauntlet. The idea I have in mind is an item that makes all projectiles the wearer shoots explode on contact with an entity or block. However, despite my best efforts I cannot find any code for such things with which to reference.
 

GreenTea

Terrarian
Hello! I am currently having a problem with a minion shooting a projectile. My minion Dunkleostasis(BonyFish in the code files) is planned to shoot out bones in all directions when it hits an NPC. So because I put a chunk of code intended for Shoot() into OnHitNPC() I had to define a lot of floats manually.
When I tested it out only one bone flies out of the minion. I do not know if this is a problem with me defining all of my floats manually or if I am missing something. Here is the part of the code that I am having problems with.
C#:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.myPlayer == projectile.owner)
            {
                Vector2 targetPos = projectile.position;
                Vector2 shootVel = targetPos - projectile.Center;

                projectile.netUpdate = true;
               
                Player player = Main.player[projectile.owner];
                float speedX = projectile.velocity.X;
                float speedY = projectile.velocity.Y;
             
                float numberProjectiles = 8; // 3 shots
                float rotation = MathHelper.ToRadians(180);//Shoots them in a 45 degree radius. (This is technically 90 degrees because it's 45 degrees up from your cursor and 45 degrees down)
                targetPos += Vector2.Normalize(new Vector2(speedX, speedY)) * 180f; //45 should equal whatever number you had on the previous line
                for (int i = 0; i < numberProjectiles; i++)
                {
                    Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // Vector for spread. Watch out for dividing by 0 if there is only 1 projectile.
                    Projectile.NewProjectile(projectile.Center, Vector2.Normalize(shootVel) * 15f, ProjectileType<BonyFishBone>(), projectile.damage, projectile.knockBack, Main.myPlayer, 0f, 0f); //Creates a new projectile with our new vector for spread.
                }
               

            }


        }
Thank You so much!
 
Hello! I am currently having a problem with a minion shooting a projectile. My minion Dunkleostasis(BonyFish in the code files) is planned to shoot out bones in all directions when it hits an NPC. So because I put a chunk of code intended for Shoot() into OnHitNPC() I had to define a lot of floats manually.
When I tested it out only one bone flies out of the minion. I do not know if this is a problem with me defining all of my floats manually or if I am missing something. Here is the part of the code that I am having problems with.
C#:
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (Main.myPlayer == projectile.owner)
            {
                Vector2 targetPos = projectile.position;
                Vector2 shootVel = targetPos - projectile.Center;

                projectile.netUpdate = true;
              
                Player player = Main.player[projectile.owner];
                float speedX = projectile.velocity.X;
                float speedY = projectile.velocity.Y;
            
                float numberProjectiles = 8; // 3 shots
                float rotation = MathHelper.ToRadians(180);//Shoots them in a 45 degree radius. (This is technically 90 degrees because it's 45 degrees up from your cursor and 45 degrees down)
                targetPos += Vector2.Normalize(new Vector2(speedX, speedY)) * 180f; //45 should equal whatever number you had on the previous line
                for (int i = 0; i < numberProjectiles; i++)
                {
                    Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // Vector for spread. Watch out for dividing by 0 if there is only 1 projectile.
                    Projectile.NewProjectile(projectile.Center, Vector2.Normalize(shootVel) * 15f, ProjectileType<BonyFishBone>(), projectile.damage, projectile.knockBack, Main.myPlayer, 0f, 0f); //Creates a new projectile with our new vector for spread.
                }
              

            }


        }
Thank You so much!
All the projectiles are spawning, but they’re stacked on top of one another. You need to use the perturbedSpeed you’re defining instead of what you currently have in NewProjectile.
 

GreenTea

Terrarian
Thank you so much, that seemed to fix it. Now all I need to worry about is the sprite offset because that is heckin wonky at the moment.
 

tifey

Terrarian
hi, does anyone know an open source mod with different weapons
I can't find up-to-date guides for creating various projectiles
most mod authors block access and it is very difficult to find a good reference
 

willcocobo

The Destroyer
hi, does anyone know an open source mod with different weapons
I can't find up-to-date guides for creating various projectiles
most mod authors block access and it is very difficult to find a good reference

the " Projectile Guide and Implementation " thread is very helpful for projectiles, there will be a lot of reading but its really helpfull

and the tModLoader ExampleMod on git hub has things like enemies and weapons and its showes all code
 

Goldblitzx

Skeletron
I'm trying to figure out how to add crit chance increases to an armor set I've tried player.Crit += x% however I don't know if it will exactly work
 

Goldblitzx

Skeletron
I'm having an issue with my code for armor more so with the line that says that when you equip it you gain stat bonuses
this is my code
public override void UpdateEquip(Player player) {
player.buffImmune[BuffID.Bleeding] = true;
player.thrownDamage += 2f;
}
and when I start to build my mod in the mod sources section it states that my mod failed to build with the term of 'Player" not being able to be found
any help at all would be nice
 

willcocobo

The Destroyer
I'm having an issue with my code for armor more so with the line that says that when you equip it you gain stat bonuses
this is my code
public override void UpdateEquip(Player player) {
player.buffImmune[BuffID.Bleeding] = true;
player.thrownDamage += 2f;
}
and when I start to build my mod in the mod sources section it states that my mod failed to build with the term of 'Player" not being able to be found
any help at all would be nice

could you post the full code of the armor? it may be a problem somewhere else
 

willcocobo

The Destroyer
I'm having an issue with my code for armor more so with the line that says that when you equip it you gain stat bonuses
this is my code
public override void UpdateEquip(Player player) {
player.buffImmune[BuffID.Bleeding] = true;
player.thrownDamage += 2f;
}
and when I start to build my mod in the mod sources section it states that my mod failed to build with the term of 'Player" not being able to be found
any help at all would be nice

use this



public override void SetStaticDefaults() {
Tooltip.SetDefault(" adds throwing damage ");

you can change what it says. i dont know how to make it only show up when you have all the armor set equipted. so it will show up on the piece you put the code on
 

Goldblitzx

Skeletron
use this



public override void SetStaticDefaults() {
Tooltip.SetDefault(" adds throwing damage ");

you can change what it says. i dont know how to make it only show up when you have all the armor set equipted. so it will show up on the piece you put the code on
I realised it was because I forgot to put using Terraria at the top
 

kyaryx

Terrarian
i'm trying to make a consumable waffle item that gives you the well fed buff, please provide me with the holy waffle code
 
Top Bottom