tModLoader Official tModLoader Help Thread

Is the sentry in your weapons folder? Because if it is, you need to add .Weapons to namespace customsentry.Items

the sentry is in My Games\Terraria\ModLoader\Mod Sources\vangloriansword\Items. the png is called customsentry, at the same time than the .cs, this is the code of customsentry.cs

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameInput;

namespace customsentry.Items
{
public class customsentry : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("customsentry");
Tooltip.SetDefault("This is a modded sword.");
}
public override void SetDefaults()
{
item.damage = 60; //The damage stat for the Weapon.
item.mana = 20; //this defines how many mana this weapon use
item.width = 56; //The size of the width of the hitbox in pixels.
item.height = 56; //The size of the height of the hitbox in pixels.
item.useTime = 25; //How fast the Weapon is used.
item.useAnimation = 25; //How long the Weapon is used for.
item.useStyle = 1; //The way your Weapon will be used, 1 is the regular sword swing for example
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 2.5f; //The knockback stat of your Weapon.
item.value = Item.buyPrice(0, 10, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
item.rare = 8; //The color the title of your Weapon when hovering over it ingame
item.UseSound = SoundID.Item44; //The sound played when using your Weapon
item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
item.shoot = mod.ProjectileType("CustomSentryProj"); //This defines what type of projectile this weapon will shot
item.summon = true; //This defines if it does Summon damage and if its effected by Summon increasing Armor/Accessories.
item.sentry = true; //tells the game that this is a sentry
}

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 SPos = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY); //this make so the projectile will spawn at the mouse cursor position
position = SPos;
for (int l = 0; l < Main.projectile.Length; l++)
{ //this make so you can only spawn one of this projectile at the time,
Projectile proj = Main.projectile[l];
if (proj.active && proj.type == item.shoot && proj.owner == player.whoAmI)
{
proj.active = false;
}
}
return true;
}
}
}

if you can, tell where is something than doesnt have as a name "customsentry" or "CustomSentryProj".
 
the sentry is in My Games\Terraria\ModLoader\Mod Sources\vangloriansword\Items. the png is called customsentry, at the same time than the .cs, this is the code of customsentry.cs

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameInput;

namespace customsentry.Items
{
public class customsentry : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("customsentry");
Tooltip.SetDefault("This is a modded sword.");
}
public override void SetDefaults()
{
item.damage = 60; //The damage stat for the Weapon.
item.mana = 20; //this defines how many mana this weapon use
item.width = 56; //The size of the width of the hitbox in pixels.
item.height = 56; //The size of the height of the hitbox in pixels.
item.useTime = 25; //How fast the Weapon is used.
item.useAnimation = 25; //How long the Weapon is used for.
item.useStyle = 1; //The way your Weapon will be used, 1 is the regular sword swing for example
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 2.5f; //The knockback stat of your Weapon.
item.value = Item.buyPrice(0, 10, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
item.rare = 8; //The color the title of your Weapon when hovering over it ingame
item.UseSound = SoundID.Item44; //The sound played when using your Weapon
item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
item.shoot = mod.ProjectileType("CustomSentryProj"); //This defines what type of projectile this weapon will shot
item.summon = true; //This defines if it does Summon damage and if its effected by Summon increasing Armor/Accessories.
item.sentry = true; //tells the game that this is a sentry
}

public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 SPos = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY); //this make so the projectile will spawn at the mouse cursor position
position = SPos;
for (int l = 0; l < Main.projectile.Length; l++)
{ //this make so you can only spawn one of this projectile at the time,
Projectile proj = Main.projectile[l];
if (proj.active && proj.type == item.shoot && proj.owner == player.whoAmI)
{
proj.active = false;
}
}
return true;
}
}
}

if you can, tell where is something than doesnt have as a name "customsentry" or "CustomSentryProj".

I found the problem. The namespace customsentry.Items should be namespace vangloriansword.Items
 
Hello !
Im new to modding and I need some help.
So i'm trying to make an unnerf rod of discord (When you had no CD on TP) and i have 2 problems.
Since i started like 1h ago I have my sprite, my animation and part of the tp.

- I need to get the tile type under my mouse position (Or maybe more like "around" my mouse position) to see if I can TP or not. And I can't find anything about "world" related tiles - something like a huge array of all the tiles of the map. Sorry if a similar questions has been asked before. 187 pages are a lot of pages to check :sigh:

- And less importantly, when you use the actual rod of discord you have a little "fade to black" effect. I wonder if you can do something similar with tmodloader :)
Here's some quick code that will check if the tile at the mouse's position is solid. (i.e., if the player can pass though it).
Code:
if (Main.tileSolid[Main.tile[(int)Main.MouseWorld.X, (int)Main.MouseWorld.Y].type])
{
    Main.NewText("This tile is solid");
} else
{
    Main.NewText("This tile is not solid");
}
There's also a function for checking if an area is solid or not, but I don;t have time to find it right now. Maybe another day.
 
