tModLoader Official tModLoader Help Thread

How to kill item on pickup? I want to make something like nebula bonuses, mana, or hearts, but when I write the code in
Code:
public override bool OnPickup(Player player) {}
, then it still stays in my inventory. How to solve this?
 
could you help me and please tell me what i need to change? my staff code:


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

namespace mod_terraria_another_dimension.items (my mod).Weapons (my mod)
{
public class the heart cooler : ModItem
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("cool your enemys heart");
Item.staff[item.type] = true; //this makes the useStyle animate as a staff instead of as a gun
}

public override void SetDefaults() {
item.damage = 11;
item.magic = true;
item.mana = 7;
item.width = 40;
item.height = 40;
item.useTime = 25;
item.useAnimation = 25;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 5;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item29;
item.autoReuse = true;
item.shoot = mod.ProjectileType("the heart cooler proj");
item.shootSpeed = 16f;
}

public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod.ItemType("Snow Block"), 15); //you can make multiple needed recipes by pressing the enter button and writing the same thing but whith an other item and maybe a different amoutn of the item!!!!!!!
recipe.AddIngredient(mod.ItemType("Ice Block"), 15);
recipe.AddIngredient(mod.ItemType("Lesser Mana Potion"), 7);
recipe.AddTile(mod.TileType("WorkBenches"));
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}


my projectile code:

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

namespace mod_terraria_another_dimension.Projectiles (my mod)
{
public class the heart cooler proj : ModProjectile
{
public override void SetDefaults() {
projectile.width = 16;
projectile.height = 16;
projectile.friendly = true;
projectile.magic = true;
projectile.penetrate = 3;
projectile.timeLeft = 600;
}

public override void AI() {
projectile.velocity.Y += projectile.ai[0];
if (Main.rand.NextBool(3)) {
Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, mod.DustType("the heart cooler proj dust"), projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f);
}
}

public override bool OnTileCollide(Vector2 oldVelocity) {
projectile.penetrate--;
if (projectile.penetrate <= 0) {
projectile.Kill();
}
else {
projectile.ai[0] += 0.1f;
if (projectile.velocity.X != oldVelocity.X) {
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y) {
projectile.velocity.Y = -oldVelocity.Y;
}
projectile.velocity *= 0.75f;
Main.PlaySound(SoundID.Item10, projectile.position);
}
return false;
}

public override void Kill(int timeLeft) {
for (int k = 0; k < 5; k++) {
Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, mod.DustType("the heart cooler proj dust"), projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f);
}
Main.PlaySound(SoundID.Item25, projectile.position);
}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) {
projectile.ai[0] += 0.1f;
projectile.velocity *= 0.75f;
}
}
}


my projectile dust code:

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

namespace mod_terraria_another_dimension.Dusts (my mod)
{
public class the heart cooler proj dust : ModDust
{
public override void OnSpawn(Dust dust) {
dust.noLight = true;
dust.color = new Color(200, 220, 230);
dust.scale = 1.2f;
dust.noGravity = true;
dust.velocity /= 2f;
dust.alpha = 100;
}

public override bool Update(Dust dust) {
dust.position += dust.velocity;
dust.rotation += dust.velocity.X;
Lighting.AddLight((int)(dust.position.X / 16f), (int)(dust.position.Y / 16f), 0.05f, 0.15f, 0.2f);
dust.scale -= 0.03f;
if (dust.scale < 0.5f) {
dust.active = false;
}
return false;
}
}
}

IAM using notepad++ and i did find these codes in here:blushiemagic/tModLoader

i did turn the files into .cs files btw and here are my sprites (please DO NOT steal these sprites!!!!! piskel IS free!!!!!) my staff sprite:Piskel - the heart cooler

my projectile sprite:Piskel - the heart cooler proj

my projectile dust sprite:Piskel - the heart cooler proj dust

