Standalone [1.3] tModLoader - A Modding API

I'm not exactly sure why you'd involve the velocity here(?).
We're talking about shoot intervalls here :p

That's weird, doesn't happen with me... Could you show me all your code (preferably in a spoiler, since it must be pretty long :p)
Yeah, ofc.
Code:
    public class TonbogiriProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Tonbogiri Projectile";
            projectile.width = 18;
            projectile.height = 18;
            projectile.scale = 1.3f;

            projectile.friendly = true;
            projectile.tileCollide = false;
            projectile.ownerHitCheck = true;

            projectile.penetrate = -1;
            projectile.melee = true;

            projectile.alpha = 0;
            projectile.hide = true;

            projectile.aiStyle = 19;
        }

        public override bool PreAI()
        {
            float protractSpeed = 1.5F;
            float retractSpeed = 1.4F;

            Vector2 vector21 = Main.player[projectile.owner].RotatedRelativePoint(Main.player[projectile.owner].MountedCenter, true);
            projectile.direction = Main.player[projectile.owner].direction;
            Main.player[projectile.owner].heldProj = projectile.whoAmI;
            Main.player[projectile.owner].itemTime = Main.player[projectile.owner].itemAnimation;
            projectile.position.X = vector21.X - (float)(projectile.width / 2);
            projectile.position.Y = vector21.Y - (float)(projectile.height / 2);
            if (!Main.player[projectile.owner].frozen)
            {
                if (projectile.ai[0] == 0f)
                {
                    projectile.ai[0] = 3f;
                    projectile.netUpdate = true;
                }
                if (Main.player[projectile.owner].itemAnimation < Main.player[projectile.owner].itemAnimationMax / 3)
                {
                    projectile.ai[0] -= retractSpeed;
                }
                else
                {
                    projectile.ai[0] += protractSpeed;
                }
            }
            projectile.position += projectile.velocity * projectile.ai[0];
            if (Main.player[projectile.owner].itemAnimation == 0)
            {
                projectile.Kill();
            }
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f;
            if (projectile.spriteDirection == -1)
            {
                projectile.rotation -= 1.57f;
            }
            return false;
        }

        public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Color lightColor)
        {
            Vector2 zero = Vector2.Zero;
            SpriteEffects effects1 = SpriteEffects.None;
            if (projectile.spriteDirection == -1)
            {
                zero.X = (float)Main.projectileTexture[projectile.type].Width;
                effects1 = SpriteEffects.FlipHorizontally;
            }
            Main.spriteBatch.Draw(Main.projectileTexture[projectile.type], new Vector2(projectile.position.X - Main.screenPosition.X + (float)(projectile.width / 2), projectile.position.Y - Main.screenPosition.Y + (float)(projectile.height / 2) + projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.projectileTexture[projectile.type].Width, Main.projectileTexture[projectile.type].Height)), projectile.GetAlpha(lightColor), projectile.rotation, zero, projectile.scale, effects1, 0.0f);
            return base.PreDraw(spriteBatch, lightColor);
        }

    }
}
 