I found the problem. The namespace customsentry.Items should be namespace vangloriansword.Items
thanks nun, everything worked fine, but now i have an issue with a minion staff

here is the code

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameInput;

namespace vangloriansword.Projectiles.Minions
{
public class MinionName : MinionINFO
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("CustomSentryProj");
}
public override void SetDefaults()
{
projectile.netImportant = true;
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];
Player 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;
}
}
}
}

and the log

My Games\Terraria\ModLoader\Mod Sources\vangloriansword\Projectiles\Minions\MinionName.cs(47,33) : error CS0246

My Games\Terraria\ModLoader\Mod Sources\vangloriansword\Projectiles\Minions\MinionName.cs(50,27) : error CS1061

My Games\Terraria\ModLoader\Mod Sources\vangloriansword\Projectiles\Minions\MinionName.cs(52,27) : error CS1061

sorry if i bother you about all this errors. im just getting started on terraria modding :happy:.
 
guys, somewhere in this thread (or in another thread) must be a chest frame table for generating items in those chests, but i can't find it. maybe someone have it? i'll be really appreciate.
 
I'm trying to change some vanilla tiles to be immune to explosions.
Code:
public virtual bool CanExplode(int i, int j, int type)
        {
            if (type == TileID.Ebonstone && Main.hardMode == false && Config.BombNerf)
            {
                return false;
            }
            return true;
            if (type == TileID.Pearlstone && Main.hardMode == false && Config.BombNerf)
            {
                return false;
            }
            return true;
            if (type == TileID.Crimstone && Main.hardMode == false && Config.BombNerf)
            {
                return false;
            }
            return true;
        }
I have something here, which loads fine, but doesn't actually make the tiles immune to explosives. What am I doing wrong? And yes, the config setting is set to true.
 
Hi Everyone, Im new Here, how is Everyone?
Anyways, i have an problem...
im trying to make a Zombie for my mod (Most likely not going to be released)
but every time it comes up with this "Error CS0115 TestMod.NPCs.ModdedZombie.CanSpawn(Terraria.ModLoader.NPCSpawnInfo)': no suitable method found to override"
heres the code for the NPC
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Minecraft.NPCs
{
public class MCZombie : ModNPC
{
public override void SetDefaults()
{
npc.name = "Minecraft Zombie";
npc.displayName = "Zombie";
npc.width = 18;
npc.height = 40;
npc.damage = 30;
npc.defense = 2;
npc.lifeMax = 500;
npc.HitSound = SoundID.Item1;
npc.DeathSound = SoundID.Item10;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 3; //see here: http://tconfig.wikia.com/wiki/List_of_NPC_AI_Styles
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Zombie];
aiType = NPCID.Harpy;
animationType = NPCID.Zombie;
}

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
return spawnInfo.spawnTileY < Main.worldSurface && Main.dayTime ? 1.0f : 0f; //spawn at day
}

public override void NPCLoot()
{
if (Main.rand.Next(1, 50) == 1) //drop chance - This gives a 49% chance as 50-1 = 49
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.LunarBar, Main.rand.Next(5, 10)); //amount
}
}
}
}
could anyone help me?
thanks to whoever helps me, also, its not just this, any other thing that isn't a weapon has the same error.
 
So. I'm really new to modding. Really. First item got made and sprited yesterday. As me and my friends laughed because I made it just about 300 tiles high. But, with spriting, I'm using paint.net (recommened by GitHub) and my problem is that I can't remove the background off the sprite. When I swing it, behind it is white and it covers walls. It's a white box around the weapon, which is from the background of the sprite. How do I remove it?
 
So. I'm really new to modding. Really. First item got made and sprited yesterday. As me and my friends laughed because I made it just about 300 tiles high. But, with spriting, I'm using paint.net (recommened by GitHub) and my problem is that I can't remove the background off the sprite. When I swing it, behind it is white and it covers walls. It's a white box around the weapon, which is from the background of the sprite. How do I remove it?
For a sprite to be transparent in game, the .png file of that sprite must also be transparent. You must have started with a white background when you painted your sword, so you'll need to erase the white to transparent. I don't actually know how to use paint.net, but look for a way to select a colour range so that you can select all white pixels then delete them. Turn to Google if that's not enough information because that's all I can guess.
 