the error:
c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Dusts (my mod)\the heart cooler proj dust.cs(5,48) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Dusts (my mod)\the heart cooler proj dust.cs(7,19) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Dusts (my mod)\the heart cooler proj dust.cs(7,32) : error CS1002: ; erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Dusts (my mod)\the heart cooler proj dust.cs(7,42) : error CS1002: ; erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Dusts (my mod)\the heart cooler proj dust.cs(8,2) : error CS1519: Ungültiges Token '{' in Klasse, Struktur oder Schnittstellenmemberdeklaration.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\items (my mod)\Weapons (my mod)\the heart cooler.cs(5,48) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\items (my mod)\Weapons (my mod)\the heart cooler.cs(7,19) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\items (my mod)\Weapons (my mod)\the heart cooler.cs(7,32) : error CS1002: ; erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\items (my mod)\Weapons (my mod)\the heart cooler.cs(8,2) : error CS1519: Ungültiges Token '{' in Klasse, Struktur oder Schnittstellenmemberdeklaration.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Projectiles (my mod)\the heart cooler proj.cs(6,54) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Projectiles (my mod)\the heart cooler proj.cs(8,19) : error CS1514: { erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Projectiles (my mod)\the heart cooler proj.cs(8,32) : error CS1002: ; erwartet.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Projectiles (my mod)\the heart cooler proj.cs(8,37) : error CS1519: Ungültiges Token ':' in Klasse, Struktur oder Schnittstellenmemberdeklaration.

c:\Users\\Documents\My Games\Terraria\ModLoader\Mod Sources\mod_terraria_another_dimension\Projectiles (my mod)\the heart cooler proj.cs(9,2) : error CS1519: Ungültiges Token '{' in Klasse, Struktur oder Schnittstellenmemberdeklaration.



it would be nice if ANYONE could help me out please dont reply with i dont know how to fix this if you dont know!!!! thank you!!!!

sorry cause of the spaces!!!!!
The problem will most likely be because of the spaces in your class name. E.g. "public class the heart cooler : ModItem" should be "public class TheHeartCooler : ModItem" or something.
 
The problem will most likely be because of the spaces in your class name. E.g. "public class the heart cooler : ModItem" should be "public class TheHeartCooler : ModItem" or something.
you should download visual studio, because it has linter and will help you with making code (linter is a program which highlights errors and shows potential solutions)
 
How to kill item on pickup? I want to make something like nebula bonuses, mana, or hearts, but when I write the code in
Code:
public override bool OnPickup(Player player) {}
, then it still stays in my inventory. How to solve this?
It stays because you're not actually doing anything; You're calling the method, but not telling it to do anything out of the ordinary. Try using this:
Code:
public override bool OnPickup(Player player)
{
   //<Whatever you want the item to do before dying, like adding a buff or healing>
   item.TurnToAir();
   return base.OnPickup(player);
}
 
It stays because you're not actually doing anything; You're calling the method, but not telling it to do anything out of the ordinary. Try using this:
Code:
public override bool OnPickup(Player player)
{
   //<Whatever you want the item to do before dying, like adding a buff or healing>
   item.TurnToAir();
   return base.OnPickup(player);
}
Thank you! I tried this method before but it threw random errors and now I realized i used it the wrong way
 
I am using tmodloader 10.1.5. with Heros mod for kick and ban help. When I save and exit I do not see the world saving in the console. I have to manually click type save in the console and it will work. Isn't it supposed to auto safe on exit?
 
I am using tmodloader 10.1.5. with Heros mod for kick and ban help. When I save and exit I do not see the world saving in the console. I have to manually click type save in the console and it will work. Isn't it supposed to auto safe on exit?
when you save and exit on the client, it won't affect the server. I think the server will autosave when you exit it properly.
 
Hello. Assistance with the NPC implementation is needed. I would like to see one code example of an enemy which shoots something simple like arrow or other projectile instead of just melee damaging behavior. Example mod isn't giving proper information about it:)
[doublepost=1555863175,1555862995][/doublepost]Does anyone has any idea where to search or how to make worm-type enemy like wyvern. (head and all body is always not upside down)
 
How do I make my player invisible when the custom buff is on?
Code:
using Terraria;
using Terraria.ModLoader;

namespace ________.Buffs
{
    public class Ghost : ModBuff
    {
        public override void SetDefaults() {
            DisplayName.SetDefault("________");
            Description.SetDefault("_______");
            Main.buffNoTimeDisplay[Type] = true;
        }

        public override void Update(Player player, ref int buffIndex) {
            
        }
    }
}
I've tried things like "invisible", "invisibility", "opacity", "transparency", etc.
Please help! :cool:
 
How do I make my player invisible when the custom buff is on?
Code:
using Terraria;
using Terraria.ModLoader;

namespace ________.Buffs
{
    public class Ghost : ModBuff
    {
        public override void SetDefaults() {
            DisplayName.SetDefault("________");
            Description.SetDefault("_______");
            Main.buffNoTimeDisplay[Type] = true;
        }

        public override void Update(Player player, ref int buffIndex) {
           
        }
    }
}
I've tried things like "invisible", "invisibility", "opacity", "transparency", etc.
Please help! :cool:
Have you tried player.invis = true; ??
First one I found.
 
Can anyone help? So I got a new laptop and moved my characters via the steam cloud but when I downloaded tmodloader they all disapeared and are not in mygames/terraria/players because of how I transferred them. Is there any way to get them back?
 
Can anyone help?
i keep getting this error

ScaleExpertStats(int, float) no suitable method to override


public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.625f * bossLifeScale);
npc.damage = (int)(npc.damage * 0.6f);
npc.defense = (int)(npc.defense + numPlayers);