Yeah, ofc.
Code:
    public class TonbogiriProjectile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Tonbogiri Projectile";
            projectile.width = 18;
            projectile.height = 18;
            projectile.scale = 1.3f;

            projectile.friendly = true;
            projectile.tileCollide = false;
            projectile.ownerHitCheck = true;

            projectile.penetrate = -1;
            projectile.melee = true;

            projectile.alpha = 0;
            projectile.hide = true;

            projectile.aiStyle = 19;
        }

        public override bool PreAI()
        {
            float protractSpeed = 1.5F;
            float retractSpeed = 1.4F;

            Vector2 vector21 = Main.player[projectile.owner].RotatedRelativePoint(Main.player[projectile.owner].MountedCenter, true);
            projectile.direction = Main.player[projectile.owner].direction;
            Main.player[projectile.owner].heldProj = projectile.whoAmI;
            Main.player[projectile.owner].itemTime = Main.player[projectile.owner].itemAnimation;
            projectile.position.X = vector21.X - (float)(projectile.width / 2);
            projectile.position.Y = vector21.Y - (float)(projectile.height / 2);
            if (!Main.player[projectile.owner].frozen)
            {
                if (projectile.ai[0] == 0f)
                {
                    projectile.ai[0] = 3f;
                    projectile.netUpdate = true;
                }
                if (Main.player[projectile.owner].itemAnimation < Main.player[projectile.owner].itemAnimationMax / 3)
                {
                    projectile.ai[0] -= retractSpeed;
                }
                else
                {
                    projectile.ai[0] += protractSpeed;
                }
            }
            projectile.position += projectile.velocity * projectile.ai[0];
            if (Main.player[projectile.owner].itemAnimation == 0)
            {
                projectile.Kill();
            }
            projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 2.355f;
            if (projectile.spriteDirection == -1)
            {
                projectile.rotation -= 1.57f;
            }
            return false;
        }

        public override bool PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Color lightColor)
        {
            Vector2 zero = Vector2.Zero;
            SpriteEffects effects1 = SpriteEffects.None;
            if (projectile.spriteDirection == -1)
            {
                zero.X = (float)Main.projectileTexture[projectile.type].Width;
                effects1 = SpriteEffects.FlipHorizontally;
            }
            Main.spriteBatch.Draw(Main.projectileTexture[projectile.type], new Vector2(projectile.position.X - Main.screenPosition.X + (float)(projectile.width / 2), projectile.position.Y - Main.screenPosition.Y + (float)(projectile.height / 2) + projectile.gfxOffY), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(0, 0, Main.projectileTexture[projectile.type].Width, Main.projectileTexture[projectile.type].Height)), projectile.GetAlpha(lightColor), projectile.rotation, zero, projectile.scale, effects1, 0.0f);
            return base.PreDraw(spriteBatch, lightColor);
        }

    }
}
Can I also see your item code?
 
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class Angelic : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "AngelicBeing";
            npc.displayName = "Angelic Being";
            npc.width = 250;
            npc.height = 208;
            npc.damage = 120;
            npc.defense = 20;
            npc.lifeMax = 30000;
            npc.soundHit = 1;
            npc.soundKilled = 2;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
                                            public override bool PreAI()
{
    npc.noGravity = true;
    // The following handles the collision:
    if (!npc.noTileCollide)
    {
        if (npc.collideX)
        {
            npc.velocity.X = npc.oldVelocity.X * -0.5f;
            if (npc.direction == -1 && (double) npc.velocity.X > 0.0 && (double) npc.velocity.X < 2.0)
                npc.velocity.X = 2f;
            if (npc.direction == 1 && (double) npc.velocity.X < 0.0 && (double) npc.velocity.X > -2.0)
                npc.velocity.X = -2f;
        }
        if (npc.collideY)
        {
            npc.velocity.Y = npc.oldVelocity.Y * -0.5f;
            if ((double) npc.velocity.Y > 0.0 && (double) npc.velocity.Y < 1.0)
                npc.velocity.Y = 1f;
            if ((double) npc.velocity.Y < 0.0 && (double) npc.velocity.Y > -1.0)
                npc.velocity.Y = -1f;
        }
    } 
 
    npc.TargetClosest(true); // Gets a valid player to target.
    //The 'true' means that we want the NPC to look at the player.

    // The following is plucked right from the 'Demon Eye' AI, so you may want to take a look, but you might not understand it all:
 
    float num1 = 4f;
    float num2 = 1.5f;
    float num3 = num1 * (float) (1.0 + (1.0 - (double) npc.scale));
    float num4 = num2 * (float) (1.0 + (1.0 - (double) npc.scale));
    if (npc.direction == -1 && (double) npc.velocity.X > -(double) num3)
    {
        npc.velocity.X = npc.velocity.X - 0.1f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = npc.velocity.X - 0.1f;
        else if ((double) npc.velocity.X > 0.0)
            npc.velocity.X = npc.velocity.X + 0.05f;
        if ((double) npc.velocity.X < -(double) num3)
         npc.velocity.X = -num3;
    }
    else if (npc.direction == 1 && (double) npc.velocity.X < (double) num3)
    {
        npc.velocity.X = npc.velocity.X + 0.1f;
        if ((double) npc.velocity.X < -(double) num3)
            npc.velocity.X = npc.velocity.X + 0.1f;
        else if ((double) npc.velocity.X < 0.0)
            npc.velocity.X = npc.velocity.X - 0.05f;
        if ((double) npc.velocity.X > (double) num3)
            npc.velocity.X = num3;
    }
    if (npc.directionY == -1 && (double) npc.velocity.Y > -(double) num4)
    {
        npc.velocity.Y = npc.velocity.Y - 0.04f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = npc.velocity.Y - 0.05f;
        else if ((double) npc.velocity.Y > 0.0)
            npc.velocity.Y = npc.velocity.Y + 0.03f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = -num4;
    }
    else if (npc.directionY == 1 && (double) npc.velocity.Y < (double) num4)
    {
        npc.velocity.Y = npc.velocity.Y + 0.04f;
        if ((double) npc.velocity.Y < -(double) num4)
            npc.velocity.Y = npc.velocity.Y + 0.05f;
        else if ((double) npc.velocity.Y < 0.0)
            npc.velocity.Y = npc.velocity.Y - 0.03f;
        if ((double) npc.velocity.Y > (double) num4)
            npc.velocity.Y = num4;
    }
 
    if(!npc.wet)
        return false;
 
    if ((double) npc.velocity.Y > 0.0)
        npc.velocity.Y = npc.velocity.Y * 0.95f;
    npc.velocity.Y = npc.velocity.Y - 0.5f;
    if ((double) npc.velocity.Y < -4.0)
        npc.velocity.Y = -4f;
    npc.TargetClosest(true);
 
    return false;
}
public override void FindFrame(int frameHeight)
{
    if ((double) npc.velocity.X > 0.0)
    {
        npc.spriteDirection = 1;
        npc.rotation = (float) Math.Atan2((double) npc.velocity.Y, (double) npc.velocity.X);
    }
    if ((double) npc.velocity.X < 0.0)
    {
        npc.spriteDirection = -1;
        npc.rotation = (float) Math.Atan2((double) npc.velocity.Y, (double) npc.velocity.X) + 3.14f;
    }
}
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.sky && Main.dayTime ? 0.5f : 0;
        }
        public override void NPCLoot()
        {   
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ShatteredHalo"));
        }
    }
}
This is my current code
[DOUBLEPOST=1453430301,1453430266][/DOUBLEPOST]what would I need to add
[DOUBLEPOST=1453430754][/DOUBLEPOST]I would like the boss to shoot 2 different things.
 
