• PC NEWS: 1.4.2.3 update is out! More info here. Report bugs here
  • Journey's End on Xbox and PlayStation!: Get all the info by clicking here. A new patch is in QA - expect some Gamepad love, the return of Red's Pick and more. Click here for Known Issues and FAQ. For any other bugs, report them (with as much detail as possible) here.
  • MOBILE NEWS: Stay up to date with the latest mobile news here. Report mobile bugs here

tModLoader Official tModLoader Help Thread

Gionas36 1

Official Terrarian
You would add in
C#:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) {
    Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
    return false;
}
.

What this does, is it overrides the vanilla projectile shooting AI (by calling "return false;" at the end) and makes a new AI, where it moves the projectile forwards by the velocity vector times a multiplier value (Which you can set to be whatever you want, just make sure they are both the same number)
idk wut i did to mess it up(im new to programming) but it didnt work
erroe.PNG


this is the code:
C#:
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria.ModLoader;

namespace MySword.Projectiles
{
    public class ExProcyonBlast : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Ex Procyon Blast");
        }

        public override void SetDefaults()
        {
            projectile.width = 500;
            projectile.height = 500;
            projectile.scale = 1f;
            projectile.timeLeft = 30;
            projectile.penetrate = 10;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.tileCollide = false;
            projectile.alpha = 55;
            projectile.light = 1f;
            projectile.aiStyle = 4;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
            return false;
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            //The debuff inflicted is the modded debuff Ethereal Flames. 180 is the duration in frames: Terraria runs at 60 FPS, so that's 3 seconds (180/60=3). To change the modded debuff, change EtherealFlames to whatever the buff is called; to add a vanilla debuff, change mod.BuffType("EtherealFlames") to a number based on the terraria buff IDs. Some useful ones are 20 for poison, 24 for On Fire!, 39 for Cursed Flames, 69 for Ichor, and 70 for Venom.
            target.AddBuff(mod.BuffType("OnFire!"), 180, false);
        }
    }
}
 

LuckyLMJ

Terrarian
idk wut i did to mess it up(im new to programming) but it didnt work
View attachment 329456

this is the code:
C#:
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria.ModLoader;

namespace MySword.Projectiles
{
    public class ExProcyonBlast : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Ex Procyon Blast");
        }

        public override void SetDefaults()
        {
            projectile.width = 500;
            projectile.height = 500;
            projectile.scale = 1f;
            projectile.timeLeft = 30;
            projectile.penetrate = 10;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.tileCollide = false;
            projectile.alpha = 55;
            projectile.light = 1f;
            projectile.aiStyle = 4;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
            return false;
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            //The debuff inflicted is the modded debuff Ethereal Flames. 180 is the duration in frames: Terraria runs at 60 FPS, so that's 3 seconds (180/60=3). To change the modded debuff, change EtherealFlames to whatever the buff is called; to add a vanilla debuff, change mod.BuffType("EtherealFlames") to a number based on the terraria buff IDs. Some useful ones are 20 for poison, 24 for On Fire!, 39 for Cursed Flames, 69 for Ichor, and 70 for Venom.
            target.AddBuff(mod.BuffType("OnFire!"), 180, false);
        }
    }
}
You put it in the weapon code, not the projectile code.

Sorry, probably should have specified that
 

Gionas36 1

Official Terrarian
You put it in the weapon code, not the projectile code.

Sorry, probably should have specified that
Now there is another problem after i added it to the weapon(i eliminated it from the projectile)
errorcode.PNG


