tModLoader Official tModLoader Help Thread

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
 

willcocobo

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

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

namespace Modding2.Items.Buffs
{
public class Waffle : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("holy Waffle");
Tooltip.SetDefault("Grants WellFed Buff");
}
public override void SetDefaults()
{

item.width = 12;
item.height = 26;
item.maxStack = 99;

item.value = 500;
item.rare = 3;
item.useAnimation = 30;
item.useTime = 30;
item.useStyle = 4;
item.consumable = true;
}

public override bool UseItem(Player player)
{
player.AddBuff(BuffID.WellFed, 7200); // this about 1 minute

return true;

}
}
}


you will have to change some stuff around to fit your mod
 
Top Bottom