Standalone [1.3] tModLoader - A Modding API

How might I make an enemy drop my custom item? I don't know what its item ID is, and I don't know where to find it.
Here's the code for the item:
Code:
using System;

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

namespace LihzarhdExpansion.Items
{
    public class Meatloaf : ModItem
    {
        public override void SetDefaults()
        {
            item.consumable = false;
            item.rare = 9;
            item.damage = 5000;
            item.useStyle = 1;
            item.useTurn = false;
            item.useAnimation = 17;
            item.useTime = 17;
            item.healLife = 2000;
            item.useSound = 2;
            item.name = "Mushroomy Meatloaf";
            item.width = 20;
            item.height = 20;
            item.value = 10000;
            item.toolTip = "Eldrazi's favorite!";

            item.maxStack = 999;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Mushroom);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
 
How might I make an enemy drop my custom item? I don't know what its item ID is, and I don't know where to find it.
Here's the code for the item:
Code:
using System;

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

namespace LihzarhdExpansion.Items
{
    public class Meatloaf : ModItem
    {
        public override void SetDefaults()
        {
            item.consumable = false;
            item.rare = 9;
            item.damage = 5000;
            item.useStyle = 1;
            item.useTurn = false;
            item.useAnimation = 17;
            item.useTime = 17;
            item.healLife = 2000;
            item.useSound = 2;
            item.name = "Mushroomy Meatloaf";
            item.width = 20;
            item.height = 20;
            item.value = 10000;
            item.toolTip = "Eldrazi's favorite!";

            item.maxStack = 999;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.Mushroom);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}

Try the following code:

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

namespace LihzarhdExpansion.NPCs
{
    public class CustomLoot : GlobalNPC
    {
        public override void NPCLoot(NPC npc)
        {
            if((Main.rand.Next(50) == 50) && (npc.type == NPCID.Zombie))
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("Meatloaf"));
        }
    }
}

All zombies will have a 1 in 50 chance to drop meatloaf.
 
Umm... I'm no expert in tModLoader, nor have any experience in tModLoader, but you set up and used the hook wrong. If you wanted it to make it shoot, you would need to do it like this...

Code:
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, position.Y, speedX, speedY, mod.ProjectileType("DarkMatterArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type DarkMatterArrow using the original stats
    return false; //Makes sure to not fire the original projectile
}

When I put that into the code for the bow I got ths error:
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\Items\Weapons\DarkMatterBow.cs(37,16) : error CS0117: 'Terraria.Projectile' does not contain a definition for 'newProjectile'

Here is the bow's code I it helps
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.Items.Weapons
{
    public class DarkMatterBow : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dark Matter Bow";
            item.damage = 65;
            item.ranged = true;
            item.width = 16;
            item.height = 32;
            item.toolTip = "You thought Phantasm was fast? Well this is faster!";
            item.toolTip2 = "All Arrows turn into Dark Matter Arrows.";
            item.useTime = 6;
            item.useAnimation = 6;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 2;
            item.value = 325060;
            item.rare = 7;
            item.useSound = 11;
            item.autoReuse = true;
            item.shootSpeed = 13f;
            item.shoot = mod.ProjectileType ("DarkMatterArrow");
            item.useAmmo = 1;
           
        }
       
        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, position.Y, speedX, speedY, mod.ProjectileType("DarkMatterArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type DarkMatterArrow using the original stats
    return false; //Makes sure to not fire the original projectile
}

    }
}
 
When I put that into the code for the bow I got ths error:
c:\Users\Julian Romero\Documents\My Games\Terraria\ModLoader\Mod Sources\EpicnessMod\Items\Weapons\DarkMatterBow.cs(37,16) : error CS0117: 'Terraria.Projectile' does not contain a definition for 'newProjectile'

Here is the bow's code I it helps
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace EpicnessMod.Items.Weapons
{
    public class DarkMatterBow : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Dark Matter Bow";
            item.damage = 65;
            item.ranged = true;
            item.width = 16;
            item.height = 32;
            item.toolTip = "You thought Phantasm was fast? Well this is faster!";
            item.toolTip2 = "All Arrows turn into Dark Matter Arrows.";
            item.useTime = 6;
            item.useAnimation = 6;
            item.useStyle = 5;
            item.noMelee = true;
            item.knockBack = 2;
            item.value = 325060;
            item.rare = 7;
            item.useSound = 11;
            item.autoReuse = true;
            item.shootSpeed = 13f;
            item.shoot = mod.ProjectileType ("DarkMatterArrow");
            item.useAmmo = 1;
          
        }
      
        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, position.Y, speedX, speedY, mod.ProjectileType("DarkMatterArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type DarkMatterArrow using the original stats
    return false; //Makes sure to not fire the original projectile
}

    }
}
My bad, the "n" in "new" is supposed to be capitalized. So it should be...

