• Journey's End on PC - Find info here and here. Please report bugs and issues for PC 1.4 and 1.4.1 to Re-Logic here.
  • Journey's End on Mobile - Find info here. Report bugs for Mobile 1.4 to DR Studios at this link and give as much detail as possible.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Console and Switch - The latest news can be found here. To report a bug, please use this link.

tAPI [TUTORIAL] How to make a basic flail type weapon.

If you are reading this thread, you likely know how to create at least a basic item/weapon, if that's the case: Good! you can move right on to the next section.
However you may be completely new to modding in general in which case I wouldn't recommend starting with this.
Instead read this Tutorial first,
http://forums.terraria.org/index.php?threads/getting-started-with-modding.7832/
it covers a lot of basics in modding and will help you get started.

Now onto the real tutorial.
In this tutorial you will learn how to make a basic flail type weapon edit its stats.
It will be divided into three parts telling you how to make the chain of the flail, the actual flail, and the item

Creating the chain
In your mod folder, create another folder called Gores
inside this folder create a .png called ExampleChain
For now you can just use this one
ExampleChain.png
(provided by Zoomo)
Great! you're done with step one.

Creating the item
Step 1:
In your mod folder create another folder called Items
in that folder make a new Item json called ExampleFlail
inside that file use this code
Code:
{
    "code": "ExampleFlail",
    "displayName": "Example Flail",
    "size": [30,36],
    "maxStack": 1,
    "value": [0,0,0,0],
    "rare": 0,
    "pretendType": 163,
    "useStyle": 5,
    "useAnimation": 45,
    "useTime": 30,
    "damage": 30,
    "knockback": 8,
    "useSound": 1,
    "noMelee": true,
    "melee": true,
    "shoot": "YourModNameHere:ExampleBall",
    "shootSpeed": 18,
    "noUseGraphic": true,
    "channel": true,

    "recipes":
    [{
        "items": { "Dirt Block": 1  },
        "tiles": [ "Work Bench" ],
        "creates": 1
    }]
}
After you've done that you will need an image for you flail item
for now just use this
ExampleFlail.png
(Provided by Zoomo).

Finally you need your item CS file which will look something like this
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace YourModNameHere
{
    public class ExampleFlail : ModItem
    {
        public override void HoldStyle(Player P)
        {
            Main.chain3Texture = Main.goreTexture[GoreDef.gores["YourModNameHere:ExampleChain"]];
        }
    }
}
And that's it for your item.

The Flail Projectile
Yet again in your mod folder create a new folder called Projectiles
inside that folder you will make three files.
Number one will be the .png file, which will be you flail head(the actual mace part)
just use this sprite for now
ExampleBall.png
(also provided by Zoomo)

then lets move onto your projectiles json code
Code:
{
    "displayName": "Example Ball",
    "size": [30, 30], //size in this projectile means the hitbox, so it can be as big or small as you want.
    "aiStyle": 15,
    "friendly": true,
    "hostile": false,
    "tileCollide": true,
    "damage": 30,
    "melee": true,
    "penetrate": 40
}
And now your .json is finished

moving on to the .cs of your projectile
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace YourModNameHere.Projectiles
{
    public class ExampleBall : ModProjectile
    {
    }
}
you can put extra code in here for your projectile to have extra special effects(more on that later)
And now you should have a working flail!, which you can edit and use to your hearts content.
First download this image and put it in your gore folder with the other chain texture
Chain4.png

Then in your mod folder create a file to modify your player class, it should look something like this
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Mod
{
    public class MPlayer : TAPI.ModPlayer
    {
        public override void PreUpdate()
        {
            int held_item = player.inventory[player.selectedItem].type;
            if (held_item == 163)
            {
                Main.chain3Texture = Main.goreTexture[GoreDef.gores["Mod:Chain4"]]; //don't change any of this code

            }

        }
    }
}
and now whenever you switch to the bluemoon it will change its texture.
I hope this was helpful to you, and, if not please tell me why!