public override bool Autoload(ref string name, ref string texture)
{
name = "MaskedMan";
return mod.Properties.Autoload;
}

public override void SetDefaults()
{
npc.name = "Mask Salesman";
npc.townNPC = true;
I think these 2 names need to be the same to save correctly
 
I'm not exactly sure what you mean... Do you want to use your summoning item and then spawn multiple minions, or do you want to increase the amount of minions the player can control? ;)

projectile.minionSlots (on your minion I assume) determines how many slots the minion should take up. So if you have... Say room for 4 minions and you spawn two minions that have minionSlots set to 2, you won't be able to spawn any more, since your available slots have been filled.

Oh sorry, I meant I'd like to use my summoning item to spawn multiple minions. How would you go about doing that? Thanks!
 
Can I also see your item code?
Yep.
Code:
public class Tonbogiri : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Tonbogiri";
            item.damage = 67;
            item.crit = 10;
            item.melee = true;
            item.width = 48;
            item.height = 48;
            item.scale = 1f;
            item.useTime = 30;
            item.useAnimation = 30;
            item.noUseGraphic = true;
            item.noMelee = true;
            item.useStyle = 5;
            item.knockBack = 4;
            item.value = 100000;
            item.rare = 7;
            item.useSound = 1;
            item.autoReuse = true;
            item.shoot = mod.ProjectileType("TonbogiriProjectile");
            item.shootSpeed = 3.7f;
        }
 
