Standalone [1.3] tModLoader - A Modding API

how do i make bullets home like the Chlorophyte Bullet
There's a lot of code required for that. I'd suggest you look up the vanilla code for the Chlorophyte bullet and see if you can get a comprehension of it. If not, just change all 'this' and 'base' refs to 'projectile'.
Code:
else if (this.type == 207)
{
    if (this.alpha < 170)
    {
        for (int num136 = 0; num136 < 10; num136++)
        {
            float x2 = this.position.X - this.velocity.X / 10f * (float)num136;
            float y2 = this.position.Y - this.velocity.Y / 10f * (float)num136;
            int num137 = Dust.NewDust(new Vector2(x2, y2), 1, 1, 75, 0f, 0f, 0, default(Color), 1f);
            Main.dust[num137].alpha = this.alpha;
            Main.dust[num137].position.X = x2;
            Main.dust[num137].position.Y = y2;
            Main.dust[num137].velocity *= 0f;
            Main.dust[num137].noGravity = true;
        }
    }
    float num138 = (float)Math.Sqrt((double)(this.velocity.X * this.velocity.X + this.velocity.Y * this.velocity.Y));
    float num139 = this.localAI[0];
    if (num139 == 0f)
    {
        this.localAI[0] = num138;
        num139 = num138;
    }
    if (this.alpha > 0)
    {
        this.alpha -= 25;
    }
    if (this.alpha < 0)
    {
        this.alpha = 0;
    }
    float num140 = this.position.X;
    float num141 = this.position.Y;
    float num142 = 300f;
    bool flag4 = false;
    int num143 = 0;
    if (this.ai[1] == 0f)
    {
        for (int num144 = 0; num144 < 200; num144++)
        {
            if (Main.npc[num144].CanBeChasedBy(this, false) && (this.ai[1] == 0f || this.ai[1] == (float)(num144 + 1)))
            {
                float num145 = Main.npc[num144].position.X + (float)(Main.npc[num144].width / 2);
                float num146 = Main.npc[num144].position.Y + (float)(Main.npc[num144].height / 2);
                float num147 = Math.Abs(this.position.X + (float)(this.width / 2) - num145) + Math.Abs(this.position.Y + (float)(this.height / 2) - num146);
                if (num147 < num142 && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num144].position, Main.npc[num144].width, Main.npc[num144].height))
                {
                    num142 = num147;
                    num140 = num145;
                    num141 = num146;
                    flag4 = true;
                    num143 = num144;
                }
            }
        }
        if (flag4)
        {
            this.ai[1] = (float)(num143 + 1);
        }
        flag4 = false;
    }
    if (this.ai[1] > 0f)
    {
        int num148 = (int)(this.ai[1] - 1f);
        if (Main.npc[num148].active && Main.npc[num148].CanBeChasedBy(this, true) && !Main.npc[num148].dontTakeDamage)
        {
            float num149 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
            float num150 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
            float num151 = Math.Abs(this.position.X + (float)(this.width / 2) - num149) + Math.Abs(this.position.Y + (float)(this.height / 2) - num150);
            if (num151 < 1000f)
            {
                flag4 = true;
                num140 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
                num141 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
            }
        }
        else
        {
            this.ai[1] = 0f;
        }
    }
    if (!this.friendly)
    {
        flag4 = false;
    }
    if (flag4)
    {
        float num152 = num139;
        Vector2 vector13 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
        float num153 = num140 - vector13.X;
        float num154 = num141 - vector13.Y;
        float num155 = (float)Math.Sqrt((double)(num153 * num153 + num154 * num154));
        num155 = num152 / num155;
        num153 *= num155;
        num154 *= num155;
        int num156 = 8;
        this.velocity.X = (this.velocity.X * (float)(num156 - 1) + num153) / (float)num156;
        this.velocity.Y = (this.velocity.Y * (float)(num156 - 1) + num154) / (float)num156;
    }
}
 
I'm trying to download the example mod, but it just takes me to a Permission Denied page. Anyone else?
 
Any support for flails?
There's not really support needed for flails (if you ask me at least). You can take a look at the flails that are allready in Terraria. They're projectiles, so you can find their AI in the Projectile.cs file.
Are you looking for a flail in specific?
 