(for more projectile special effects and code visit this tutorial by Sin Costan
http://forums.terraria.org/index.php?threads/tutorial-projectile-guide-and-implementation.13048/ )
Currently there is a small bug with this code that changes the blue moon's chain texture into your modded one, I am trying to work this out, however if I remove the line of code that causes the problem, it will change your modded flail into the blue moon's chain texture
Great thanks to Everybody for helping me figure out how to do this
 
Last edited:

Jupa

Terrarian
Thank you very much for the flail tutorial, it's extremely helpful, but i noticed a bit of a bug. Since you are replacing the chain texture, that means by holding the " example flail " and then switching over to a blue moon, the blue moon chain texture will be changed to the one you're using for your custom flail. Is there anyway to fix this?
 
Thank you very much for the flail tutorial, it's extremely helpful, but i noticed a bit of a bug. Since you are replacing the chain texture, that means by holding the " example flail " and then switching over to a blue moon, the blue moon chain texture will be changed to the one you're using for your custom flail. Is there anyway to fix this?
I'll check it out, is it permanent? or does blue moon revert back to normal at some point?
I'll try and fix it now.
 

Jupa

Terrarian
I'll check it out, is it permanent? or does blue moon revert back to normal at some point?
I'll try and fix it now.

From what i know, it will only revert if you reload the world. How Ironic, i was so sick of seeing the flails having the blue moon chains and didn't know how to fix it, and now the opposite problem appears! Oh well, i'm sure you could find some way to check if the player is no longer holding the item, and then change the texture back to normal.
 
From what i know, it will only revert if you reload the world. How Ironic, i was so sick of seeing the flails having the blue moon chains and didn't know how to fix it, and now the opposite problem appears! Oh well, i'm sure you could find some way to check if the player is no longer holding the item, and then change the texture back to normal.
It's strange, it permanently changes the texture for me, looking for a way to fix it now.
 

Jupa

Terrarian
It's strange, it permanently changes the texture for me, looking for a way to fix it now.

Reload your world and use ONLY the blue flail, i have a felling you did what i did that confused me originally, and had the test flail in my hot bar. Simply scrolling over it will change the texture. Either way, should probably get it fixed
 
Reload your world and use ONLY the blue flail, i have a felling you did what i did that confused me originally, and had the test flail in my hot bar. Simply scrolling over it will change the texture. Either way, should probably get it fixed
The cs item file is there so that the chain texture doesn't become blue moon at all times, unfortunately this also overrides blue moon's chain texture, also I can't seem to change the code without the modded chain becoming blue moon again. I will continue working on this problem though, thanks for bringing it to my attention.
 

Sin Costan

Eye of Cthulhu
The cs item file is there so that the chain texture doesn't become blue moon at all times, unfortunately this also overrides blue moon's chain texture, also I can't seem to change the code without the modded chain becoming blue moon again. I will continue working on this problem though, thanks for bringing it to my attention.
The simplest solution is probably to get the vanilla chain textures, label them as your own under gore, and then when you need to switch them back, you just set the chain texture back to the original chain that you c&p using the PostKill() method for your projectile. Never tested this, but logically it should work.
 
The simplest solution is probably to get the vanilla chain textures, label them as your own under gore, and then when you need to switch them back, you just set the chain texture back to the original chain that you c&p using the PostKill() method for your projectile. Never tested this, but logically it should work.
so something like this? Just asking so I can put this in the tutorial.
Code:
namespace Mod.Projectiles
{
    public class ExampleBall : ModProjectile
    {
        public override void PostKill()
        {
            Main.chain3Texture = Main.goreTexture[GoreDef.gores["Mod:Chain4"]];
        }
    }
}
 

Eli10293

Spazmatism
The simplest solution is probably to get the vanilla chain textures, label them as your own under gore, and then when you need to switch them back, you just set the chain texture back to the original chain that you c&p using the PostKill() method for your projectile. Never tested this, but logically it should work.
Could i Possibly make a flail controllabe like a magic missle by adding in code like
Code:
public override void AI()
        {
                                    if (projectile.aiStyle == 15)
                                    {
                                        {
                                            int num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 3.5f);
                                            Main.dust[num142].noGravity = true;
                                            Main.dust[num142].velocity *= 1.4f;
                                            num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 1.5f);
                                        }
                                        if (Main.myPlayer == projectile.owner && projectile.ai[0] == 0f)
                                        {
                                            if (Main.player[projectile.owner].channel)
                                            {
                                                float num146 = 12f;
                                                if (projectile.type == 16)
                                                {
                                                    num146 = 15f;
                                                }
                                                Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                                                float num147 = (float)Main.mouseX + Main.screenPosition.X - vector10.X;
                                                float num148 = (float)Main.mouseY + Main.screenPosition.Y - vector10.Y;
                                                if (Main.player[projectile.owner].gravDir == -1f)
                                                {
                                                    num148 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector10.Y;
                                                }
                                                float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                if (num149 > num146)
                                                {
                                                    num149 = num146 / num149;
                                                    num147 *= num149;
                                                    num148 *= num149;
                                                    int num150 = (int)(num147 * 1000f);
                                                    int num151 = (int)(projectile.velocity.X * 1000f);
                                                    int num152 = (int)(num148 * 1000f);
                                                    int num153 = (int)(projectile.velocity.Y * 1000f);
                                                    if (num150 != num151 || num152 != num153)
                                                    {
                                                        projectile.netUpdate = true;
                                                    }
                                                    projectile.velocity.X = num147;
                                                    projectile.velocity.Y = num148;
                                                }
                                            }
                                        }
                                    }
        }
    }
}
 
