Standalone [1.3] tModLoader - A Modding API

You'll want to look up the difference between = and ==. One is assigning, and the other is comparing for equality. The code "head.name = "Wooden Helmet"" is actually returning the string "Wooden Helmet", not a boolean value as you assumed.
Aha, now I understand this.
As for my "Super Ironskin Potion", it failed again... This is quite heart-breaking.
You see
public class SuperIronskin : ModItem
{
public override void SetDefaults()
{
item.name = "Super Ironskin Potion";
item.width = 12;
item.height = 12;
item.value = 200;
item.maxStack = 999;
AddTooltip("This is a stronger Iron Potion.");
item.useTurn = true;
item.autoReuse = true;
item.useAnimation = 15;
item.useTime = 10;
item.useStyle = 1;
item.consumable = true;
}

public override bool ConsumeItem(Player player)
{
player.AddBuff(BuffID.Ironskin, 120);
return true;
}
Well, I do create an item named "Super Ironskin Potion" with the texture I attached. Problem is...wired. I cannot drink it actually. Really don't know what to do.

One more thing, could you send me a copy of decompiled files of vanilla game?
Maybe I don't need the entire game, but having some weapon, armor and potion examples could be really useful, for I frequently stuck in some really basic questions like "how to express 'critical damage chance'" or "how to give a bonus to defense".
It seems you know all these stuff! I simply don't realize I should use the sentence "player.meleeCrit += 1" to modify the "critical damage chance".
Have you seen to the decompiled files? Or this is just a kind of knowledge? I think it would be annoying if I'm going to ask every single usage of these, maybe you could tell me where I can refer to.:)
 
public override bool ConsumeItem(Player player)
{
player.AddBuff(BuffID.Ironskin, 120);
return true;
}
Well, I do create an item named "Super Ironskin Potion" with the texture I attached. Problem is...wired. I cannot drink it actually. Really don't know what to do.

One more thing, could you send me a copy of decompiled files of vanilla game?
Maybe I don't need the entire game, but having some weapon, armor and potion examples could be really useful, for I frequently stuck in some really basic questions like "how to express 'critical damage chance'" or "how to give a bonus to defense".
It seems you know all these stuff! I simply don't realize I should use the sentence "player.meleeCrit += 1" to modify the "critical damage chance".
Have you seen to the decompiled files? Or this is just a kind of knowledge? I think it would be annoying if I'm going to ask every single usage of these, maybe you could tell me where I can refer to.:)
I think just change ConsumeItem to UseItem.

You can decompile Terraria very easily with the tModLoader setup. https://github.com/bluemagic123/tModLoader/archive/master.zip

Distributing the decompiled source is a big no-no on the forums, I assume.

Also, are you not using Visual Studio? Adding the Terraria.exe as a reference should expose you to all the available variables even without decompiling, and autocomplete will show you available variables in a context sensitive manner.
 
Oh, I think Visual Studio is just a kind of advanced .txt editor. Never Have I thought it has such a powerful function. I'll go have a check. And is there any place you would recommend for me to learn some basis of C#? Just 0-basic type book or website.

Still, I can't find the "reference" function... I used VS to open Terraria.exe, but nothing happened except a few seconds lag.
 
Last edited:
Here`s my code once again:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Tutorial.Items
{

public class PowerPunchSword : ModItem
{
private object item;

public override void SetDefaults()
{

item.name = "Power Punch Sword";
item.width = 64;
item.height = 64;
item.damage = 999999;
item.useStyle = 15;
item.knockBack = 75;
item.useTime = 30;
item.useAnimation = 20;
item.melee = true;
item.maxStack = 1;
item.toolTip = "With great power comes great responsiblity and all that junk";
item.value = Item.buyPrice(0, 4, 58, 0);
item.autoReuse = true;
item.useTurn = true;
}

public override void AddRecipes()
{

ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(18);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}


}
}
 
Here`s my code once again:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Tutorial.Items
{

public class PowerPunchSword : ModItem
{
private object item;

public override void SetDefaults()
{

item.name = "Power Punch Sword";
item.width = 64;
item.height = 64;
item.damage = 999999;
item.useStyle = 15;
item.knockBack = 75;
item.useTime = 30;
item.useAnimation = 20;
item.melee = true;
item.maxStack = 1;
item.toolTip = "With great power comes great responsiblity and all that junk";
item.value = Item.buyPrice(0, 4, 58, 0);
item.autoReuse = true;
item.useTurn = true;
}

public override void AddRecipes()
{

ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(18);
recipe.SetResult(this, 1);
recipe.AddRecipe();
}


}
}
Your error says it all. You're creating 'private object item;', but there's already a variable called 'item' present in ModItem (which you inherit from). Rename your variable, so that it doesn't override the already existing variables. If you WANT to override it (for whatever reason) you should do 'private new object item;'.
 
Your error says it all. You're creating 'private object item;', but there's already a variable called 'item' present in ModItem (which you inherit from). Rename your variable, so that it doesn't override the already existing variables. If you WANT to override it (for whatever reason) you should do 'private new object item;'.
:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\Beta Tester`s Items\PowerPunchSword.cs(9,18) : error CS0146: Circular base class dependency involving 'Tutorial.Items.PowerPunchSword' and 'Tutorial.Items.PowerPunchSword'. I swear it`s one line of code that I`m doing wrong...
 
:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\Beta Tester`s Items\PowerPunchSword.cs(9,18) : error CS0146: Circular base class dependency involving 'Tutorial.Items.PowerPunchSword' and 'Tutorial.Items.PowerPunchSword'. I swear it`s one line of code that I`m doing wrong...
"Private object item" Why is that line even there? Delete it.
 
"Private object item" Why is that line even there? Delete it.
Done, now this happened.
c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\Beta Tester`s Items\PowerPunchSword.cs(9,18) : error CS0146: Circular base class dependency involving 'Tutorial.Items.PowerPunchSword' and 'Tutorial.Items.PowerPunchSword'
 
Done, now this happened.
c:\Users\Owner\Documents\My Games\Terraria\ModLoader\Mod Sources\Beta Tester`s Items\PowerPunchSword.cs(9,18) : error CS0146: Circular base class dependency involving 'Tutorial.Items.PowerPunchSword' and 'Tutorial.Items.PowerPunchSword'
Ah, I see, this was after. The error seems weird, do you have other .cs files? Also, try using code blocks here on the forum if you are posting a lot of code, it helps the readability.
 
Nope, only one.
K, I just tried your code and it seems fine. The only other thing I can think of is possible the apostrophe in the folder name is causing problems, or somewhere in Mod Sources some other code has the same namespace and is messing things up? (You have a .cs file that extends Mod, don't you?)
 
Hey guys, I have this
Code:
public override void UpdateAccessory(Player player)
    {
        if (Main.rand.Next(120) == 0)
        {
            NPC target = Main.npc[];
            Projectile.NewProjectile(player.position.X, player.position.Y, player.velocity.X, player.velocity.Y, 321, 50, 4, player.whoAmI, target.whoAmI, 0f);
        }
    }

What I should put into the []? I tried with 0 but the projectile (the pumpkin) follows a town NPC
 
Hey guys, I have this
Code:
public override void UpdateAccessory(Player player)
    {
        if (Main.rand.Next(120) == 0)
        {
            NPC target = Main.npc[];
            Projectile.NewProjectile(player.position.X, player.position.Y, player.velocity.X, player.velocity.Y, 321, 50, 4, player.whoAmI, target.whoAmI, 0f);
        }
    }

What I should put into the []? I tried with 0 but the projectile (the pumpkin) follows a town NPC
You know what Main.npc is? Main.npc is an array, which means it's a variable which holds multiple variables (if you can understand that).
It's basically a 'list' that holds multiple NPCs (200 to be exact, since it's set to 200 by Terraria internally).
Since Town NPCs are spawned when the player himself is spawned, it's comprehendable that the first NPC in that list is a Town NPC.
What you'll want to do is loop through the Main.npc to get a valid NPC like follows:
Code:
for(int i = 0; i < Main.npc.Length; ++i)
{
    
}
Then you can use 'i' to get the data from one of the NPCs in the Main.npc array (Main.npc). You'll still have to check if the npc is active and if it can be followed at all, but that's not too difficult, so you might be able to solve that yourself. :)
 
