tModLoader Official tModLoader Help Thread

hi, I've been trying to freeze NPC when i hit them but it doesnt work.

this is the code that i have on my sword:

public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.Frozen, 60000);
}

when i try using other buff such as OnFire they work
 
You can use the hook ModifyDrawLayers in the ModPlayer Class to hide individual layers, then create a loop to hide all of the layers that you want. I'd suggest hiding them by name so that it won't matter if another mod alters the PlayerLayers.

Hope that makes sense.

It does make sense. I thought that perhaps with hueing there might be an easier way. The above modifies the players body so I'll look into hiding equipment as well. So far layer hiding is getting me closer so I think it's the way to go.
 
hi, I've been trying to freeze NPC when i hit them but it doesnt work.

this is the code that i have on my sword:

public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.Frozen, 60000);
}

when i try using other buff such as OnFire they work
This is because NPCs don't have any implementation for the Frozen debuff; not all player buffs work on NPCs. If you want a Frozen-like effect, you will have to write your own logic for it.
 
Lads i need help i want to get tmod loader on mac, i cant find the files ive tried doing the /users/steam ect and the steam properties i cant find it plz help also i wanted to make a mod where do i go to find the page or software to male mods.
[doublepost=1506538760,1506538565][/doublepost]Lads i need help with finding the steam terraria files ive tried the /users and ive tried properties also I wanted to make a mod can I get directions on the software or whatever.
 
Recently i keep getting this same exact error message with anything that has large scale content mods but i can't seem to figure it out.
I'll leave the error log here

ailed to resolve assembly: 'Terraria, Version=1.3.5.1, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArrayArgument(ArrayType type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
at Mono.Cecil.CustomAttribute.<Resolve>b__34_0(CustomAttribute attribute, MetadataReader reader)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.CustomAttribute.Resolve()
at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Terraria.ModLoader.AssemblyManager.LoadedMod.EncapsulateReferences(Byte[] code)
at Terraria.ModLoader.AssemblyManager.LoadedMod.LoadAssemblies()
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)
 
Recently i keep getting this same exact error message with anything that has large scale content mods but i can't seem to figure it out.
I'll leave the error log here

ailed to resolve assembly: 'Terraria, Version=1.3.5.1, Culture=neutral, PublicKeyToken=null'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArrayArgument(ArrayType type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
at Mono.Cecil.CustomAttribute.<Resolve>b__34_0(CustomAttribute attribute, MetadataReader reader)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.CustomAttribute.Resolve()
at Mono.Cecil.CustomAttribute.get_ConstructorArguments()
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider)
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type)
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types)
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module)
at Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Terraria.ModLoader.AssemblyManager.LoadedMod.EncapsulateReferences(Byte[] code)
at Terraria.ModLoader.AssemblyManager.LoadedMod.LoadAssemblies()
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)
Do steam's verify integrity of game cache on Terraria, and then reinstall the latest tModLoader. Should work.
or, I have a gif showing how to install tmodloader: It needed music on it because otherwise my recorder crashes due to some bug https://streamable.com/4zurs
 
I need a hand with some coding. In my mod I am going to make an event, and I want one of my custom enemies to only spawn in that event. I haven't made the event yet but I am coding the NPC. How would I tell it to only spawn in an event that ISN'T part of vanilla Terraria but instead part of my mod.

Edit: My NPC is stuck on the ground but it is supposed to be floating... is there a simple way to toggle gravity off for my NPC? if not what can I do to make it not use gravity?

Edit: Another question I had would be how to make a projectile give a custom debuff when it hits something. I know how to make it give an already existing one but I want it to give one that is part of my mod.
 
Last edited:
I need a hand with some coding. In my mod I am going to make an event, and I want one of my custom enemies to only spawn in that event. I haven't made the event yet but I am coding the NPC. How would I tell it to only spawn in an event that ISN'T part of vanilla Terraria but instead part of my mod.

Edit: My NPC is stuck on the ground but it is supposed to be floating... is there a simple way to toggle gravity off for my NPC? if not what can I do to make it not use gravity?

Edit: Another question I had would be how to make a projectile give a custom debuff when it hits something. I know how to make it give an already existing one but I want it to give one that is part of my mod.
Use a bool in a ModWorld class which is set to true when the event is active
 
I have two problems; one enemy related, the other accessory related.