There's not really support needed for flails (if you ask me at least). You can take a look at the flails that are allready in Terraria. They're projectiles, so you can find their AI in the Projectile.cs file.
Are you looking for a flail in specific?
Ik but I'm not sure how the code to add a custom chain for a custom flail would work. Pretty sure flail projectile AI is 15
 
that worked

so just so i know if i want to add a new banner i just make that picture file bigger and use case:2 right
[DOUBLEPOST=1448281555,1448281159][/DOUBLEPOST]i found another thing i cant seem to get right

View attachment 85681

i got both red and blue Sarcophagus blue being the one that was there to start with

anyway to make the banner only say Sarcophagus
while both mobs are named red and blue
To make the banner only say Sarcophagus, the NPC that the banner is based on will have to have the name Sarcophagus. It's the same way with vanilla banners too.

As far as I understand it, you aren't allowed to distribute restricted content from Terraria. Well, I'm not really giving access to unobtainable items, I'm making a copy of them... So you can't just craft the Vortex Drill from my mod and then sell it to Vanilla players. I have no idea if that counts as illegal distribution or not.:confused: Should I ask a moderator about this?

As for the textures, I'll redo the Luminite drill textures from scratch (if implementing them is allowed in the first place. If not, I'll remove both the drills and the hamsaws completely).

OK, that makes sense. I'm not that familiar with rendering in Terraria/C# but I'll come up with something.
It wouldn't hurt to ask the mods; that would also clear up some confusion. On that note, their rules also contain out-of-date information (such as dev armor not being obtainable), so it would be nice for them to update that too.

Ik but I'm not sure how the code to add a custom chain for a custom flail would work. Pretty sure flail projectile AI is 15
To draw the chain you would basically use either the PostDraw or PreDraw hook.
 
Yeah, that's quite the task, but lemme show you what I've got:
Code:
        public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
        {
            Texture2D texture = ModLoader.GetTexture("YourMod/Folder/AnotherFolder/MyFlail_Chain");

            Vector2 position = projectile.Center;
            Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
            Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
            Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
            float num1 = (float)texture.Height;
            Vector2 vector2_4 = mountedCenter - position;
            float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
            bool flag = true;
            if (float.IsNaN(position.X) && float.IsNaN(position.Y))
                flag = false;
            if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
                flag = false;
            while (flag)
            {
                if ((double)vector2_4.Length() < (double)num1 + 1.0)
                {
                    flag = false;
                }
                else
                {
                    Vector2 vector2_1 = vector2_4;
                    vector2_1.Normalize();
                    position += vector2_1 * num1;
                    vector2_4 = mountedCenter - position;
                    Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                    color2 = projectile.GetAlpha(color2);
                    Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
                }
            }
        }
This is what I'm using for my Grappling hook, but it should work (practically) the same for drawing the chain for a flail. It's a bit of a pain to explain it all, but if you're a bit programming savvy, you'll get (mostly) everything that's going on.
Just make sure to change the GetTexture method correctly.
 
Yeah, that's quite the task, but lemme show you what I've got:
Code:
        public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
        {
            Texture2D texture = ModLoader.GetTexture("YourMod/Folder/AnotherFolder/MyFlail_Chain");

            Vector2 position = projectile.Center;
            Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
            Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
            Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
            float num1 = (float)texture.Height;
            Vector2 vector2_4 = mountedCenter - position;
            float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
            bool flag = true;
            if (float.IsNaN(position.X) && float.IsNaN(position.Y))
                flag = false;
            if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
                flag = false;
            while (flag)
            {
                if ((double)vector2_4.Length() < (double)num1 + 1.0)
                {
                    flag = false;
                }
                else
                {
                    Vector2 vector2_1 = vector2_4;
                    vector2_1.Normalize();
                    position += vector2_1 * num1;
                    vector2_4 = mountedCenter - position;
                    Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                    color2 = projectile.GetAlpha(color2);
                    Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
                }
            }
        }
