tModLoader Official tModLoader Help Thread

From all my decompiling and stuff, the item is actually drawn using the PlayerLayer, so try the player hooks and check out, if you have ilSpy or have the source, check out the DrawPlayer() method in the Player class and use the find function and search item and you'll see the whole thing.
This is helpful info, I'll see if there's something in there I can use.
 
I mean the GetTexture stuff. I have no idea how to use it on items.
You shouldn't ever need to use that. Just set autoload to true in the mod properties and Textures will be automatically bound to the item/npc/projectile

For example, if your class is named ExampleItem and the namespace is ExampleMod.Items.Weapons, autoload will look in the Mod Sources/ExampleMod/Items/Weapons/ folder for a file named ExampleItem.png.

You don't need to manually set textures.

Use this to get a barebones Mod where you can see autoload in action: javid.ddns.net/tModLoader/generator/ModSkeletonGenerator.html
 
You shouldn't ever need to use that. Just set autoload to true in the mod properties and Textures will be automatically bound to the item/npc/projectile

For example, if your class is named ExampleItem and the namespace is ExampleMod.Items.Weapons, autoload will look in the Mod Sources/ExampleMod/Items/Weapons/ folder for a file named ExampleItem.png.

You don't need to manually set textures.

Use this to get a barebones Mod where you can see autoload in action: javid.ddns.net/tModLoader/generator/ModSkeletonGenerator.html
Thank you, it works now.
 
Well, I have some kind of strange bug or something.

So, I have this code:
Code:
public override void UpdateEquip(Item item, Player player)
        {
            for (int k = 0; k < 3; k++)
            {
                if (player.armor[k].type == ItemID.ObsidianHelm)
                {
                    player.rangedDamage = player.rangedDamage + 0.06f;
                    player.rangedCrit = player.rangedCrit + 3;
                }
                if (player.armor[k].type == ItemID.ObsidianShirt)
                {
                    player.rangedDamage = player.rangedDamage + 0.07f;
                    player.rangedCrit = player.rangedCrit + 4;
                }
                if (player.armor[k].type == ItemID.ObsidianPants)
                {
                    player.rangedDamage = player.rangedDamage + 0.06f;
                    player.rangedCrit = player.rangedCrit + 2;
                    player.moveSpeed = player.moveSpeed + 0.03f;
                }
            }
        }
It raises player characterisitics if he wears obsidian armor.
BUT when I test it, all characteristics seems to be applied 3 times(!!!).
Look: Terraria_modLoader 2016-03-31 19-19-03-091.png/Terraria_modLoader 2016-03-31 19-19-13-756.png

How do I fix it?
 
Well, I have some kind of strange bug or something.

So, I have this code:
Code:
public override void UpdateEquip(Item item, Player player)
        {
            for (int k = 0; k < 3; k++)
            {
                if (player.armor[k].type == ItemID.ObsidianHelm)
                {
                    player.rangedDamage = player.rangedDamage + 0.06f;
                    player.rangedCrit = player.rangedCrit + 3;
                }
                if (player.armor[k].type == ItemID.ObsidianShirt)
                {
                    player.rangedDamage = player.rangedDamage + 0.07f;
                    player.rangedCrit = player.rangedCrit + 4;
                }
                if (player.armor[k].type == ItemID.ObsidianPants)
                {
                    player.rangedDamage = player.rangedDamage + 0.06f;
                    player.rangedCrit = player.rangedCrit + 2;
                    player.moveSpeed = player.moveSpeed + 0.03f;
                }
            }
        }
It raises player characterisitics if he wears obsidian armor.
BUT when I test it, all characteristics seems to be applied 3 times(!!!).
Look:View attachment 102628/View attachment 102629
That's because you're looping 3 times.
I assume this code is on a GlobalItem? If so, remove the for loop and just check if(item.type == blabla) no need to loop through the armor, since the function you're using is already called for each individual piece of equipment.
 