For a sprite to be transparent in game, the .png file of that sprite must also be transparent. You must have started with a white background when you painted your sword, so you'll need to erase the white to transparent. I don't actually know how to use paint.net, but look for a way to select a colour range so that you can select all white pixels then delete them. Turn to Google if that's not enough information because that's all I can guess.
I fixed it, using a different site now, but can you fix my spaghetti coding? I was trying to make a bow (damn right I almost did) and I keep getting an error that the "Documents\My Games\Terraria\ModLoader\Mod Sources\MyFirstMod\Items(34,36) : error CS0246: The type or namespace name 'MyPlayer' could not be found (are you missing a using directive or an assembly reference?)" Also heres my coding. (for the section it's messed up.)


public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 
Last edited:
Hi. I have a problem creating a accesory. When I build the source this error appears (The error actually appears on Spanish, cuz I'm in Argentina, but I tried to translate it) : It wasn't found any suitable member to invalidate. Here is my code, the error is in the UpdateAccesory(Player...) line (I checked the ExampleMod and it is just like that)

using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace GoliatMod.Items
{
public class MeleeTalisman : ModItem
{
public override void SetDefaults()
{
item.width = 10;
item.height = 15;
item.value = 0;
item.rare = 2;
item.accesory = true;
}

public override void AddRecipes()
{
ModRecipe recipe = newModRecipe(mod);
recipe.AddIngredient(mod, "DivineTalisman")
recipe.SetResult(this);
recipe.AddRecipe();
}

public override void UpdateAccesory(Player player, bool hideVisual)
{
player.meleeCrit += 17;
player.meleeDamage += 0.22f;
player.meleeSpeed += 0.15f;
}
}
}
 
Last edited:
Hi

I'm coming from tAPI, so I have zero experience with C#, so I'm super sorry if I miss something obvious.

I was trying to test out tModLoader, but it refuses to build anything, even the plain skeleton mod from the generator with no changes.
Here is the error:
20170728214111_1.jpg
 
Hi

I'm coming from tAPI, so I have zero experience with C#, so I'm super sorry if I miss something obvious.

I was trying to test out tModLoader, but it refuses to build anything, even the plain skeleton mod from the generator with no changes.
Here is the error:
View attachment 178019
I'm guessing when it told you to not put spaces, you still put spaces. Remove spaces in the filenames, classnames.
 
Hi,

I'm trying to make a recipe for a vanilla item that doesn't have one (magic lantern)

However, the recipe doesn't work. In fact, the recipe doesn't show at all in-game.

The skeleton for this was generated from the mod skeleton generator.

Here is the code for the main .cs file:

using Terraria.ID;
using Terraria.ModLoader


namespace norngforrng
{
class norngforrng : Mod
{
public norngforrng()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
};
ModRecipe recipe = new ModRecipe(this);

recipe.AddIngredient(ItemID.GoldBar, 10);
recipe.AddIngredient(ItemID.GlassWall, 10);
recipe.AddIngredient(ItemID.Torch, 2);
recipe.AddTile(TileID.Anvils);
recipe.needLava = true;
recipe.SetResult(ItemID.MagicLantern);
recipe.AddRecipe();
}
}
}
You have to add recipes in the AddRecipes hook, look at ExampleMod for an example.
 
Hi again,

I'm trying to make a sword that fires a projectile. The sword's code isn't generating any errors, but the projectile's code refuses to build.
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Terraria;
using Terraria.ModLoader;

namespace SmashPvP.Projectiles
{
    public class Projectile1 : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Projectile 1";
            projectile.width = 32;
            projectile.height = 32;
            projectile.timeLeft = 60;
            projectile.penetrate = 1;
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.tileCollide = true;
            projectile.ignoreWater = true;
            projectile.melee = true;
            projectile.aiStyle = 0;
        }
    }
}
20170729112241_1.jpg
 
Did that, but now it keeps giving me an error that there should be a } where there already is one (norngforrng.cs(16,5) : error CS1513: } expected). The line the error is referencing looks like this: }

It is the line that is supposed to close the ModProperties part of the code

If I add another one to it, it gives an error saying there needs to be a ; there now,

Then if I add that to it, the error says a semicolon after method or accessor block is not valid.

How do I fix this?
Show Code.
 
Show Code.

using Terraria.ID;
using Terraria.ModLoader;


namespace norngforrng
{
class norngforrng : Mod
{
public norngforrng()
{
Properties = new ModProperties()
{
Autoload = true,
AutoloadGores = true,
AutoloadSounds = true
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(this);
recipe.AddIngredient(ItemID.GoldBar, 10);
recipe.AddIngredient(ItemID.GlassWall, 10);
recipe.AddIngredient(ItemID.Torch, 2);
recipe.AddTile(TileID.Anvils);
recipe.AddTile(TileID.CrystalBall);
recipe.needLava = true;
recipe.SetResult(ItemID.MagicLantern);
recipe.AddRecipe();
}
}
}
 
D: This error is preventing me from making my mod, how do I select the name and the tooltip of my accesory?

When I build it gives me this error : 'Terraria.Item' does not contain a definition for 'name' and no extension method 'name' accepting a first argument of type 'Terraria.Item' could be found (are you missing a using directive or an assembly reference?)

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

namespace GoliatMod.Items
{
public class SummonerTalisman : ModItem
{
public override void SetDefaults()
{
item.name = "Goliat Talisman";
item.width = 10;
item.height = 14;
item.value = 0;
item.rare = 2;
item.accessory = true;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "DivineTalisman");
recipe.SetResult(this);
recipe.AddRecipe();
}

public override void UpdateAccessory(Player player, bool hideVisual)
{

player.maxMinions += 1;
player.minionDamage += 0.10f;
}
}
}
 
Back
Top Bottom