tModLoader Official tModLoader Help Thread

How do I make an item drop from a NPC after a certain boss has been defeated? Here's my current code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace FragmentsFromEnemies.NPCs
{
    public class NPCDrops : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (npc.type == NPCID.SolarCrawltipedeTail)
            {
                if(Main.expertMode)
                {
                    if(Main.rand.Next(4) == 0)
                    {
                        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.FragmentSolar);
                    }
                }
                else
                {
                    if(Main.rand.Next(9) == 0)
                    {
                        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.FragmentSolar);
                    }
                }
            }
        }
    }
}
 
How do I make an item drop from a NPC after a certain boss has been defeated? Here's my current code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace FragmentsFromEnemies.NPCs
{
    public class NPCDrops : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (npc.type == NPCID.SolarCrawltipedeTail)
            {
                if(Main.expertMode)
                {
                    if(Main.rand.Next(4) == 0)
                    {
                        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.FragmentSolar);
                    }
                }
                else
                {
                    if(Main.rand.Next(9) == 0)
                    {
                        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.FragmentSolar);
                    }
                }
            }
        }
    }
}
Simply add this to the first if statement:
Code:
if (npc.type == NPCID.SolarCrawltipedeTail && NPC.downedBoss1)

Replace downedBoss1 by whichever boss you want defeated.
 
Simply add this to the first if statement:
Code:
if (npc.type == NPCID.SolarCrawltipedeTail && NPC.downedBoss1)

Replace downedBoss1 by whichever boss you want defeated.
Thanks, but another thing. How would one use the Moon Lord with this? Neither MoonLordCore nor the NPC ID work. Would you use something else?
 
How is the Boolean Value for Knockback Resistance called(if it's a Boolean Value)?
Or is it a single?
Edit: Found it out myself.
 
Last edited:
What code do I use to make my modded wings spawn custom dust particles in the WingUpdate(Player player, bool inUse) method
 
Hi im new to modding. I know how to make weapons/npcs (not very gud at it though lul)but does anyone know if it is possible to make a custom animation and use it on a custom weapon, like a spin on a sword or something fancy. If anyone knows plz teach me senpai

Thx gorateron, yeah ive been doing coding lately but still not too good with the terraria version of c#, ty for the help. I got curious because in one of the terraria otherworld leaks it said weapon lv up new upgrade slot available, so i thought if there was a way in modding that made it so u could have items to upgrade/modify ur sword animation, kinda like the game warframe where u have mods(these items) that change how u swing ur weapon
 
What code do I use to make my modded wings spawn custom dust particles in the WingUpdate(Player player, bool inUse) method
I believe it would be something like this.

Code:
if (Main.rand.Next(1) == 0)
            {
                int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("DustName"));
                Main.dust[dust].velocity /= 1f;
            }
 
I keep getting this error:

An error occured while compiling a mod.

c:/Users/MyName/Documents/My Games/Terraria/ModLoader/ModSources/MyModName/Items/MagicWeapon.cs(27,18) : error CS1061: 'Terraria.Item' does not contain a definition for 'useSound' and no extension method 'useSound' accepting a first argument of type 'Terraria.Item' could be found

This is my code

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

namespace MyModName.Items
{
public class MagicWeapon : ModItem
{
public override void SetDefaults()
{
item.name = "MagicWeaponTest";
item.damage = 34;
item.magic = true;
item.width = 24;
item.height = 28;
item.toolTip = "Casts a fire bolt.";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 2;
item.value = 1000;
item.rare = 6;
item.mana = 5;
item.useSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = mod.ProjectileType ("MagicProjectile");
item.shootSpeed = 8f;
}
}
}
[doublepost=1483491630,1483491579][/doublepost]
I keep getting this error:

An error occured while compiling a mod.

c:/Users/MyName/Documents/My Games/Terraria/ModLoader/ModSources/MyModName/Items/MagicWeapon.cs(27,18) : error CS1061: 'Terraria.Item' does not contain a definition for 'useSound' and no extension method 'useSound' accepting a first argument of type 'Terraria.Item' could be found

This is my code

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