That's because you're looping 3 times.
I assume this code is on a GlobalItem? If so, remove the for loop and just check if(item.type == blabla) no need to loop through the armor, since the function you're using is already called for each individual piece of equipment.

I knew that I was doing something wrong.Thanks! :)
 
my projectile for my magic weapon wont deal damage to hostile mobs no matter what i do
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace BMod.Projectiles
{
public class BStaff0Proj : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "BStaff 0% Power Projectile";
projectile.width = 6;
projectile.height = 6;
projectile.alpha = 255;
projectile.timeLeft = 600;
projectile.penetrate = 1;
projectile.hostile = false;
projectile.magic = true;
projectile.tileCollide = true;
projectile.ignoreWater = true;
}

public override void AI()
{
if (projectile.localAI[0] == 0f)
{
PlaySound();
if (projectile.ai[0] < 0f)
{
projectile.alpha = 0;
projectile.damage = 0;
}
if (projectile.ai[0] == 44f)
{
projectile.coldDamage = true;
projectile.damage = 0;
}
if (projectile.ai[0] < 0f && Main.expertMode)
{
cooldownSlot = 1;
projectile.damage = 0;
}
projectile.localAI[0] = 1f;
}
}

public virtual void PlaySound()
{
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 20);
}

public override void OnHitPlayer(Player target, int damage, bool crit)
{
if ((Main.expertMode || Main.rand.Next(2) == 0) && projectile.ai[0] >= 0f)
{
target.AddBuff((int)projectile.ai[0], (int)projectile.ai[1], true);
}
}
}
}
 
my projectile for my magic weapon wont deal damage to hostile mobs no matter what i do
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace BMod.Projectiles
{
public class BStaff0Proj : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "BStaff 0% Power Projectile";
projectile.width = 6;
projectile.height = 6;
projectile.alpha = 255;
projectile.timeLeft = 600;
projectile.penetrate = 1;
projectile.hostile = false;
projectile.magic = true;
projectile.tileCollide = true;
projectile.ignoreWater = true;
}

public override void AI()
{
if (projectile.localAI[0] == 0f)
{
PlaySound();
if (projectile.ai[0] < 0f)
{
projectile.alpha = 0;
projectile.damage = 0;
}
if (projectile.ai[0] == 44f)
{
projectile.coldDamage = true;
projectile.damage = 0;
}
if (projectile.ai[0] < 0f && Main.expertMode)
{
cooldownSlot = 1;
projectile.damage = 0;
}
projectile.localAI[0] = 1f;
}
}

public virtual void PlaySound()
{
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 20);
}

public override void OnHitPlayer(Player target, int damage, bool crit)
{
if ((Main.expertMode || Main.rand.Next(2) == 0) && projectile.ai[0] >= 0f)
{
target.AddBuff((int)projectile.ai[0], (int)projectile.ai[1], true);
}
}
}
}

You're probably going to want to set projectile.friendly = true in SetDefaults().
 
Hi I have few questions:
1) Is there any way how to change item tooltip color?
2) Can I get currently selected item?
 
Hi I have few questions:
1) Is there any way how to change item tooltip color?
2) Can I get currently selected item?
1. Not sure, you may have to wait for UI support.
2. You can get the currently selected item by using player.selectedItem:
Code:
Item selectedItem = player.inventory[player.selectedItem];
 
Need help making a robe:
Code:
public override void SetMatch(ref int equipSlot, ref bool robes){
            EquipTexture eq = EquipLoader.GetEquipTexture(EquipType.Legs,mod.GetEquipSlot("SpectralPants"));
            equipSlot = eq.Slot;
            robes = true;
        }
Can get this to work.
 
Need help making a robe:
Code:
public override void SetMatch(ref int equipSlot, ref bool robes){
            EquipTexture eq = EquipLoader.GetEquipTexture(EquipType.Legs,mod.GetEquipSlot("SpectralPants"));
            equipSlot = eq.Slot;
            robes = true;
        }
Can get this to work.
Could you show us some context code? ;)
 
Back
Top Bottom