Code:
Projectile.NewProjectile(position.X, position.Y, speedX, speedY, mod.ProjectileType("DarkMatterArrow"), damage, knockBack, player.whoAmI, 0f, 0f);

I got used to just capitalizing words after the first one on my methods.
 
How do I get a npc to drop a range of items?

Like 20 - 50 Dark Matter Bars

Here is the bosses loot code:
Code:
public override void NPCLoot()
        {
           
       
         Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("TrippleStarCane"), 1);
        
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DarkMatterBar"), 20 - 50);   
           
           
            if (Main.expertMode)
            {
                npc.DropBossBags();
            }
        }
 
I can't use the tModLoader on Mac. I selected Terraria, pressed Show Package Contents, then opened MacOS and dragged the Terraria.exe onto the Installer Window which I opened with Wine. It doesn't seem to work. Someone help me please
 
I want to make my item so i can use it with both types of iron bars(lead and iron) and with both types of mythril anvil. How should i do that?
tModLoader has a handful of crafting groupes built in. The one you want is recipe.anyIronBar;. There is also .anyFragment, .anyPressurePlate, .anySand and .anyWood. If you want more, you can create your own craft group inyour main mod file as follows.
Code:
public override void AddCraftGroups()
{
    //Add the silver ranked group
    AddCraftGroup("rankSilver", Lang.misc[37] + " Silver", ItemID.SilverBar, ItemID.TungstenBar);
            //Add the Gold ranked group
    AddCraftGroup("rankGold", Lang.misc[37] + " Gold", ItemID.GoldBar, ItemID.PlatinumBar);
}
And then in your recipe you would use 'recipe.AddCraftGroup(null, "rankSilver", 2);' or 'recipe.AddCraftGroup(null, "rankGold", 3);' to add one of the craft groups.

And I believe that just specifying the Mythril anvil will work with both types.
 
Em... it has been a loog time that I don't get a chance to sit down and work with Terraria's modding, since there're so many works to do. But today I log in randomly, and 0.7 should have come out! This is so thrilling!
Though still I may not have time to take a close look what new is in 0.7, well, at least till the next week. So I just got to ask a little question: will updating 0.7 disturb the mods I'd made in 0.6? And now there is still 0.6 in my computer. If I'm ready to update to 0.7, am I supposed to run the 0.6 installer to remove 0.6 files and then install 0.7 like what I did in 0.6? Or there are changes in installer in 0.7? I don't know, leave a reply if you got time!
 
How to put a custom tile only a stone?
Find all the tileIDs you want, then do something like this to your TileObjectData.newTile before calling addTile.

TileObjectData.newTile.AnchorValidTiles = new int[]
{
2, //TileID.Grass
109, // TileId.HallowedGrass
mod.TileType("ExampleBlock")
};
[DOUBLEPOST=1452947394,1452947349][/DOUBLEPOST]
I still can't use it... God Damit... It keeps saying about some weard Steam Social crap... Help?!
Did you read the file called README.txt? You have the steam version?
[DOUBLEPOST=1452947604][/DOUBLEPOST]
Em... it has been a loog time that I don't get a chance to sit down and work with Terraria's modding, since there're so many works to do. But today I log in randomly, and 0.7 should have come out! This is so thrilling!
Though still I may not have time to take a close look what new is in 0.7, well, at least till the next week. So I just got to ask a little question: will updating 0.7 disturb the mods I'd made in 0.6? And now there is still 0.6 in my computer. If I'm ready to update to 0.7, am I supposed to run the 0.6 installer to remove 0.6 files and then install 0.7 like what I did in 0.6? Or there are changes in installer in 0.7? I don't know, leave a reply if you got time!
You should still have the source, right? When you install 0.7, your 0.6 mods won't load, but you just need to run the build command again. There are a couple things that changed in 0.7, but you can fix the code yourself or post the error and we can help.

To install 0.7, just follow the instructions in the README.txt file in the download zip. There is no need to "uninstall" 0.6.
[DOUBLEPOST=1452947945][/DOUBLEPOST]
I can't use the tModLoader on Mac. I selected Terraria, pressed Show Package Contents, then opened MacOS and dragged the Terraria.exe onto the Installer Window which I opened with Wine. It doesn't seem to work. Someone help me please
Wine? -- Can't you run Terraria natively on Mac now? Why use wine? I'm not even sure which version you should download. Which one did you download?
Installer Window? -- What is this? Just drag and drop and confirm replace.
 
Find all the tileIDs you want, then do something like this to your TileObjectData.newTile before calling addTile.

TileObjectData.newTile.AnchorValidTiles = new int[]
{
2, //TileID.Grass
109, // TileId.HallowedGrass
mod.TileType("ExampleBlock")
};
[DOUBLEPOST=1452947394,1452947349][/DOUBLEPOST]
Did you read the file called README.txt? You have the steam version?
[DOUBLEPOST=1452947604][/DOUBLEPOST]
You should still have the source, right? When you install 0.7, your 0.6 mods won't load, but you just need to run the build command again. There are a couple things that changed in 0.7, but you can fix the code yourself or post the error and we can help.

