tModLoader Official tModLoader Help Thread

Hi, I'm making a small mod and it has all damage/crit up items(like destoyer emblem). It works great, but custom damage type weapons(i.e. thorium healter/bard weapons) don't get affected. I guess I have to modify thorium's modplayer directly, but I have no idea where to start.
 
Hello, please I need help, i'm trying to make Everscream drop a custom item that I have made.

i'm using this code for the drop

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

namespace MoreRecipe.NPCs
{
public class ModGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{

if (npc.type == NPCID.Everscream)
{
if (Main.rand.Next(2) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SnowPowerCell"), 1);
}

}
}
}
}

and this code for the item

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

namespace MoreRecipe.Items
{
public class SnowPowerCell : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Snow Power Cell");
Tooltip.SetDefault("Used to make frost moon boss item");
}
public override void SetDefaults()
{
item.width = 20;
item.height = 20;
item.maxStack = 999;
item.value = 25000;
item.rare = 7;
}
}
}

where is the error ?


Thanks everyone for the help :joy:
 
Hello, please I need help, i'm trying to make Everscream drop a custom item that I have made.

i'm using this code for the drop

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

namespace MoreRecipe.NPCs
{
public class ModGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{

if (npc.type == NPCID.Everscream)
{
if (Main.rand.Next(2) == 0)
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SnowPowerCell"), 1);
}

}
}
}
}

and this code for the item

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

namespace MoreRecipe.Items
{
public class SnowPowerCell : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Snow Power Cell");
Tooltip.SetDefault("Used to make frost moon boss item");
}
public override void SetDefaults()
{
item.width = 20;
item.height = 20;
item.maxStack = 999;
item.value = 25000;
item.rare = 7;
}
}
}

where is the error ?


Thanks everyone for the help :joy:


no idea. seems you are doing the right thing.
try this:

int NPCType = npc.type;//this just save some code
Player player = Main.player[0];//this is how you refer to the character you play if there is no Player parameter in the function

//the drop num for the bosses. differ from hardness.
if (NPCType == NPCID.KingSlime || NPCType == NPCID.EyeofCthulhu)
{
player.QuickSpawnItem(mod.ItemType("UniversalCraftingMaterial"), 3 + Main.rand.Next(0, 3));//item direct appear in your inventory
}

just replace the "UniversalCraftingMaterial" with the item id you want to drop.
 
no idea. seems you are doing the right thing.
try this:

int NPCType = npc.type;//this just save some code
Player player = Main.player[0];//this is how you refer to the character you play if there is no Player parameter in the function

//the drop num for the bosses. differ from hardness.
if (NPCType == NPCID.KingSlime || NPCType == NPCID.EyeofCthulhu)
{
player.QuickSpawnItem(mod.ItemType("UniversalCraftingMaterial"), 3 + Main.rand.Next(0, 3));//item direct appear in your inventory
}

just replace the "UniversalCraftingMaterial" with the item id you want to drop.


Thanks a lot for the help, today I tryed again to use my code... and I'm stupid because I wrote the code in another mod source...
 
Hello, I am new to modding in terraria I have made weapons before but I cannot figure out how to actually make the creature spawn in hard mode corruption but I have made it so it can spawn at night to test it.

here is the code:

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

namespace FurtherWorlds.Items.NPCs
{

public class CorruptPixie : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Corrupt Pixie");
Main.npcFrameCount[npc.type] = Main.npcFrameCount[NPCID.Pixie];
}

public override void SetDefaults()
{
npc.width = 115;
npc.height = 80;
npc.damage = 12;
npc.defense = 10;
npc.lifeMax = 350;
npc.HitSound = SoundID.NPCHit8;
npc.DeathSound = SoundID.NPCDeath12;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 22;
aiType = NPCID.Pixie;
animationType = NPCID.Pixie;
}

public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
return SpawnCondition.OverworldNightMonster.Chance * 0.5f;
}
}
}
 
I have also run into this problem:

c:\Users\Big D\Documents\My Games\Terraria\ModLoader\Mod Sources\FurtherWorlds\Items\Weapons\Pole.cs(32,7) : error CS0101: The namespace '<global namespace>' already contains a definition for 'MyGlobalNPC'

Here is the code for dropping the item:

class MyGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if(npc.type == NPCID.TwiggyZombie)
{
if (Main.rand.Next(50) == 0)
Item.NewItem(npc.getRect(), mod.ItemType("Pole"), 1);
}
// Addtional if statements here for adding drops to other vanilla npc.
}
}

It worked before but now I am trying to update my mod and now it is saying the error message listed above help would be much appreciated
 
I have another question, if I want to add an item from another mod as ingredient for my recipe, what I have to write ?
should be like this:
Player player = Main.player[0];//without this line the game won't know what is "player" in the next line
player.QuickSpawnItem(mod.ItemType("UniversalCraftingMaterial"), 3 + Main.rand.Next(0, 3));// this will drop 3-5 items in player's inventory
just change the "UniversalCraftingMaterial" to the item id. item id is the class name.

I have also run into this problem:

c:\Users\Big D\Documents\My Games\Terraria\ModLoader\Mod Sources\FurtherWorlds\Items\Weapons\Pole.cs(32,7) : error CS0101: The namespace '<global namespace>' already contains a definition for 'MyGlobalNPC'

Here is the code for dropping the item:

class MyGlobalNPC : GlobalNPC
{
public override void NPCLoot(NPC npc)
{
if(npc.type == NPCID.TwiggyZombie)
{
if (Main.rand.Next(50) == 0)
Item.NewItem(npc.getRect(), mod.ItemType("Pole"), 1);
}
// Addtional if statements here for adding drops to other vanilla npc.
}
}

It worked before but now I am trying to update my mod and now it is saying the error message listed above help would be much appreciated

see "c:\Users\Big D\Documents\My Games\Terraria\ModLoader\Mod Sources\FurtherWorlds\Items\Weapons\Pole.cs(32,7)" ?
the "c:\ ... Pole.cs" is the location of the document that contains an error(sorry for my english here, hope you can understand it)
and the (32,7) is the exact location of the error in the document. that means line 32, column 7.
not sure about columns and rows? just use notepad++ or MVS you will be good to go.
and by the way, I guess you just ctrl+c+v another document and didn't change the namespace cuz that's what the error log saying. just in case you don't understand what's that saying. and of course, you can leave any comments here if you are still not sure of something. people are reallly kind here and sometimes you get reply from experts.
 
should be like this:
Player player = Main.player[0];//without this line the game won't know what is "player" in the next line
player.QuickSpawnItem(mod.ItemType("UniversalCraftingMaterial"), 3 + Main.rand.Next(0, 3));// this will drop 3-5 items in player's inventory
just change the "UniversalCraftingMaterial" to the item id. item id is the class name.


Thanks for reply, but I have asked how to add an item from an external mod as an ingredient in my mod (sorry for my bad English maybe I can't express myself :( )
 
Disable kRPG.
that won't be a drop then, my bad. if "item A from mod A is REQUIRED to make item B from mod B", then here is the answer:


public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(74,9999);//this is vanilla item, just change the 74 to the id you want. id is easy to find with terraria official wiki.
recipe.AddIngredient(null, "GodEmblem"); // this is how you add item as an ingredient from the same mod
recipe.AddIngredient(GetItem("UniversalCraftingMaterial"), 10);// this is how you add MULTIPLE item as an ingredient from the same mod
recipe.AddIngredient(ModLoader.GetMod("CalamityMod").ItemType("YharimsCrystal"));//this is how you can add the "Yharim's Crystal" from "Calamity" as an ingredient
recipe.AddIngredient(ModLoader.GetMod("Fargowiltas").ItemType("UniverseSoul"));//this is how you can add the "Soul of Universe" from "Fargowiltas" as an ingredient
recipe.AddTile(412);//this is the required crafting station.412 is ancient manipulator. more info is on the official wiki
recipe.SetResult(this);//so obviously this method is in that class or the "this" keyword won't work
recipe.AddRecipe();
}