thats where i think the problem is
but heres the whole code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MoreContent.NPCs.Boss
{
[AutoloadBossHead]
public class BlueScreenOfDeath : ModItem
{
private Player player;
private float speed;

public override void SetStaticDefaults()
{
DisplayName.SetDefault("Error404");
Main.npcFrameCount[npc.type] = 3;
}

public override void SetDefaults()
{
npc.aiStyle = -1; // Will not have any AI from any existing AI styles.
npc.lifeMax = 1000; // The Max HP the boss has on Normal
npc.damage = 20; // The base damage value the boss has on Normal
npc.defense = 25; // The base defense on Normal
npc.knockBackResist = 0f; // No knockback
npc.width = 100;
npc.height = 100;
npc.value = 10000;
npc.npcSlots = 1f; // The higher the number, the more NPC slots this NPC takes.
npc.boss = true; // Is a boss
npc.lavaImmune = false; // Not hurt by lava
npc.noGravity = true; // Not affected by gravity
npc.noTileCollide = false; // Will not collide with the tiles.
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath1;
music = MusicID.Boss1;
bossBag = mod.ItemType("AnErrorOccured"); // Needed for the NPC to drop loot bag.
}



public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.625f * bossLifeScale);
npc.damage = (int)(npc.damage * 0.6f);
npc.defense = (int)(npc.defense + numPlayers);
}

public override void AI()
{
Target(); // Sets the Player Target

DespawnHandler(); // Handles if the NPC should despawn.

Move(new Vector2(0, -100f)); // Calls the Move Method
//Attacking
npc.ai[1] -= 1f; // Subtracts 1 from the ai.
if(npc.ai[1] <= 0f)
{
Shoot();
}
}

private void Target()
{
player = Main.player[npc.target]; // This will get the player target.
}

private void Move(Vector2 offset)
{
speed = 13f; // Sets the max speed of the npc.
Vector2 moveTo = player.Center + offset; // Gets the point that the npc will be moving to.
Vector2 move = moveTo - npc.Center;
float magnitude = Magnitude(move);
if(magnitude > speed)
{
move *= speed / magnitude;
}
float turnResistance = 30f; // The larget the number the slower the npc will turn.
move = (npc.velocity * turnResistance + move) / (turnResistance + 1f);
magnitude = Magnitude(move);
if(magnitude > speed)
{
move *= speed / magnitude;
}
npc.velocity = move;
}

private void DespawnHandler()
{
if(!player.active || player.dead)
{
npc.TargetClosest(false);
player = Main.player[npc.target];
if(!player.active || player.dead)
{
npc.velocity = new Vector2(0f, -10f);
if(npc.timeLeft > 10)
{
npc.timeLeft = 10;
}
return;
}
}
}

private void Shoot()
{
int type = mod.ProjectileType("BlueScreenOfDeathProjectile");
Vector2 velocity = player.Center - npc.Center; // Get the distance between target and npc.
float magnitude = Magnitude(velocity);
if(magnitude > 0) {
velocity *= 5f / magnitude;
} else
{
velocity = new Vector2(0f, 5f);
}
Projectile.NewProjectile(npc.Center, velocity, type, npc.damage, 2f);
npc.ai[1] = 200f;
}

private float Magnitude(Vector2 mag)
{
return (float)Math.Sqrt(mag.X * mag.X + mag.Y * mag.Y);
}

public override void FindFrame(int frameHeight)
{
npc.frameCounter += 1;
npc.frameCounter %= 20;
int frame = (int)(npc.frameCounter / 2.0);
if (frame >= Main.npcFrameCount[npc.type]) frame = 0;
npc.frame.Y = frame * frameHeight;

RotateNPCToTarget();
}

private void RotateNPCToTarget()
{
if (player == null) return;
Vector2 direction = npc.Center - player.Center;
float rotation = (float)Math.Atan2(direction.Y, direction.X);
npc.rotation = rotation + ((float)Math.PI * 0.5f);
}

public override void NPCLoot()
{
if (Main.expertMode)
{
npc.DropBossBags();
} else
{
if (Main.rand.Next(3) == 0) // For items that you want to have a chance to drop
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Yoyomite"));
}
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Microsoft")); // For Items that you want to always drop
}


}

public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
{
scale = 1.5f;
return null;
}

}
}
 
Last edited:
I'm getting this error when trying to build:

Expected resource not found:
Items/

Closest guess: (Is there a spelling or folder placement error?)
Items/GoldFishingLine
at Terraria.ModLoader.Mod.GetTexture(String name)
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.ModItem.AutoStaticDefaults()
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)


Files are located in Documents\my games\Terraria\ModLoader\Mod Sources\MtbRepack\Items
Double checked that all of the namespaces were MtbRepack.Items, and the image files are all named correctly.

What am I missing?
 
Been getting a CTD when changing worlds happens almost like clockwork load a world play a little switch to a new world just as it would finish loading crash
heres a list of my mods
"ThoriumMod",
"WillFrostKillTerraria",
"VeinMiner",
"RecipeBrowser",
"MagicStorage",
"Fargowiltas",
"FargowiltasSouls",
"BossChecklist",
"Antisocial",
"CalamityMod",
"CalamityModMusic"
 

Attachments

  • Annotation 2019-05-11 193817.png
    Annotation 2019-05-11 193817.png
    47.1 KB · Views: 93
Back
Top Bottom