namespace MyModName.Items
{
public class MagicWeapon : ModItem
{
public override void SetDefaults()
{
item.name = "MagicWeaponTest";
item.damage = 34;
item.magic = true;
item.width = 24;
item.height = 28;
item.toolTip = "Casts a fire bolt.";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 2;
item.value = 1000;
item.rare = 6;
item.mana = 5;
item.useSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = mod.ProjectileType ("MagicProjectile");
item.shootSpeed = 8f;
}
}
}
IDk why it looks like this with all the } but its normal in the code
 
So what would I use to have an item only drop in pre-hardmode?

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Mod.NPCs
{
    public class NPCDrops : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if (what do I put here)
            {
                if(Main.player[Main.myplayer].ZoneUnderworldHeight)
                {
                    if(Main.rand.Next(199) == 0)
                    {
                        Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Cascade);
                    }
                }
            }
        }
    }
}
 
Is it possible for a boss to flash the whole screen white when it changes phases? And how do I make the hitbox of the 2nd phase smaller (so it doesn't float off the ground)?
 
I made a custom projectile for my custom minion and everything is working but the minion isn't shooting its custom projectile. Can someone please check for an issue I can't find it

Minion Code


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

namespace StudyExampleMod.Projectiles.Minions
{
public class MinionName : MinionINFO
{
public override void SetDefaults()
{
projectile.netImportant = true;
projectile.name = "MinionP";
projectile.width = 32;
projectile.height = 32;
Main.projFrames[projectile.type] = 3;
projectile.friendly = true;
Main.projPet[projectile.type] = true;
projectile.minion = true;
projectile.netImportant = true;
projectile.minionSlots = 1;
projectile.penetrate = 1;
projectile.timeLeft = 18000;
projectile.tileCollide = false;
projectile.ignoreWater = true;
ProjectileID.Sets.MinionSacrificable[projectile.type] = true;
ProjectileID.Sets.Homing[projectile.type] = true;
inertia = 30f;
shoot = mod.ProjectileType("MinionP");
shootSpeed = 10f;
ProjectileID.Sets.LightPet[projectile.type] = true;
Main.projPet[projectile.type] = true;
}

public override void CheckActive()
{
Player player = Main.player[projectile.owner];
MyPlayer modPlayer = (MyPlayer)player.GetModPlayer(mod, "MyPlayer");
if (player.dead)
{
modPlayer.minionName = false;
}
if (modPlayer.minionName)
{
projectile.timeLeft = 2;
}
}

public override void CreateDust()
{
Lighting.AddLight((int)(projectile.Center.X / 16f), (int)(projectile.Center.Y / 16f), 0.6f, 0.9f, 0.3f);
}

public override void SelectFrame()
{
projectile.frameCounter++;
if (projectile.frameCounter >= 8)
{
projectile.frameCounter = 0;
projectile.frame = (projectile.frame + 1) % 3;
}
}
}
}




Minions Projectile Code


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

namespace StudyExampleMod.Projectiles.Minions
{
public class MinionP : ModProjectile
{

private int[] dusts = {160, 600, 64, 61, 50, 60, 590};

public override void SetDefaults()
{
projectile.name = "MinionP";
projectile.width = 30;
projectile.height = 30;
projectile.aiStyle = 0;
projectile.alpha = 255;
projectile.timeLeft = 150;
projectile.friendly = true;
projectile.tileCollide = true;
projectile.ignoreWater = true;
projectile.magic = true;
projectile.penetrate = 1;
}
public override void AI()
{
if (projectile.localAI[0] == 0f)
{
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 20);
projectile.localAI[0] = 1f;
}
int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, 66, 0f, 0f, 100, new Color(200, 10, 200), 1.5f);
Main.dust[dust].velocity *= 0.1f;
if (projectile.velocity == Vector2.Zero)
{
Main.dust[dust].velocity.Y -= 1f;
Main.dust[dust].scale = 1.2f;
}
else
{
Main.dust[dust].velocity += projectile.velocity * 0.2f;
}
Main.dust[dust].position.X = projectile.Center.X + 4f + (float)Main.rand.Next(-2, 3);
Main.dust[dust].position.Y = projectile.Center.Y + (float)Main.rand.Next(-2, 3);
Main.dust[dust].noGravity = true;
}
}
}




Thank you for your time :)
 
Back
Top Bottom