Yeah here it is:


INTERNAL configuration error: failed to get configuration 'system.diagnostics'
at System.Diagnostics.DiagnosticsConfiguration.get_Settings () [0x00000] in <filename unknown>:0
at System.Diagnostics.TraceImpl.InitOnce () [0x00000] in <filename unknown>:0
at System.Diagnostics.TraceImpl.get_Listeners () [0x00000] in <filename unknown>:0
at System.Diagnostics.TraceImpl.get_ListenersSyncRoot () [0x00000] in <filename unknown>:0
at System.Diagnostics.TraceImpl.WriteLine (System.String message, System.String category) [0x00000] in <filename unknown>:0
at System.Diagnostics.Trace.WriteLine (System.String message, System.String category) [0x00000] in <filename unknown>:0
at MP3Sharp.Decoding.Bitstream.isSyncMark (Int32 headerstring, Int32 syncmode, Int32 word) [0x00000] in <filename unknown>:0
at MP3Sharp.Decoding.Bitstream.syncHeader (SByte syncmode) [0x00000] in <filename unknown>:0
at MP3Sharp.Decoding.Header.read_header (MP3Sharp.Decoding.Bitstream stream, MP3Sharp.Decoding.Crc16[] crcp) [0x00000] in <filename unknown>:0
at MP3Sharp.Decoding.Bitstream.readNextFrame () [0x00000] in <filename unknown>:0
at MP3Sharp.Decoding.Bitstream.readFrame () [0x00000] in <filename unknown>:0
at MP3Sharp.MP3Stream.ReadFrame () [0x00000] in <filename unknown>:0
at MP3Sharp.MP3Stream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at System.IO.Stream.CopyTo (System.IO.Stream destination, Int32 bufferSize) [0x00000] in <filename unknown>:0
at System.IO.Stream.CopyTo (System.IO.Stream destination) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Stream:CopyTo (System.IO.Stream)
at Terraria.ModLoader.ModLoader.LoadMod (Terraria.ModLoader.IO.TmodFile modFile, Terraria.ModLoader.BuildProperties properties) [0x00000] in <filename unknown>:0
at Terraria.ModLoader.ModLoader.LoadMods () [0x00000] in <filename unknown>:0

Hope this helps!
I was unable to solve this issue. I have to use wine to play Terraria on Mac with Tremor Remastered mod. It is probably because of a log statement in the mod's source, but I'm obviously unable to confirm or solve that myself.

EDIT: I was wrong. The new Tremor Remastered 1.2.1 works with the Steam Terraria on Mac. I put the new tmod into the wrong folder previously.
 
Last edited:
Help how do i make an item spawn a boss... this is my code...
Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.Items
{
    public class DoomWhistle : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Doom Whistle";
            item.width = 60;
            item.height = 48;
            item.maxStack = 99;
            item.value = 100;
            item.rare = 10;
            item.useAnimation = 45;
            item.useTime = 45;
            item.useStyle = 4;
            item.useSound = 44;
            item.consumable = true;
        }
       
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(1006);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
       
                public override bool CanUseItem(Player player)
        {
            return !NPC.AnyNPCs(mod.NPCType("Angelic"));
        }
    }
}
 
Is your town NPC able to respawn? If not, some changes in your code may have killed him.
If so, that's weird, because mine is persistent.