this is the code of the weapon
C#:
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Items
{
    public class TrueFomalhautEx : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("True Fomalhaut");
            Tooltip.SetDefault("7200% Fire DMG (Magic). Increases own DMG by 50% for 2s.");
        }

        public override void SetDefaults()
        {
            item.buffType = 159;
            item.buffTime = 120;
            item.magic = true;
            item.noMelee = true;
            item.damage = 250;
            item.useStyle = 5;
            item.useTime = 5;
            item.useAnimation = 5;
            item.knockBack = 2;
            item.value = 5000;
            item.rare = -12;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.width = 64;
            item.height = 64;
            item.mana = 15;
            item.scale = 0.33f;

            item.shoot = item.shoot = mod.ProjectileType("ExProcyonBlast");
            item.shootSpeed = 1f;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
            return false;
        }

        public override void AddRecipes()
        {
            ModRecipe TrueFomalhautExrecipe = new ModRecipe(mod);
            TrueFomalhautExrecipe.AddIngredient(2, 1);
            TrueFomalhautExrecipe.AddIngredient(29, 1);
            TrueFomalhautExrecipe.AddIngredient(22, 10);
            TrueFomalhautExrecipe.AddIngredient(65, 3);
            TrueFomalhautExrecipe.AddIngredient(19, 5);

            TrueFomalhautExrecipe.AddTile(17);
            TrueFomalhautExrecipe.SetResult(this);
            TrueFomalhautExrecipe.AddRecipe();
        }
    }
}[/CODE=csharp]
 
Last edited:

BTVOS

Terrarian
In TModLoader when I try to start the Old One's Army, the Eternia Portals won't spawn. When I tried this on the unofficial TModLoader 64-bit version it crashed with no error screen. Any advice on how to fix this?
Details: my pc is Windows 7, when I start the OOA on the official 32-bit version the portals just won't spawn. when I do this on the unofficial 64-bit version, the portals spawn, the goblins spawn and after like 1 or 2 seconds it crashes. I was messing with the DLL libraries before to fix Terraria not launching, and after I messed around with things, Terraria launched with no sound. TModLoader 32-bit doesn't launch with sound as well, and the unofficial 64-bit version does output the sound, it's made on FNA and not XNA. Any advice on how do I fix this?

P.S. Sorry for my probably bad grammar, English is not my native language
 

LuckyLMJ

Terrarian
Now there is another problem after i added it to the weapon(i eliminated it from the projectile)
View attachment 329464

this is the code of the weapon
C#:
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Items
{
    public class TrueFomalhautEx : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("True Fomalhaut");
            Tooltip.SetDefault("7200% Fire DMG (Magic). Increases own DMG by 50% for 2s.");
        }

        public override void SetDefaults()
        {
            item.buffType = 159;
            item.buffTime = 120;
            item.magic = true;
            item.noMelee = true;
            item.damage = 250;
            item.useStyle = 5;
            item.useTime = 5;
            item.useAnimation = 5;
            item.knockBack = 2;
            item.value = 5000;
            item.rare = -12;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
            item.width = 64;
            item.height = 64;
            item.mana = 15;
            item.scale = 0.33f;

            item.shoot = item.shoot = mod.ProjectileType("ExProcyonBlast");
            item.shootSpeed = 1f;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
            return false;
        }

        public override void AddRecipes()
        {
            ModRecipe TrueFomalhautExrecipe = new ModRecipe(mod);
            TrueFomalhautExrecipe.AddIngredient(2, 1);
            TrueFomalhautExrecipe.AddIngredient(29, 1);
            TrueFomalhautExrecipe.AddIngredient(22, 10);
            TrueFomalhautExrecipe.AddIngredient(65, 3);
            TrueFomalhautExrecipe.AddIngredient(19, 5);

            TrueFomalhautExrecipe.AddTile(17);
            TrueFomalhautExrecipe.SetResult(this);
            TrueFomalhautExrecipe.AddRecipe();
        }
    }
}[/CODE=csharp]
Set it to "position.X" and "velocity.X" and "position.Y" and "velocity.Y" instead of ".x" and ".y"

my mistake, sorry
 

Olipog

Terrarian
Hey everyone, I'm fairly new to Terraria modding and today I ran into an issue I couldn't find a forum or answer for. The issue was not a visible code error, but it occured when I clicked "build and reload" on my mod.