You know what Main.npc is? Main.npc is an array, which means it's a variable which holds multiple variables (if you can understand that).
It's basically a 'list' that holds multiple NPCs (200 to be exact, since it's set to 200 by Terraria internally).
Since Town NPCs are spawned when the player himself is spawned, it's comprehendable that the first NPC in that list is a Town NPC.
What you'll want to do is loop through the Main.npc to get a valid NPC like follows:
Code:
for(int i = 0; i < Main.npc.Length; ++i)
{
   
}
Then you can use 'i' to get the data from one of the NPCs in the Main.npc array (Main.npc). You'll still have to check if the npc is active and if it can be followed at all, but that's not too difficult, so you might be able to solve that yourself. :)
Oh, I dont know much about arrays :p
I will try :D
 
How do I make it so that an arrow that gets shot from my weapon never drops as an item? Here's my current code:
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)
        {
            for(int i = 0; i < Main.rand.Next(2, 5); i++)
            {
                Projectile.NewProjectile(position.X + (Main.rand.NextFloat() - 0.5f) * 0.5f, position.Y + (Main.rand.NextFloat() - 0.5f) * 0.5f,
                                         speedX + (Main.rand.NextFloat() - 0.5f) * 3, speedY + (Main.rand.NextFloat() - 0.5f) * 3, type, damage, knockBack, item.owner);
            }
            return false;
        }