Could i Possibly make a flail controllabe like a magic missle by adding in code like
Code:
public override void AI()
        {
                                    if (projectile.aiStyle == 15)
                                    {
                                        {
                                            int num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 3.5f);
                                            Main.dust[num142].noGravity = true;
                                            Main.dust[num142].velocity *= 1.4f;
                                            num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 1.5f);
                                        }
                                        if (Main.myPlayer == projectile.owner && projectile.ai[0] == 0f)
                                        {
                                            if (Main.player[projectile.owner].channel)
                                            {
                                                float num146 = 12f;
                                                if (projectile.type == 16)
                                                {
                                                    num146 = 15f;
                                                }
                                                Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                                                float num147 = (float)Main.mouseX + Main.screenPosition.X - vector10.X;
                                                float num148 = (float)Main.mouseY + Main.screenPosition.Y - vector10.Y;
                                                if (Main.player[projectile.owner].gravDir == -1f)
                                                {
                                                    num148 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector10.Y;
                                                }
                                                float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                if (num149 > num146)
                                                {
                                                    num149 = num146 / num149;
                                                    num147 *= num149;
                                                    num148 *= num149;
                                                    int num150 = (int)(num147 * 1000f);
                                                    int num151 = (int)(projectile.velocity.X * 1000f);
                                                    int num152 = (int)(num148 * 1000f);
                                                    int num153 = (int)(projectile.velocity.Y * 1000f);
                                                    if (num150 != num151 || num152 != num153)
                                                    {
                                                        projectile.netUpdate = true;
                                                    }
                                                    projectile.velocity.X = num147;
                                                    projectile.velocity.Y = num148;
                                                }
                                            }
                                        }
                                    }
        }
    }
}
No I don't think it would work, I believe you have to make the projectile ai style the same as magic missiles if you want that to work
 

Sin Costan

Eye of Cthulhu
Could i Possibly make a flail controllabe like a magic missle by adding in code like
Code:
public override void AI()
        {
                                    if (projectile.aiStyle == 15)
                                    {
                                        {
                                            int num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 3.5f);
                                            Main.dust[num142].noGravity = true;
                                            Main.dust[num142].velocity *= 1.4f;
                                            num142 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 27, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, default(Color), 1.5f);
                                        }
                                        if (Main.myPlayer == projectile.owner && projectile.ai[0] == 0f)
                                        {
                                            if (Main.player[projectile.owner].channel)
                                            {
                                                float num146 = 12f;
                                                if (projectile.type == 16)
                                                {
                                                    num146 = 15f;
                                                }
                                                Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
                                                float num147 = (float)Main.mouseX + Main.screenPosition.X - vector10.X;
                                                float num148 = (float)Main.mouseY + Main.screenPosition.Y - vector10.Y;
                                                if (Main.player[projectile.owner].gravDir == -1f)
                                                {
                                                    num148 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector10.Y;
                                                }
                                                float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
                                                if (num149 > num146)
                                                {
                                                    num149 = num146 / num149;
                                                    num147 *= num149;
                                                    num148 *= num149;
                                                    int num150 = (int)(num147 * 1000f);
                                                    int num151 = (int)(projectile.velocity.X * 1000f);
                                                    int num152 = (int)(num148 * 1000f);
                                                    int num153 = (int)(projectile.velocity.Y * 1000f);
                                                    if (num150 != num151 || num152 != num153)
                                                    {
                                                        projectile.netUpdate = true;
                                                    }
                                                    projectile.velocity.X = num147;
                                                    projectile.velocity.Y = num148;
                                                }
                                            }
                                        }
                                    }
        }
    }
}
I saw this before, forgot to answer you. Yes, you can, tested it before actually...
 
Are U Ever Going 2 Upload The Finished Flail?
I will right now. I was waiting until I worked out the bug with the blue moon chain.
[DOUBLEPOST=1430022993,1430022605][/DOUBLEPOST]
I will right now. I was waiting until I worked out the bug with the blue moon chain.
The working flail has been uploaded, message me if there are any problems(it's literally exactly what you did in the tutorial so there shouldn't be
 

Eli10293

Spazmatism
I will right now. I was waiting until I worked out the bug with the blue moon chain.
[DOUBLEPOST=1430022993,1430022605][/DOUBLEPOST]
The working flail has been uploaded, message me if there are any problems(it's literally exactly what you did in the tutorial so there shouldn't be
I Thought You Were Going To Post An Image Of it :(
 
Top Bottom