To install 0.7, just follow the instructions in the README.txt file in the download zip. There is no need to "uninstall" 0.6.
[DOUBLEPOST=1452947945][/DOUBLEPOST]
Wine? -- Can't you run Terraria natively on Mac now? Why use wine? I'm not even sure which version you should download. Which one did you download?
Installer Window? -- What is this? Just drag and drop and confirm replace.
Thank you! It's work
 
Find all the tileIDs you want, then do something like this to your TileObjectData.newTile before calling addTile.

TileObjectData.newTile.AnchorValidTiles = new int[]
{
2, //TileID.Grass
109, // TileId.HallowedGrass
mod.TileType("ExampleBlock")
};
[DOUBLEPOST=1452947394,1452947349][/DOUBLEPOST]
Did you read the file called README.txt? You have the steam version?
[DOUBLEPOST=1452947604][/DOUBLEPOST]
You should still have the source, right? When you install 0.7, your 0.6 mods won't load, but you just need to run the build command again. There are a couple things that changed in 0.7, but you can fix the code yourself or post the error and we can help.

To install 0.7, just follow the instructions in the README.txt file in the download zip. There is no need to "uninstall" 0.6.
[DOUBLEPOST=1452947945][/DOUBLEPOST]
Wine? -- Can't you run Terraria natively on Mac now? Why use wine? I'm not even sure which version you should download. Which one did you download?
Installer Window? -- What is this? Just drag and drop and confirm replace.
I used Wine to open the Mac version of tModLoader, because it was an exe. When I drag and drop the file it doesn't seem to do anything, regardless of whether I drag on Terraria.app or the package content Terraria.exe. I'm completely stuck and confused, because I followed all the instructions in the README.txt, but it's not working. Thanks
[DOUBLEPOST=1452951847][/DOUBLEPOST]
I used Wine to open the Mac version of tModLoader, because it was an exe. When I drag and drop the file it doesn't seem to do anything, regardless of whether I drag on Terraria.app or the package content Terraria.exe. I'm completely stuck and confused, because I followed all the instructions in the README.txt, but it's not working. Thanks
Never mind, I think version 0.7 fixed it. Thanks for all the help anyway!
 
Find all the tileIDs you want, then do something like this to your TileObjectData.newTile before calling addTile.

TileObjectData.newTile.AnchorValidTiles = new int[]
{
2, //TileID.Grass
109, // TileId.HallowedGrass
mod.TileType("ExampleBlock")
};
[DOUBLEPOST=1452947394,1452947349][/DOUBLEPOST]
Did you read the file called README.txt? You have the steam version?
[DOUBLEPOST=1452947604][/DOUBLEPOST]
You should still have the source, right? When you install 0.7, your 0.6 mods won't load, but you just need to run the build command again. There are a couple things that changed in 0.7, but you can fix the code yourself or post the error and we can help.

To install 0.7, just follow the instructions in the README.txt file in the download zip. There is no need to "uninstall" 0.6.
[DOUBLEPOST=1452947945][/DOUBLEPOST]
Wine? -- Can't you run Terraria natively on Mac now? Why use wine? I'm not even sure which version you should download. Which one did you download?
Installer Window? -- What is this? Just drag and drop and confirm replace.


Noo. I didn't read the readme... Nooo, I'm that stupid... I did read it, but I don't have the steam version, I just goddamn remembered!
 
I used Wine to open the Mac version of tModLoader, because it was an exe. When I drag and drop the file it doesn't seem to do anything, regardless of whether I drag on Terraria.app or the package content Terraria.exe. I'm completely stuck and confused, because I followed all the instructions in the README.txt, but it's not working. Thanks
[DOUBLEPOST=1452951847][/DOUBLEPOST]
Never mind, I think version 0.7 fixed it. Thanks for all the help anyway!
Ok....so you mean you figured it out then, right?

Noo. I didn't read the readme... Nooo, I'm that stupid... I did read it, but I don't have the steam version, I just goddamn remembered!
Yeah, we still haven't gotten around to a non-steam version yet, sorry
 
Hold on, just a question, what should the Mac GUI look like? Mine doesn't look right, can someone please clarify? I copied the files and pasted in the Terraria MacOS Package Contents file, followed README instructions
 

Attachments

  • Screen Shot 2016-01-16 at 9.51.34 pm.png
    Screen Shot 2016-01-16 at 9.51.34 pm.png
    1 MB · Views: 184
Hold on, just a question, what should the Mac GUI look like? Mine doesn't look right, can someone please clarify? I copied the files and pasted in the Terraria MacOS Package Contents file, followed README instructions
No, I believe that running tModLoader requires a Mono environment, since tModLoader is packaged as a ".exe" rather than an ".app"
 
Back
Top Bottom