This is what I'm using for my Grappling hook, but it should work (practically) the same for drawing the chain for a flail. It's a bit of a pain to explain it all, but if you're a bit programming savvy, you'll get (mostly) everything that's going on.
Just make sure to change the GetTexture method correctly.
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TemMod.Items.Weapons {
public class SpikedSlimeFlail : ModItem
{
    public override void SetDefaults()
    {
        item.name = "Spiked Slime Ball";
        item.damage = 90;
        item.melee = true;
        item.width = 36;
        item.height = 38;
        item.toolTip = "A ball of slime armed with spikes?";
        item.useTime = 20;
        item.useAnimation = 20;
        item.useStyle = 5;
        item.knockBack = 6;
        item.value = 0;
        item.noUseGraphic = true;
        item.rare = 9;
        item.useSound = 1;
        item.autoReuse = true;
        item.shoot = mod.ProjectileType("SlimeBall");
        item.shootSpeed = 10;
    }

    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.SetResult(this, 1);
        recipe.AddRecipe();
    }
    public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
    {
        Texture2D texture = ModLoader.GetTexture("TemMod/Items/Weapons/Melee/SlimeChain");
        Vector2 position = projectile.Center;
        Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
        Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
        Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
        float num1 = (float)texture.Height;
        Vector2 vector2_4 = mountedCenter - position;
        float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
        bool flag = true;
        if (float.IsNaN(position.X) && float.IsNaN(position.Y))
            flag = false;
        if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
            flag = false;
        while (flag)
        {
            if ((double)vector2_4.Length() < (double)num1 + 1.0)
            {
                flag = false;
            }
            else
            {
                Vector2 vector2_1 = vector2_4;
                vector2_1.Normalize();
                position += vector2_1 * num1;
                vector2_4 = mountedCenter - position;
                Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                color2 = projectile.GetAlpha(color2);
                Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
            }
        }
    }
}}
I get this error when building
upload_2015-11-23_15-22-5.png
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TemMod.Items.Weapons {
public class SpikedSlimeFlail : ModItem
{
    public override void SetDefaults()
    {
        item.name = "Spiked Slime Ball";
        item.damage = 90;
        item.melee = true;
        item.width = 36;
        item.height = 38;
        item.toolTip = "A ball of slime armed with spikes?";
        item.useTime = 20;
        item.useAnimation = 20;
        item.useStyle = 5;
        item.knockBack = 6;
        item.value = 0;
        item.noUseGraphic = true;
        item.rare = 9;
        item.useSound = 1;
        item.autoReuse = true;
        item.shoot = mod.ProjectileType("SlimeBall");
        item.shootSpeed = 10;
    }

    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(ItemID.DirtBlock);
        recipe.SetResult(this, 1);
        recipe.AddRecipe();
    }
    public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
    {
        Texture2D texture = ModLoader.GetTexture("TemMod/Items/Weapons/Melee/SlimeChain");
        Vector2 position = projectile.Center;
        Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
        Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
        Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
        float num1 = (float)texture.Height;
        Vector2 vector2_4 = mountedCenter - position;
        float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
        bool flag = true;
        if (float.IsNaN(position.X) && float.IsNaN(position.Y))
            flag = false;
        if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
            flag = false;
        while (flag)
        {
            if ((double)vector2_4.Length() < (double)num1 + 1.0)
            {
                flag = false;
            }
            else
            {
                Vector2 vector2_1 = vector2_4;
                vector2_1.Normalize();
                position += vector2_1 * num1;
                vector2_4 = mountedCenter - position;
                Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                color2 = projectile.GetAlpha(color2);
                Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
            }
        }
    }
}}
I get this error when building
View attachment 85726
Are you applying this logic on your projectile or on your Item? It should be applied on your ModProjectile.
 
Alright, that worked, but now I'm getting an error.
error CS0006: metadata file 'TerrariaMac.exe' could not be found
I'm on Windows so I'm confused why it needs mac
A lot of peeps have been getting that error, although I'm not exactly sure where it comes from. When are you getting the error?
 
Are you applying this logic on your projectile or on your Item? It should be applied on your ModProjectile.
Applied it to projectile
upload_2015-11-23_15-27-11.png

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

