tModLoader Official tModLoader Help Thread

can some one help me with use a post draw method for a buff that work like medusa buff
http://forums.terraria.org/index.php?threads/1-3-tmodloader-a-modding-api.23726/page-582

This guys have same problems and i have answer.

im back here with questions for two things
1. can I make it, that a weapon makes more damage on the third succsesive hit?
2. can I make it, that a weapon hurts the player whenever you hit an enemy?

1)
This is simple, you create a variable private int value=0;
Then, maybe:

Code:
        public override bool UseItem(Player player)
        {
            value++;
            if(value==1)
            item.damage*=2
            if(value==2)
            item.damage*=2;
            if(value==3){
             value=0;item.damage/=4;
            }
           //Or value++; here.
            return base.UseItem(player);
        }
This thing probably do not work correctly , sorry< (it work, but, probably not correctly)
This thing is better, but you need hit the ennemi:
private int value = 0;
public override void ModifyHitNPC(Player player, NPC target, ref int damage, ref float knockBack, ref bool crit)
{


if (value == 1) damage= (int)(damage*1.2f);
if (value == 2) damage = (int)(damage * 1.6f);
if (value == 3) value = 0;
value++;

base.ModifyHitNPC(player, target, ref damage, ref knockBack, ref crit);
}


2) More simple: You use this method:
Code:
        public override void OnHitNPC(Player player, NPC target, int damage, float knockBack, bool crit)
        {
               int spike = (int)Math.Floor((double)(damage / 100));
                 player.Hurt(spike, target.direction);
            base.OnHitNPC(player, target, damage, knockBack, crit);
        }
 
Last edited:
sorry for being dumb but i dont have a clue where to put them. when I tried it by myself to put them in, the second even crashed the game ^^'

Edit: I only wanted to do it so i have to hit the enemy to lose hp
 
Last edited:
You have put that in your item weapon, no? This is a crash of terraria or you have a log?

You have maybe forgot a thing here:
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
 
Hello again!

I'm trying to make an armor piece that inflicts shadowflame on enemy NPC hits (similar to the Magma Stone).

Would I do something like this?

Code:
public override void UpdateEquip(Player player)
 {
 player.moveSpeed += 0.15f;
 if (Main.rand.Next(4) == 0)
 {
 Main.npc[i].AddBuff(153, 360, false);
 }
 else if (Main.rand.Next(2) == 0)
 {
 Main.npc[i].AddBuff(153, 240, false);
 }
 else
 {
 Main.npc[i].AddBuff(153, 120, false);
 }
 Item item = player.inventory[player.selectedItem];
 if (item.melee && !item.noMelee && !item.noUseGraphic && Main.rand.Next(3) != 0)
 {
 int num280 = Dust.NewDust(new Vector2((float)r2.X, (float)r2.Y), r2.Width, r2.Height, 27, player.velocity.X * 0.2f + (float)(player.direction * 3), player.velocity.Y * 0.2f, 100, default(Color), 2.5f);
 Main.dust[num280].noGravity = true;
 Dust expr_D7B2_cp_0 = Main.dust[num280];
 expr_D7B2_cp_0.velocity.X = expr_D7B2_cp_0.velocity.X * 2f;
 Dust expr_D7D2_cp_0 = Main.dust[num280];
 expr_D7D2_cp_0.velocity.Y = expr_D7D2_cp_0.velocity.Y * 2f;
 }
 }
 
Would Main.rand.Next(0)==0) make a 100% chance not to consume ammo?
*Edit Is there a way for the setbonus to be Not Consume ITEMS instead of Ammo?
 
Last edited:
Hello Guys I have a Problem and I could really need your Help.

My Problem is following:
I Cloned the Vampire Knives with "item.CloneDefaults(ItemID.VampireKnives);" But the cloned item only "Throws" 1 Projectile.
What should I do? I can Post the file if Needed.
 
Hello Guys I have a Problem and I could really need your Help.

My Problem is following:
I Cloned the Vampire Knives with "item.CloneDefaults(ItemID.VampireKnives);" But the cloned item only "Throws" 1 Projectile.
What should I do? I can Post the file if Needed.
Cloning an items just clones the properties, nothing else. In this case, the Shoot method in vanilla randomly chooses to shoot 3,4, or 5 projectiles. You'll have to do the same in your Shoot method. See the commented examples in ExampleGun.
[doublepost=1468560895,1468560721][/doublepost]
Would Main.rand.Next(0)==0) make a 100% chance not to consume ammo?
*Edit Is there a way for the setbonus to be Not Consume ITEMS instead of Ammo?
"if(Main.rand.Next(0)==0)" will always be true. Might as well just say "return true" or whatever.

GlobalItem has a ConsumeItem hook, so if you have a ModPlayer variable, you can check that to return false....You'll probably want to limit the scope to certain items.
 
Cloning an items just clones the properties, nothing else. In this case, the Shoot method in vanilla randomly chooses to shoot 3,4, or 5 projectiles. You'll have to do the same in your Shoot method. See the commented examples in ExampleGun.
[doublepost=1468560895,1468560721][/doublepost]
"if(Main.rand.Next(0)==0)" will always be true. Might as well just say "return true" or whatever.

GlobalItem has a ConsumeItem hook, so if you have a ModPlayer variable, you can check that to return false....You'll probably want to limit the scope to certain items.