The item consumes 1 arrow and shoots 3, but each one of them has a chance to be 50% recovered so it leads to dupes. I'm assuming you have to add something to the ai and ai2 parametres but I don't know what.
 
How do I make it so that an arrow that gets shot from my weapon never drops as an item? Here's my current code:
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)
        {
            for(int i = 0; i < Main.rand.Next(2, 5); i++)
            {
                Projectile.NewProjectile(position.X + (Main.rand.NextFloat() - 0.5f) * 0.5f, position.Y + (Main.rand.NextFloat() - 0.5f) * 0.5f,
                                         speedX + (Main.rand.NextFloat() - 0.5f) * 3, speedY + (Main.rand.NextFloat() - 0.5f) * 3, type, damage, knockBack, item.owner);
            }
            return false;
        }
The item consumes 1 arrow and shoots 3, but each one of them has a chance to be 50% recovered so it leads to dupes. I'm assuming you have to add something to the ai and ai2 parametres but I don't know what.
You'll have to cache the index of your projectile in the Main.projectile array like this:
Code:
int index = Projectile.NewProjectile(etc,etc);
Where you just spawn your projectile like you normally would (no fiddling with ai here ;)) and then you'll want to put the following right behind that:
Code:
Main.projectile[index].noDropItem = true;
 
You'll have to cache the index of your projectile in the Main.projectile array like this:
Code:
int index = Projectile.NewProjectile(etc,etc);
Where you just spawn your projectile like you normally would (no fiddling with ai here ;)) and then you'll want to put the following right behind that:
Code:
Main.projectile[index].noDropItem = true;
Oh. That's much simpler than I thought it would be! Thank you!:)
 
1. install mono 2. put the folder that you downloaded onto you desktop 3. to make it easier, remove the spaces between the words in the folder name 4. open terminal 5. type 'cd desktop' 6. type 'cd tModLoaderMacv0.6' 7. type 'mono Installer.exe' and the system will take it from there. keep in mind that it may crash a lot, because apple computers are {insert pretty much any swear word here} when it comes to all things games. if this happens, repeat step 7 until it works. also, my mac wont let me build mods, so i work with @EliANs on a mod so that he can build it. i just play the mods. :p hope this helps

I can't found the folder that I downloaded, where is it?
 
Back
Top Bottom