last but not least, just a little hint: you can get the mod id in the mods folder which can be easily found by click 2 buttons in game menu.(Mods-open mods folder) some mod name and mod id is different. the name is a piece of :red:, but the id MATTERS.

also, just in case you need, i will show you the mod I wrote. nothing else, just hell lot of recipes depends on an item I created called "Universal Crafting Material", which can be dropped from every mob in the game.
 

Attachments

  • RecipeChange.cs
    52 KB · Views: 177
that won't be a drop then, my bad. if "item A from mod A is REQUIRED to make item B from mod B", then here is the answer:


public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(74,9999);//this is vanilla item, just change the 74 to the id you want. id is easy to find with terraria official wiki.
recipe.AddIngredient(null, "GodEmblem"); // this is how you add item as an ingredient from the same mod
recipe.AddIngredient(GetItem("UniversalCraftingMaterial"), 10);// this is how you add MULTIPLE item as an ingredient from the same mod
recipe.AddIngredient(ModLoader.GetMod("CalamityMod").ItemType("YharimsCrystal"));//this is how you can add the "Yharim's Crystal" from "Calamity" as an ingredient
recipe.AddIngredient(ModLoader.GetMod("Fargowiltas").ItemType("UniverseSoul"));//this is how you can add the "Soul of Universe" from "Fargowiltas" as an ingredient
recipe.AddTile(412);//this is the required crafting station.412 is ancient manipulator. more info is on the official wiki
recipe.SetResult(this);//so obviously this method is in that class or the "this" keyword won't work
recipe.AddRecipe();
}

last but not least, just a little hint: you can get the mod id in the mods folder which can be easily found by click 2 buttons in game menu.(Mods-open mods folder) some mod name and mod id is different. the name is a piece of :red:, but the id MATTERS.

also, just in case you need, i will show you the mod I wrote. nothing else, just hell lot of recipes depends on an item I created called "Universal Crafting Material", which can be dropped from every mob in the game.

Ok, thanks for help, now it's much clearer to me.
and sorry for misunderstandings.
 
Hello!) Can anyone help with making of glowmask for item, please? (Basic-glowmask-guide on github helps only for dropped item, not what I asking for.) This item I asking about - is assault rifle (useStyle 5). Sry for my english by the way, if something wrong.:naughty:
This code helps for dropped item only:

public override void PostDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, float rotation, float scale, int whoAmI) //for dropped item!
{
Texture2D texture = mod.GetTexture("Items/AR_Glowmask");
spriteBatch.Draw
(
texture,
new Vector2
(
item.position.X - Main.screenPosition.X + item.width * 0.5f,
item.position.Y - Main.screenPosition.Y + item.height - texture.Height * 0.5f + 2f
),
new Rectangle(0, 0, texture.Width, texture.Height),
Color.Red,
rotation,
texture.Size() * 0.5f,
scale,
SpriteEffects.None,
0f
);
}
 
Last edited:
Is there any way to modify the code for demon altars? I would like to be able to potentially spawn different ores on demon altar smashing, or have the demon altars not spawn corruption/crimson/hallow 66% of the time.
 
Hi. I'm back after a long time away. And new to the modded community. So please excuse me if this question has been asked already. 225 pages on this post and I wasn't able to find an answer. I'm probably not using the right keywords or something. I know I should mention I'm running a Steam installation of the game.

So I've set up a Terraria server over on my dedicated server host. But I can't connect to it because no matter what I do, I can't get my copy of Terraria to run. From what I've gathered online all you need to do is copy the latest "tmod" files into your game folder, let it overwrite what it needs to. And it should be good from there. But when I go to launch the game I get hit with an error.

https://i.imgur.com/UwCcYv0.png

I know it can be done. I just can't seem to figure it out. I love this game. But I've gotten tired of Vanilla and want to move on to something new. Any help would be greatly appreciated.
 
Last edited:
Back
Top Bottom