So I put this in my ModPlayer cs file :

public override bool ConsumeItem (Item item, Player player)
{
if (this.SetBonus && item.thrown)
return false;

else
return base.ConsumeItem(item, player);
}

It says "no suitable method found to override. Is there something wrong?

*Edit Just realized that it had to be in the global Item and got it to work! Thanks!
 
Last edited:
Hello again!

I'm trying to make an armor piece that inflicts shadowflame on enemy NPC hits (similar to the Magma Stone).

Would I do something like this?

Code:
public override void UpdateEquip(Player player)
{
player.moveSpeed += 0.15f;
if (Main.rand.Next(4) == 0)
{
Main.npc[i].AddBuff(153, 360, false);
}
else if (Main.rand.Next(2) == 0)
{
Main.npc[i].AddBuff(153, 240, false);
}
else
{
Main.npc[i].AddBuff(153, 120, false);
}
Item item = player.inventory[player.selectedItem];
if (item.melee && !item.noMelee && !item.noUseGraphic && Main.rand.Next(3) != 0)
{
int num280 = Dust.NewDust(new Vector2((float)r2.X, (float)r2.Y), r2.Width, r2.Height, 27, player.velocity.X * 0.2f + (float)(player.direction * 3), player.velocity.Y * 0.2f, 100, default(Color), 2.5f);
Main.dust[num280].noGravity = true;
Dust expr_D7B2_cp_0 = Main.dust[num280];
expr_D7B2_cp_0.velocity.X = expr_D7B2_cp_0.velocity.X * 2f;
Dust expr_D7D2_cp_0 = Main.dust[num280];
expr_D7D2_cp_0.velocity.Y = expr_D7D2_cp_0.velocity.Y * 2f;
}
}

You have try in modplayer?
public override void MeleeEffects(Item item, Rectangle hitbox)
{
if(setbonus) {Dust.....}
base.MeleeEffects(item, hitbox);
}
 
How can I make a projectile that starts off slow, then speeds up? Is this a certain AI style I have to use? Or is it with the projectile's velocity?
Afaik, the Demon Scythe speeds up but starts slowly. You could look into its AI and tweak it.
Hello again!

I'm trying to make an armor piece that inflicts shadowflame on enemy NPC hits (similar to the Magma Stone).

Would I do something like this?

Code:
public override void UpdateEquip(Player player)
{
player.moveSpeed += 0.15f;
if (Main.rand.Next(4) == 0)
{
Main.npc[i].AddBuff(153, 360, false);
}
else if (Main.rand.Next(2) == 0)
{
Main.npc[i].AddBuff(153, 240, false);
}
else
{
Main.npc[i].AddBuff(153, 120, false);
}
Item item = player.inventory[player.selectedItem];
if (item.melee && !item.noMelee && !item.noUseGraphic && Main.rand.Next(3) != 0)
{
int num280 = Dust.NewDust(new Vector2((float)r2.X, (float)r2.Y), r2.Width, r2.Height, 27, player.velocity.X * 0.2f + (float)(player.direction * 3), player.velocity.Y * 0.2f, 100, default(Color), 2.5f);
Main.dust[num280].noGravity = true;
Dust expr_D7B2_cp_0 = Main.dust[num280];
expr_D7B2_cp_0.velocity.X = expr_D7B2_cp_0.velocity.X * 2f;
Dust expr_D7D2_cp_0 = Main.dust[num280];
expr_D7D2_cp_0.velocity.Y = expr_D7D2_cp_0.velocity.Y * 2f;
}
}
I'm not sure what you're trying to do here. If you want to add a (de)buff upon hitting an NPC, you can use the OnHitNPC hook.
[doublepost=1468603222,1468603077][/doublepost]
Can someone explain me how to use
TooltipLine
1. public readonly string mod
2. public readonly string Name


TooltipLine is used in ModifyTooltips(List<TooltipLine> tooltips) for custom tooltips.
 
@Gorateron like the AI of the Demon Scythe Projectile you mentioned or the shoot Methode of the Vampire Knives
He presumably wants to see the source code of Terraria.


Try ILSpy
http://ilspy.net/
Thats might be it, but how do I download it?
Aaah yes. You can look into the sourcecode by decompiling Terraria.exe, and thus you will need a decompiler. ILSpy is one of the best, and it's free. You can download it via the website ilspy.net You will want to look in Terraria.Terraria.Projectile.VanillaAI()
 
Afaik, the Demon Scythe speeds up but starts slowly. You could look into its AI and tweak it.

I'm not sure what you're trying to do here. If you want to add a (de)buff upon hitting an NPC, you can use the OnHitNPC hook.
[doublepost=1468603222,1468603077][/doublepost]
TooltipLine is used in ModifyTooltips(List<TooltipLine> tooltips) for custom tooltips.

Sorry, I fixed it. I just made a custom buff called "dsSetBonus", set a static bool called that to false in my main player class. Then I just put CalamityPlayer.dsSetBonus = true; in the set bonus for the armor set.

The set bonus causes the shadowflame debuff on enemy hits, demon scythes and shadowbeams to rain from the sky, and causes the armor wearer to emit shadowflame particles when they move.

It all works now :)
 
How can i manually animate a projectile? I have multiple animation frames in the texture, but how do i switch between them?
 
Back
Top Bottom