Problem 1: Shark-type enemy floating above where it should be.
Solved: I just moved the sprites down by 10 pixels, and it fixed it without any issues. The simplest things work sometimes.
Trying my hand at modding an enemy in, and I'm having trouble with an enemy's sprite showing in the game. I managed to make a working shark enemy, following the same AI and whatnot. I don't know if I got the thing ENTIRELY right, but it has gore, the same movement and ai type, and so on. The problem is that when I spawn it to make sure it works, its sprite is offset a bit off the ground for some reason. I noticed it when I was having it spawn naturally, and the modded shark was higher up than it should have been (as evident from a normal shark nearby) The sprite is a 1:1 copy of the default shark, just colored differently and with a few small extra details (Nothing that increases its dimensions, of course). Why would something like that happen? Here's the file I have for my current shark;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Harble_World_Spicer.NPCs
{
public class enemy_Reaver_Shark_01 : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Reaver Shark");
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Shark];
}

public override void SetDefaults()
{
npc.noGravity = true;
npc.width = 100;
npc.height = 24;
npc.damage = 120;
npc.defense = 100;
npc.lifeMax = 100;
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
npc.value = 400f;
npc.knockBackResist = 1.0f;
npc.aiStyle = 16;
aiType = NPCID.Shark;
animationType = NPCID.Shark;
}

public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
return SpawnCondition.OceanMonster.Chance * 0.1f;
Main.hardMode = true;
}

public override void NPCLoot()
{
if (Main.rand.Next(98) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.DivingHelmet);
}
}

public override void HitEffect(int hitDirection, double damage)
{
if (npc.life <= 0)
{
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/enemy_Reaver_Shark_01_01"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/enemy_Reaver_Shark_01_02"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/enemy_Reaver_Shark_01_03"), 1f);
Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/enemy_Reaver_Shark_01_04"), 1f);
}
}
}
}
And here's the example of it floating; https://i.imgur.com/1ps6Mka.png (I know, sharks are water animals, but they can jump on land if you trick them to! This is just a demonstration)

I'm sure my coding is probably very basic and sloppy, but I genuinely don't know exactly what I need for the shark. Is something in my code causing this odd floating behavior? Likewise, I have a few extra questions on what I'd need to add to my code for the following;

- How would I make this enemy spawn only in hard mode? There's not hard mode ocean spawnCondition.
- How would I increase or decrease how fast it swims through the water?
- How would I scale it up or down without editing the sprite's dimensions? Similar to some enemies naturally spawning slightly bigger or smaller, like Eater of Souls.
- How would I alter the above if I did use different sprite dimensions? For example, a shark whose three frames are each 1000 wide by 100 high.

Problem 2: Accessory causing mod to not compile.
I wanted my own ridiculous bundle of balloons, so I made a sprite and .cs file. I get the following error:
Items/Acc_Balloon_Giga_Bundle_01_Balloon
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AddEquipTexture(ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AutoloadItem(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

My accessory cs is as follows;
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Harble_World_Spicer.Items
{
[AutoloadEquip(EquipType.Balloon)]
public class Acc_Balloon_Giga_Bundle_01 : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Balloon Mega Bundle");
Tooltip.SetDefault("Up!");
}

public override void SetDefaults()
{
item.width = 24;
item.height = 28;
item.value = Item.buyPrice(0, 5, 0, 0);
item.rare = 7;
item.accessory = true;

}

public override void UpdateAccessory(Player player, bool hideVisual)

{
player.jumpBoost = true;
player.doubleJumpCloud = true;
player.doubleJumpBlizzard = true;
player.doubleJumpSandstorm = true;
player.doubleJumpFart = true;
player.doubleJumpSail = true;
player.doubleJumpUnicorn = true;
player.waterWalk = true;
player.slowFall = true;
player.bee = true;
player.noFallDmg = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.LuckyHorseshoe, 1);
recipe.AddIngredient(ItemID.BundleofBalloons, 1);
recipe.AddIngredient(ItemID.HoneyBalloon, 1);
recipe.AddIngredient(ItemID.FartInABalloon, 1);
recipe.AddIngredient(ItemID.BalloonPufferfish, 1);
recipe.AddIngredient(ItemID.SharkronBalloon, 1);
recipe.AddIngredient(ItemID.PartyBundleOfBalloonsAccessory, 1);
recipe.AddIngredient(ItemID.PartyBalloonAnimal, 1);
recipe.AddTile(TileID.TinkerersWorkbench); //WorkBenches, Anvils, MythrilAnvil, Furnaces, DemonAltar, or TinkerersWorkbench
recipe.SetResult(this);
recipe.AddRecipe();
}

}
}

What do I need to do to allow my accessory to work?

These issues are causing me a bit more trouble than they need to. I appreciate any and all help in getting this stuff squared away!
 
Last edited:
I have a question about something. I am making a town NPC and I want it to have a different texture depending on what it's name is. (For example: if its name is Bob it should use the BobSprite.png file but if its name is Harry it should use the HarrySprite.png file) Is there a way to do this?
 