C#:
[Thread Pool Worker/ERROR] [tML]: Value cannot be null.
Parameter name: document
System.ArgumentNullException: Value cannot be null.
Parameter name: document
  at Mono.Cecil.Cil.SequencePoint..ctor (Int32 offset, Document document) [0x00009] in data-0x7fa7d235e000
  at Mono.Cecil.SignatureReader.ReadSequencePoints (Document document) [0x000f9] in data-0x7fa7d235e000
  at Mono.Cecil.MetadataReader.ReadSequencePoints (MethodDefinition method) [0x0004e] in data-0x7fa7d235e000
  at Mono.Cecil.Cil.PortablePdbReader.ReadSequencePoints (MethodDebugInformation method_info) [0x00000] in data-0x7fa7d235e000
  at Mono.Cecil.Cil.PortablePdbReader.Read (MethodDefinition method) [0x00007] in data-0x7fa7d235e000
  at Mono.Cecil.ImmediateModuleReader.ReadMethodsSymbols (TypeDefinition type, ISymbolReader symbol_reader) [0x0003d] in data-0x7fa7d235e000
  at Mono.Cecil.ImmediateModuleReader.ReadTypesSymbols (Collection[T] types, ISymbolReader symbol_reader) [0x00029] in data-0x7fa7d235e000
  at Mono.Cecil.ImmediateModuleReader.ReadTypesSymbols (Collection[T] types, ISymbolReader symbol_reader) [0x0001b] in data-0x7fa7d235e000
  at Mono.Cecil.ImmediateModuleReader.ReadSymbols (ModuleDefinition module) [0x00010] in data-0x7fa7d235e000
  at Mono.Cecil.ModuleWriter.Write (ModuleDefinition module, Disposable[T] stream, WriterParameters parameters) [0x00039] in data-0x7fa7d235e000
  at Mono.Cecil.ModuleWriter.WriteModule (ModuleDefinition module, Disposable[T] stream, WriterParameters parameters) [0x00002] in data-0x7fa7d235e000
  at Mono.Cecil.ModuleDefinition.Write (String fileName, WriterParameters parameters) [0x00017] in data-0x7fa7d235e000
  at Mono.Cecil.AssemblyDefinition.Write (String fileName, WriterParameters parameters) [0x00000] in data-0x7fa7d235e000
  at Terraria.ModLoader.Core.ModCompile.BuildModForPlatform (BuildingMod mod, Boolean xna) [0x0025d] in tModLoader.exe
  at Terraria.ModLoader.Core.ModCompile.Build (BuildingMod mod) [0x000d0] in tModLoader.exe
  at Terraria.ModLoader.Core.ModCompile.Build (String modFolder) [0x00008] in tModLoader.exe
  at Terraria.ModLoader.UI.UIBuildMod+<>c__DisplayClass5_0.<Build>b__0 (ModCompile mc) [0x00000] in tModLoader.exe
  at Terraria.ModLoader.UI.UIBuildMod.BuildMod (Action[T] buildAction, Boolean reload) [0x0003a] in tModLoader.exe

The code itself is:

C#:
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.World.Generation;
using Terraria.GameContent.Generation;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using System.Collections.Generic;
using System.IO;

namespace HollowKnightContent
{

    public class HallownestWorld : ModWorld
    {

        #region Generation

        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
        {
            int shiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));
            if(shiniesIndex != -1)
            {
                tasks.Insert(shiniesIndex + 1, new PassLegacy("Pale Ore Spawn", GeneratePaleOre));
            }
        }

        private void GeneratePaleOre(GenerationProgress progress)
        {
            progress.Message = "Conjuring Pale Ore";
            for (var i = 0; i < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); i++)
            {
                int x = WorldGen.genRand.Next(200, Main.maxTilesX - 200);
                int y = WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY - 500);

                WorldGen.TileRunner(x, y, WorldGen.genRand.Next(1, 3), WorldGen.genRand.Next(3, 6),
                    ModContent.TileType<Tiles.PaleOre.PaleOre>());
            }
        }

        #endregion
    }
}