namespace TemMod.Projectiles {
public class SlimeBall : ModProjectile
{
    public override void SetDefaults()
    {
        projectile.name = "Spiked Slime Ball";
        projectile.width = 34;
        projectile.height = 34;
        projectile.friendly = true;
        projectile.melee = true;
        projectile.penetrate = -1;
        projectile.timeLeft = 10000;
        projectile.aiStyle = 15;
    }
    public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
    {
        Texture2D texture = ModLoader.GetTexture("TemMod/Items/Weapons/Melee/SlimeChain");
        Vector2 position = projectile.Center;
        Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
        Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
        Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
        float num1 = (float)texture.Height;
        Vector2 vector2_4 = mountedCenter - position;
        float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
        bool flag = true;
        if (float.IsNaN(position.X) && float.IsNaN(position.Y))
            flag = false;
        if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
            flag = false;
        while (flag)
        {
            if ((double)vector2_4.Length() < (double)num1 + 1.0)
            {
                flag = false;
            }
            else
            {
                Vector2 vector2_1 = vector2_4;
                vector2_1.Normalize();
                position += vector2_1 * num1;
                vector2_4 = mountedCenter - position;
                Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                color2 = projectile.GetAlpha(color2);
                Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
            }
        }
    }
}}
 
Applied it to projectile
View attachment 85728
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TemMod.Projectiles {
public class SlimeBall : ModProjectile
{
    public override void SetDefaults()
    {
        projectile.name = "Spiked Slime Ball";
        projectile.width = 34;
        projectile.height = 34;
        projectile.friendly = true;
        projectile.melee = true;
        projectile.penetrate = -1;
        projectile.timeLeft = 10000;
        projectile.aiStyle = 15;
    }
    public override void PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Color lightColor)
    {
        Texture2D texture = ModLoader.GetTexture("TemMod/Items/Weapons/Melee/SlimeChain");
        Vector2 position = projectile.Center;
        Vector2 mountedCenter = Main.player[projectile.owner].MountedCenter;
        Microsoft.Xna.Framework.Rectangle? sourceRectangle = new Microsoft.Xna.Framework.Rectangle?();
        Vector2 origin = new Vector2((float)texture.Width * 0.5f, (float)texture.Height * 0.5f);
        float num1 = (float)texture.Height;
        Vector2 vector2_4 = mountedCenter - position;
        float rotation = (float)Math.Atan2((double)vector2_4.Y, (double)vector2_4.X) - 1.57f;
        bool flag = true;
        if (float.IsNaN(position.X) && float.IsNaN(position.Y))
            flag = false;
        if (float.IsNaN(vector2_4.X) && float.IsNaN(vector2_4.Y))
            flag = false;
        while (flag)
        {
            if ((double)vector2_4.Length() < (double)num1 + 1.0)
            {
                flag = false;
            }
            else
            {
                Vector2 vector2_1 = vector2_4;
                vector2_1.Normalize();
                position += vector2_1 * num1;
                vector2_4 = mountedCenter - position;
                Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)position.X / 16, (int)((double)position.Y / 16.0));
                color2 = projectile.GetAlpha(color2);
                Main.spriteBatch.Draw(texture, position - Main.screenPosition, sourceRectangle, color2, rotation, origin, 1f, SpriteEffects.None, 0.0f);
            }
        }
    }
}}
Have you made sure to include its namespace?
Code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
 
Alright, that worked, but now I'm getting an error.
error CS0006: metadata file 'TerrariaMac.exe' could not be found
I'm on Windows so I'm confused why it needs mac
Did you make sure to click the "Setup Dev Environment" button on the installer? This is necessary to make your mods cross-platform compatible.
 
How I can add % of not consume ammo?
Do you mean to a weapon or to the player itself (as in a buff)?
On the weapon it's easy, you can override the ConsumeAmmo function of the ModItem and just check against a random value. As an example:
Code:
public override bool ConsumeAmmo(Player player)
{
    if (Main.rand.Next(0, 2) == 0) // 50% chance not to consume ammo.
        return false;
    return true;
}
If you want it on the player, you'll either need to wait for player hooks (I guess you'll be able to do it then) or use one of the build in booleans from the player, but these are hardcoded at set percentages.
 
Back
Top Bottom