Check if this works:
Code:
public override void AI()
{
    projectile.ai[0] += 1f;
    int num2 = 0;
    if (projectile.ai[0] >= 40f)
    {
        num2++;
    }
    if (projectile.ai[0] >= 80f)
    {
        num2++;
    }
    if (projectile.ai[0] >= 120f)
    {
        num2++;
    }
    int num3 = 24;
    int num4 = 6;
    projectile.ai[1] += 1f;
    bool flag = false;
    if (projectile.ai[1] >= (float)(num3 - num4 * num2))
    {
        projectile.ai[1] = 0f;
        flag = true;
    }
  
    Player player = Main.player[projectile.owner];
    float num1 = 1.570796f;
    Vector2 vector2_1 = player.RotatedRelativePoint(player.MountedCenter, true);
    if (flag && Main.myPlayer == projectile.owner)
    {
        if (player.channel && !player.noItems && !player.CCed)
        {
            int shoot, Damage; float speed, KnockBack; bool canShoot = false;
            player.PickAmmo(player.inventory[player.selectedItem], ref shoot, ref speed, ref canShoot, ref Damage, ref KnockBack);
            if(canShoot)
            {
                float num5 = player.inventory[player.selectedItem].shootSpeed * projectile.scale;
                Vector2 vector2_2 = vector2_1;
                Vector2 vector2_3 = Main.screenPosition + new Vector2((float) Main.mouseX, (float) Main.mouseY) - vector2_2;
                if ((double) player.gravDir == -1.0)
                vector2_3.Y = (float) (Main.screenHeight - Main.mouseY) + Main.screenPosition.Y - vector2_2.Y;
                Vector2 vector2_4 = Vector2.Normalize(vector2_3);
                if (float.IsNaN(vector2_4.X) || float.IsNaN(vector2_4.Y))
                vector2_4 = -Vector2.UnitY;
                vector2_4 *= num5;
                if ((double) vector2_4.X != (double) projectile.velocity.X || (double) vector2_4.Y != (double) projectile.velocity.Y)
                projectile.netUpdate = true;
                projectile.velocity = vector2_4;
                float num6 = 14f;
                int num7 = 7;
                for (int index = 0; index < 2; ++index)
                {
                    Vector2 vector2_5 = projectile.Center + new Vector2((float) Main.rand.Next(-num7, num7 + 1), (float) Main.rand.Next(-num7, num7 + 1));
                    Vector2 spinningpoint = Vector2.Normalize(projectile.velocity) * num6;
                    spinningpoint = Utils.RotatedBy(spinningpoint, Main.rand.NextDouble() * 0.196349546313286 - 0.0981747731566429, new Vector2());
                    if (float.IsNaN(spinningpoint.X) || float.IsNaN(spinningpoint.Y))
                    spinningpoint = -Vector2.UnitY;
                    Projectile.NewProjectile(vector2_5.X, vector2_5.Y, spinningpoint.X, spinningpoint.Y, mod.ProjectileType("PulseShot"), projectile.damage, projectile.knockBack, projectile.owner, 0.0f, 0.0f);
                }
            }
            else
            {
                projectile.Kill();
            }
        }
        else
        {
            projectile.Kill();
        }
    }
}
So this was the error I got
upload_2016-1-22_6-44-48.png

I then changed KnockBack to knockback and got this error
upload_2016-1-22_6-46-5.png
 
Can you make mods without Visual studio? I cant run it on my computer.
SharpDevelop is a good alternative. It's not as powerful and it will only let you code in C# or F# (meanwhile Visual Studio supports, like, 20 languages) but for a Terraria mod it's more than enough.

I use it because VS requires about 5 GB on your C:\ drive no matter where you install it. And my laptop's C:\ drive is only 20 GB so I can't afford that.
 
I don't know if I'm doing something wrong but no mods are showing up in the mod browser. I use a mac so that's probably the problem.
 
I don't know if I'm doing something wrong but no mods are showing up in the mod browser. I use a mac so that's probably the problem.
That is probably the cause yeah :p
[DOUBLEPOST=1453481386,1453481185][/DOUBLEPOST]I just want to put out here everyone, it is very much OKAY for you to type the error you get in GOOGLE and see which answers you get. There's literally no point in asking us the most basic questions of basic errors when you can know what's wrong when using Google, in about 1 minute or less.
 
Back
Top Bottom