Thanks in advance :D
 

bhuinda

Terrarian
Hi Terraria forums,

After hours of trying to self-diagnose to no avail, I'm coming here with a couple glaring issues running tModLoader:

1. tModLoader suffers from abnormally low framerates.

I run a GTX 1070 and an i5-11400. Running Terraria 1.4 at 1440p fullscreen, I don't dip below 144 fps. However, running tModLoader at 1440p fullscreen, I'm sitting around 60-70 fps without ANY mods. These numbers are coming after a fresh reinstall of Windows so I don't believe there's any external conflict there.

The one significant difference between the two is that running Task Manager in the background, I've noticed that Terraria utilizes only 20% of my GPU / 15 - 20% CPU while in-game and tModLoader utilizes 80% of the GPU / <10% CPU. If I had to guess this is very much related to the framerate issue, but I don't have the expertise to figure out how or why. I've tried changing the priority of the executable in Task Manager with no change in performance. The framerate in tModLoader increases when switching to 1080p but it still does not reach 144hz in any scene, so framerate does scale based on resolution as it should. If I had to make any guesses it has something to do with the tModLoader code and *potentially* compatibility with my brand new 11400 CPU, but that's all I can think of. Any help there?

2. tModLoader running with Calamity - No Music, Calamity - Music, Cataclysm, Magic Storage, and Boss Checklist (all to-date) CTDs at random at every stage of the game:

I've supplied the client.log from the most recent crash. I crashed three times in short succession just after joining my friend's server.