Im trying to add my recipes but it gives the error:
c:\directory\Botania\Botania.cs(24,32): error CS0103: The name 'mod' does not exist in the current context

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

namespace Botania
{
    class Botania : Mod
    {
        public Botania()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
        public override void AddRecipes()
        {
            // Flower station recipe
            Error refers to here --> ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.StoneBlock, 30);
            recipe.AddIngredient(this, "Mana");
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this, "FlowerStation");
            recipe.AddRecipe();
            // Pure daisy recipe
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DaybloomSeeds, 3);
            recipe.AddIngredient(this, "Mana");
            recipe.AddTile(null, "FlowerStation");
            recipe.SetResult(this, "PureDaisy");
            recipe.AddRecipe();
            // Livingrock recipe
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.StoneBlock, 3);
            recipe.AddTile(null, "PureDaisy");
            recipe.SetResult(this, "Livingrock");
            recipe.AddRecipe();
        }
    }
}
 
Im trying to add my recipes but it gives the error:
c:\directory\Botania\Botania.cs(24,32): error CS0103: The name 'mod' does not exist in the current context

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

namespace Botania
{
    class Botania : Mod
    {
        public Botania()
        {
            Properties = new ModProperties()
            {
                Autoload = true,
                AutoloadGores = true,
                AutoloadSounds = true
            };
        }
        public override void AddRecipes()
        {
            // Flower station recipe
            Error refers to here --> ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.StoneBlock, 30);
            recipe.AddIngredient(this, "Mana");
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this, "FlowerStation");
            recipe.AddRecipe();
            // Pure daisy recipe
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DaybloomSeeds, 3);
            recipe.AddIngredient(this, "Mana");
            recipe.AddTile(null, "FlowerStation");
            recipe.SetResult(this, "PureDaisy");
            recipe.AddRecipe();
            // Livingrock recipe
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.StoneBlock, 3);
            recipe.AddTile(null, "PureDaisy");
            recipe.SetResult(this, "Livingrock");
            recipe.AddRecipe();
        }
    }
}
Since you are inside the mod class, change mod to this
 
c:\Users\John\Documents\My Games\Terraria\ModLoader\Mod Sources\MyMod\Items\NPCsINFO.cs(5,29) : error CS0246: The type or namespace name 'NPCInfo' could not be found (are you missing a using directive or an assembly reference?)

i get this error every time i try to launch my mod

using Terraria.ModLoader;

namespace MyMod.Items
{
public class NPCsINFO : NPCInfo
{
public bool customdebuff = false;
}
}
 
I have a question about something. I am making a town NPC and I want it to have a different texture depending on what it's name is. (For example: if its name is Bob it should use the BobSprite.png file but if its name is Harry it should use the HarrySprite.png file) Is there a way to do this?
Well, I haven't done this myself, but you can manually load a texture for your NPC with the Texture hook. The example mod shows you how to do this:
Code:
public override string Texture
{
    get
    {
        return "ExampleMod/NPCs/ExamplePerson";
    }
}
You could replace the single return line with a bit of script that randomly picks a number one less than the number of textures that you want, stores it outside of the hook, then loads a texture based on the number generated. Then you'd use the TownNPCName hook to check what the random number was and pick a name based on that number.
 
Heya! So I've been digging in and working on code for almost 24 hours now... sleep dep has sunk in but I've gotten a (relative) LOT done for the little things I wanted, including a projectile that rotates around the player, clips graphically through tiles but won't damage through them, and only lasts while being channeled. I also put the finishing adjustments on a thrown weapon inspired by the improvisational techniques of a certain wizard up a tree.

I'm stuck trying to figure out how to get a vanilla sound to loop while my new weapon is being channeled. My working code looks like this:
Code:
if (player.channel)
            {
                Main.PlaySound(SoundID.Item15);
            }

... but what that does is play the beginning of the Phasesaber sound while channeled, then completes the sound when released, which means it just plays a very low, monotonous hum while channeled, not the thrum I'm looking for. What I'd like is for it to play the sound through over and over while channeled, but everything I've tried from ExampleMod, searches on these forums, and even MS C# documents hasn't worked. I know for sure it's because I don't yet have a solid grasp of the syntax, so I probably missed something obvious, but I'm down to either asking here (Discord, helpful as they've been for all this so far, doesn't have an answer), or re-inventing the laser wheel by re-creating the sound as a custom sound and using the WatchOut sound's example from ExampleMod to make it play through before looping.

Any insight would be appreciated!

Edit: Actually, nevermind! After getting a banner FOUR HOURS of sleep and taking another look at ExampleLightPet and WatchOut, I realized it was pretty easy! Now I just need to adjust the speed and variance!
 
Last edited:
Back
Top Bottom