Playing with two friends in a multiplayer server hosted by one of them, since we have started playing I have crashed at random with increasing frequency especially after entering Hardmode. It happens no matter what I'm doing but is especially problematic during boss battles. When tModLoader crashes like this it's always 1. the screen freezes, 2. the audio cuts out/glitches and repeats, 3. the entire screen turns black (even if I'm playing in a small window), and 4. the screen returns and the executable has either closed or continues functioning, only to eventually CTD, returning no crash log. If a YouTube video is playing in the background I've noticed that the video there sometimes turns a blank green, like my entire computer briefly crashes. To note, neither of my friends have crashed a single time, leading me to believe that my issue is entirely unique to my computer and could possibly be related to the framerate issue.

I've supplied all the info I can think of but if requested I can try to supply more. If anyone out there can help me out that would be greatly appreciated!
 

Attachments

  • client.log
    15.6 KB · Views: 11
Last edited:

fryguythe777th

Terrarian
Hello. I am currently creating an NPC for the first time using code from the ExampleMod. I am receiving multiple errors in my code, which is as follows:

using PogMod.Items.Banners;
using PogMod.Projectiles;
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace PogMod.NPCs
{
//ported from my tAPI mod because I'm lazy
public class YouthTwinklefish : ModNPC
{
public YouthTwinklefish() {
speed = 1f;
speedY = 1f;
acceleration = 0.05f;
accelerationY = 0.05f;
idleSpeed = 0.5f;
bounces = false;
}

public override void SetStaticDefaults() {
DisplayName.SetDefault("Youth Twinklefish");
}
public override void SetDefaults() {
npc.lifeMax = 200;
npc.damage = 90;
npc.defense = 0;
npc.knockBackResist = -0.1f;
npc.width = 26;
npc.height = 26;
npc.aiStyle = 14;
npc.noGravity = true;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.value = Item.buyPrice(0, 0, 15, 0);
npc.hide = true;
banner = npc.type;
bannerItem = ModContent.ItemType<YouthTwinklefishBanner>();
}
public override void FindFrame(int frameHeight) {
npc.frame.Y = 0;
npc.rotation = 0f;
}


public override float SpawnChance(NPCSpawnInfo spawnInfo) {
return !spawnInfo.playerSafe ? SpawnCondition.HardmodeOceanMonster.Chance * 0.5f : 0f;
}
}
}

The area in my code with the issues is colored yellow. The issues are all the same; the names of all the variables do not exist in the current context. Here are the error messages:

[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(15,3) : error CS0103: The name 'speed' does not exist in the current context
[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(16,12) : error CS0103: The name 'speedY' does not exist in the current context
[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(17,3) : error CS0103: The name 'acceleration' does not exist in the current context
[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(18,12) : error CS0103: The name 'accelerationY' does not exist in the current context
[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(19,3) : error CS0103: The name 'idleSpeed' does not exist in the current context
[11:33:36] [Thread Pool Worker/ERROR] [tML]: /Users/patrickpowers/Library/Application Support/Terraria/ModLoader/Mod Sources/PogMod/NPCs/YouthTwinklefish.cs(20,3) : error CS0103: The name 'bounces' does not exist in the current context

Thank you for reading my issue. I hope you will be able to assist me in fixing my code.
 

Chapface

Plantera
Hello. I am currently creating an NPC for the first time using code from the ExampleMod. I am receiving multiple errors in my code, which is as follows:...
It says speed, speedY, acceleration, accelerationY, and idleSpeed do not exist.
You'll have to add either bool, int, float, ect when setting the variables, since they do not exist outside the NPC.
Like this:
Code:
public YouthTwinklefish()
{
    float speed = 1f;
    float speedY = 1f;
    float acceleration = 0.05f;
    float accelerationY = 0.05f;
    float idleSpeed = 0.5f;
    bool bounces = false;


It should also be mentioned, I don't think the YouthTwinklefish() function will ever be called, assuming no external files call on it.
For the variable setting, I'd recommend just removing it. (Unless I'm wrong, in that case just ignore this part)
Code:
namespace PogMod.NPCs
{
    float speed = 1f;
    float speedY = 1f;
    float acceleration = 0.05f;
    float accelerationY = 0.05f;
    float idleSpeed = 0.5f;
    bool bounces = false;
    public override void SetStaticDefaults() 
    {
       DisplayName.SetDefault("Youth Twinklefish");
    }
     //ect
 

fryguythe777th

Terrarian
It says speed, speedY, acceleration, accelerationY, and idleSpeed do not exist.
You'll have to add either bool, int, float, ect when setting the variables, since they do not exist outside the NPC.
Like this:
Code:
public YouthTwinklefish()
{
    float speed = 1f;
    float speedY = 1f;
    float acceleration = 0.05f;
    float accelerationY = 0.05f;
    float idleSpeed = 0.5f;
    bool bounces = false;


It should also be mentioned, I don't think the YouthTwinklefish() function will ever be called, assuming no external files call on it.
For the variable setting, I'd recommend just removing it. (Unless I'm wrong, in that case just ignore this part)
Code:
namespace PogMod.NPCs
{
    float speed = 1f;
    float speedY = 1f;
    float acceleration = 0.05f;
    float accelerationY = 0.05f;
    float idleSpeed = 0.5f;
    bool bounces = false;
    public override void SetStaticDefaults()
    {
       DisplayName.SetDefault("Youth Twinklefish");
    }
     //ect
Thanks for the assistance! My code now works.
 

Simple

Official Terrarian
Collision.SolidCollision is a function. I don't know exactly what you mean by get a variable from one method and use it in another, but what I was suggesting you do is something like the following.
C#:
if (Collision.SolidCollision(npc.position, npc.width, npc.height))
{
    //do the thing
}
That should return true if your NPC is colliding with anything.
Apologies, I mistakenly thought that it was a separate method/function/hook by itself. I will take your advice, thanks!
EDIT: It actually worked, thank you for the advice!
 
Last edited:

EvoLun4r

Terrarian
Say that I wanted to create a throwing weapon, a bomb, that when it explodes, would rain down a few projectiles to it's position. Does anyone know how to do this?

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using NexusMod.Projectiles;

namespace NexusMod.Items.Weapons.Assassin
{
internal class CometDecimator : ModItem
{
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
DisplayName.SetDefault("Comet Decimator");
ItemID.Sets.ItemsThatCountAsBombsForDemolitionistToSpawn[item.type] = true;
}

public override void SetDefaults()
{
item.useStyle = ItemUseStyleID.SwingThrow;
item.shootSpeed = 12f;
item.shoot = ModContent.ProjectileType<Projectiles.CometDecimator>();
item.width = 32;
item.height = 32;
item.maxStack = 1;
item.consumable = true;
item.UseSound = SoundID.Item1;
item.useAnimation = 40;
item.useTime = 40;
item.noUseGraphic = true;
item.noMelee = true;
item.value = Item.sellPrice(0, 0, 20, 0);
item.rare = ItemRarityID.Red;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ModContent.ItemType<CometFragment>());
recipe.AddTile(TileID.LunarCraftingStation);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

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

namespace NexusMod.Projectiles
{
// to investigate: Projectile.Damage, (8843)
internal class CometDecimator : ModProjectile
{
public override void SetDefaults() {
// while the sprite is actually bigger than 15x15, we use 15x15 since it lets the projectile clip into tiles as it bounces. It looks better.
projectile.width = 15;
projectile.height = 15;
projectile.friendly = true;
projectile.penetrate = -1;

projectile.timeLeft = 300;

drawOffsetX = 5;
drawOriginOffsetY = 5;
}

public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) {
// Vanilla explosions do less damage to Eater of Worlds in expert mode, so we will too.
if (Main.expertMode) {
if (target.type >= NPCID.EaterofWorldsHead && target.type <= NPCID.EaterofWorldsTail) {
damage /= 5;
}
}
}


public override void AI() {
if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3) {
projectile.tileCollide = false;
// Set to transparent. This projectile technically lives as transparent for about 3 frames
projectile.alpha = 255;
// change the hitbox size, centered about the original projectile center. This makes the projectile damage enemies during the explosion.
projectile.position = projectile.Center;
//projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
//projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
projectile.width = 250;
projectile.height = 250;
projectile.Center = projectile.position;
//projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
//projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
projectile.damage = 250;
projectile.knockBack = 10f;
}
else {
// Smoke and fuse dust spawn.
if (Main.rand.NextBool()) {
int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1f);
Main.dust[dustIndex].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].noGravity = true;
Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f);
Main.dust[dustIndex].scale = 1f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].noGravity = true;
Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
}
}
projectile.ai[0] += 1f;
if (projectile.ai[0] > 5f) {
projectile.ai[0] = 10f;
// Roll speed dampening.
if (projectile.velocity.Y == 0f && projectile.velocity.X != 0f) {
projectile.velocity.X = projectile.velocity.X * 0.97f;
//if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
{
projectile.velocity.X = projectile.velocity.X * 0.99f;
}
if ((double)projectile.velocity.X > -0.01 && (double)projectile.velocity.X < 0.01) {
projectile.velocity.X = 0f;
projectile.netUpdate = true;
}
}
projectile.velocity.Y = projectile.velocity.Y + 0.2f;
}
// Rotation increased by velocity.X
projectile.rotation += projectile.velocity.X * 0.1f;
return;
}

}
}

However, the popup below appears when I attempt to build and reload the mod. Any ideas why this is happening?
 

Attachments

  • Screenshot 2021-08-03 184245.png
    Screenshot 2021-08-03 184245.png
    230.2 KB · Views: 18

Solo-Ion

Dungeon Spirit
Say that I wanted to create a throwing weapon, a bomb, that when it explodes, would rain down a few projectiles to it's position. Does anyone know how to do this?

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using NexusMod.Projectiles;

namespace NexusMod.Items.Weapons.Assassin
{
internal class CometDecimator : ModItem
{
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
DisplayName.SetDefault("Comet Decimator");
ItemID.Sets.ItemsThatCountAsBombsForDemolitionistToSpawn[item.type] = true;
}

public override void SetDefaults()
{
item.useStyle = ItemUseStyleID.SwingThrow;
item.shootSpeed = 12f;
item.shoot = ModContent.ProjectileType<Projectiles.CometDecimator>();
item.width = 32;
item.height = 32;
item.maxStack = 1;
item.consumable = true;
item.UseSound = SoundID.Item1;
item.useAnimation = 40;
item.useTime = 40;
item.noUseGraphic = true;
item.noMelee = true;
item.value = Item.sellPrice(0, 0, 20, 0);
item.rare = ItemRarityID.Red;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ModContent.ItemType<CometFragment>());
recipe.AddTile(TileID.LunarCraftingStation);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

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

namespace NexusMod.Projectiles
{
// to investigate: Projectile.Damage, (8843)
internal class CometDecimator : ModProjectile
{
public override void SetDefaults() {
// while the sprite is actually bigger than 15x15, we use 15x15 since it lets the projectile clip into tiles as it bounces. It looks better.
projectile.width = 15;
projectile.height = 15;
projectile.friendly = true;
projectile.penetrate = -1;

projectile.timeLeft = 300;

drawOffsetX = 5;
drawOriginOffsetY = 5;
}

public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit, ref int hitDirection) {
// Vanilla explosions do less damage to Eater of Worlds in expert mode, so we will too.
if (Main.expertMode) {
if (target.type >= NPCID.EaterofWorldsHead && target.type <= NPCID.EaterofWorldsTail) {
damage /= 5;
}
}
}


public override void AI() {
if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3) {
projectile.tileCollide = false;
// Set to transparent. This projectile technically lives as transparent for about 3 frames
projectile.alpha = 255;
// change the hitbox size, centered about the original projectile center. This makes the projectile damage enemies during the explosion.
projectile.position = projectile.Center;
//projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
//projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
projectile.width = 250;
projectile.height = 250;
projectile.Center = projectile.position;
//projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
//projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
projectile.damage = 250;
projectile.knockBack = 10f;
}
else {
// Smoke and fuse dust spawn.
if (Main.rand.NextBool()) {
int dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1f);
Main.dust[dustIndex].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].noGravity = true;
Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
dustIndex = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f);
Main.dust[dustIndex].scale = 1f + (float)Main.rand.Next(5) * 0.1f;
Main.dust[dustIndex].noGravity = true;
Main.dust[dustIndex].position = projectile.Center + new Vector2(0f, (float)(-(float)projectile.height / 2 - 6)).RotatedBy((double)projectile.rotation, default(Vector2)) * 1.1f;
}
}
projectile.ai[0] += 1f;
if (projectile.ai[0] > 5f) {
projectile.ai[0] = 10f;
// Roll speed dampening.
if (projectile.velocity.Y == 0f && projectile.velocity.X != 0f) {
projectile.velocity.X = projectile.velocity.X * 0.97f;
//if (projectile.type == 29 || projectile.type == 470 || projectile.type == 637)
{
projectile.velocity.X = projectile.velocity.X * 0.99f;
}
if ((double)projectile.velocity.X > -0.01 && (double)projectile.velocity.X < 0.01) {
projectile.velocity.X = 0f;
projectile.netUpdate = true;
}
}
projectile.velocity.Y = projectile.velocity.Y + 0.2f;
}
// Rotation increased by velocity.X
projectile.rotation += projectile.velocity.X * 0.1f;
return;
}

}
}

However, the popup below appears when I attempt to build and reload the mod. Any ideas why this is happening?
I think that means that it can't find the image for your projectile.
 

Chapface

Plantera
I am trying to check if the WoF is defeated or if the game is the Hardmode, if anyone knows please reply!
The field is Main.hardMode.
I dont think there is a vanilla field for if the WoF was defeated other than just if the world is in hardmode (since they usually serve the same purpose anyway).

So for example,
Code:
if(Main.hardMode == true)
            {
                //code
            }
 
Top Bottom