Standalone [1.3] tModLoader - A Modding API

less of a problem now :)

all it does now is go out a small distance and the stops and then homes when there is something to home on.
but it still is stopping when there is nothing to home on.

Code:
public NPC FindNearest(Vector2 pos)
        {
        
            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length - 1; i++)
            {
                if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
                    continue;
                if (!Terraria.Main.npc[i].CanBeChasedBy(projectile))
                    continue;
                if (nearest == null)
                    nearest = Terraria.Main.npc[i];
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);
                    newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);
                    if (newDist < oldDist)
                        nearest = Terraria.Main.npc[i];
                }
            }
            return nearest;
        }
        int maxSpeed = 10;
        public override void AI()
        {
            NPC nearest = this.FindNearest(projectile.Center);
            Vector2 acceleration;
            if (nearest != null) // extremely important
            {
                acceleration = (nearest.position - projectile.position);
            } else
            {
                acceleration = Vector2.Zero; // maintain speed -- or whatever else you want to do here
            }
            projectile.velocity += acceleration * 1.5f;
            projectile.velocity *= 0.95f;
            if (projectile.velocity.Length() > maxSpeed)
            {
                projectile.velocity.Normalize();
                projectile.velocity *= maxSpeed;
            }
            projectile.rotation = projectile.velocity.ToRotation();
        }

also, since this homing is almost complete, how might I make an arkhalis type weapon. I have tried, but the projectile for the blade doesn't even show up!

Weapon Code defaults:
Code:
 public override void SetDefaults()
        {
            item.name = "Solarius";
            item.damage = 75;
            item.melee = true;
            item.width = 48;
            item.height = 48;
            item.useTime = 1;
            item.useAnimation = 1;
            item.useStyle = 1;
            item.noMelee = true;
            item.knockBack = 2;
            item.noUseGraphic = true;
            item.channel = true;
            item.value = 100000;
            item.rare = 9;
            item.useSound = 1;
            item.autoReuse = true;
            item.shoot = mod.ProjectileType("SolarisP");
            item.shootSpeed = 20;
        }

Projectile Code defaults:
Code:
public class SolarisP : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Solarius";
            projectile.width = 36;
            projectile.height = 20;
            projectile.friendly = true;
            projectile.penetrate = -1;
            projectile.aiStyle = 20;
            projectile.melee = true;
            projectile.tileCollide = false;
            projectile.light = 2f;
        }
the class is shown so you know why the weapon is refering to that name for the projectile.
pls help me
I am so lost :(
To fix the slow-to-a-stop problem, move the line 'projectile.velocity *= 0.95f;' inside the 'if (nearest != null)' condition, or get rid of it entirely if you don't want any drag. That's all that line did.

As for the arkhalis type weapon, the vanilla projectile has the type of 595 and uses the ai style of 75, so you'll need to set projectile.type and .aiStyle to those two numbers. Also, it would be a good idea for you to try decompiling tModLoader's source so that you can have a look at vanilla code for yourself. ILSpy and DotPeek are two good decompilers.
 
I'd like to say that after my pc updated, windows defender identifies the Terraria.exe file from this is a trojan, I'm aware this is not the case but you may want to look into checking nothing has been infected and for users of this to got to the antivirus view details of quarantined items and allow it (you can check its the terraria file by reading details of the trojan)
 
Last edited:
I have a problem with this code:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ZeldaMod.Items.Weapons
{
    public class HerosBow : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Hero's Bow";
            item.damage = 20;
            item.ranged = true;
            item.noMelee = true;
            item.width = 14;
            item.height = 42;
            item.toolTip = "The tresaure of Gorons.";
            item.useTime = 27;
            item.useAnimation = 27;
            item.useStyle = 5;
            item.knockBack = 2;
            item.value = 10000;
            item.rare = 2;
            item.shoot = mod.ProjectileType("LightArrow");
            item.useAmmo = 1;
            item.useSound = 1;
            item.shootSpeed = 9;
            item.autoReuse = true;
        }
      
        public override bool AltFunctionUse(Player player) //Enable right click
        {
            return true;
        }
        public override bool UseItem(Player player)
        {
            return base.UseItem(player);
        }

        public override bool CanUseItem(Player player)
        {
            return true;
        }

        public override bool ConsumeAmmo(Player player) //So that when right clicking it change the projectile but doesn't shoot anything
        {
            if (player.altFunctionUse == 2)
                return false;
            else
                return true;
        }

        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            ZMPlayer mp = player.GetModPlayer<ZMPlayer>(mod);
            if (player.altFunctionUse == 2) // if right click sswitch projectile that will be shooted
            {
                if (mp.switchArrow == 3) //Variable in ZMPlayer (ModPlayer)
                    mp.switchArrow = 0;
                else
                    mp.switchArrow++;
                return false;
            }

            if (mp.switchArrow == 0) // If there is no special projectile type, we just want to shoot the bow.
                return true;

            // If there is, however, we want to set the projectile type we want to shoot to the specialProjetileType of the player.

            if (mp.switchArrow == 3)
            {
                if (player.statMana >= 50)
                {
                    player.statMana -= 50;
                    type = mod.ProjectileType("LightArrow");
                    damage = 150;
                }
                else
                {
                    type = ProjectileID.WoodenArrowFriendly;
                    damage = 20;
                }
            }
            else if (mp.switchArrow == 1)
            {
                if (player.statMana >= 25)
                {
                    player.statMana -= 25;
                    type = ProjectileID.FireArrow;
                    damage = 50;
                }
                else
                {
                    type = ProjectileID.WoodenArrowFriendly;
                    damage = 20;
                }
            }
            else if (mp.switchArrow == 2)
                if (player.statMana >= 25)
                {
                    player.statMana -= 25;
                    type = ProjectileID.FrostburnArrow;
                    damage = 40;
                }
                else
                {
                    type = ProjectileID.WoodenArrowFriendly;
                }
          
            return true;
        }

      
    }
}
The right click function works, but only after the world is "updated". For example after loading the world it doesn't work but then I place a block and it starts to work.
 
To fix the slow-to-a-stop problem, move the line 'projectile.velocity *= 0.95f;' inside the 'if (nearest != null)' condition, or get rid of it entirely if you don't want any drag. That's all that line did.

As for the arkhalis type weapon, the vanilla projectile has the type of 595 and uses the ai style of 75, so you'll need to set projectile.type and .aiStyle to those two numbers. Also, it would be a good idea for you to try decompiling tModLoader's source so that you can have a look at vanilla code for yourself. ILSpy and DotPeek are two good decompilers.

Firstly, and most importantly, I Thank You LOADS for the help with the homing projectile doing the entirety of the homing projectile for me. It FINALLY works in a satisfactory manor :)

secondly,
ARKHALIS
I've set the type and ai to 595 and 75 respectively, but it still won't appear :( is there something in my code making it invisible, or is there something I still need to do to make it appear properly

also, I'd rather not look into the vanilla code unless it's really REALLY necessary. aka nobody anywhere on this forum knows how to do such and such thing and there are no tutorials, which would be a tragedy indeed.

also, sorry if I annoy you with my constant questions. That would not happen to be one of my goals when asking them

also, are there any tutorials on basic custom boss ai stuff that you know of? I'd like to check out things of that sort before I ask on here

also, I say 'also' too much
 
Hi I'm new here and i just tried to download the tmod loader only my virusscan began to shout that there was a virus in the zip file i clicked it away but i really want this mod so did i do something wrong or is the virusscanner oversensitive? i hope you can help me?
you have a few errors
your virusscan is a bad one, i got mine virus free, as there is no virus, its just the .jar that the computer doesnt like, get something different, ok?
there is no virus in there, ok? just turn off or get a different anti-virus, then download again, make sure its an actuall popular one that isnt in the corners of the web.

I had the tmodloader downloaded a few days ago and my computer didn't scan any virus , but when I started up Terraria today, my computer scanned there is Trojan virus in the Terraria.exe.bak file. Also my virusscan is Windows Defender so I think it shouldn't be wrong. Pls help.[/QUOTE]
 
I had the tmodloader downloaded a few days ago and my computer didn't scan any virus , but when I started up Terraria today, my computer scanned there is Trojan virus in the Terraria.exe.bak file. Also my virusscan is Windows Defender so I think it shouldn't be wrong. Pls help.
[/QUOTE]
I get something like that, except its constantly pinging at me for it and apparently Windows Defender wont shut up, and i cant even get it to DOWNLOAD.
 
I had the tmodloader downloaded a few days ago and my computer didn't scan any virus , but when I started up Terraria today, my computer scanned there is Trojan virus in the Terraria.exe.bak file. Also my virusscan is Windows Defender so I think it shouldn't be wrong. Pls help.
I get something like that, except its constantly pinging at me for it and apparently Windows Defender wont shut up, and i cant even get it to DOWNLOAD.
Anytime I download this from the media fire link given for windows I get a trojan virus disabling me to use tmodloader.
I'm starting to become convinced that Windows Defender is pretty terrible. Unfortunately, the best thing I can recommend is to get another antivirus first, then disable Windows Defender.
 
if you could , could you look for a site other than mediafire to link to the upload the example mod? If so, then thank you, as mediafire is untrustworthy, and the ads are full of malware
 
I have a couple of questions about npc ai, projectile ai, and other stuff for my custom boss. I be soo lost

- how do I make the npc texture change to something else kinda like the EoC changes to have a mouth.

- how do I make the npc shoot a projectile from the edge of the texture and not the center to where it's facing, not necessarily at the player EDIT: sorta like the way either one of the twins shoots, my shots usually come out in weird angles from the texture center to where the player is when it is shot.

- how do I make the npc stay stationary and spin
- also how might I make the npc invincible and regen while it is spinning

- how do I make the npc hover above the player like the nimbus, only stay in that position relative to the player no matter how fast they move

- how do I draw a giant rectangle, sort of like the circle around the abomination in that it is shaded, with the player's position, when it is first drawn, as the center when the boss is first summoned, and stay put until the boss is defeated or leaves, which it will do if the player dies
- also how might I move the npc to the center of the rectangle
- also how might I make the npc charge super fast at the payer and deal 1,000,000,000,000 damage or what ever the max damage in terraria is and be invincible if the player leaver the inside of the rectangle (I know it's OP, buuut... the summon item will warn you not to leave...)

- how might I make a bouncing projectile, that bounces like the meteorite bullet, but with no limit
- also how could I make this projectile bounce of the side of the rectangle, but only if it hits them from the inside (or is this even possible)
- also how could I make this projectile shoot motionless projectile every single tick to stay along the path it took and damage the player

- how might I make the npc damage and defence increase the more damaged it is

- how might I make the npc shoot a beam like the moon lord's death ray thing

-how do I make the npc face the player and then charge like the expert EoC

EDIT: 'a couple questions' is a huge understatement. I just noticed that

pls help me
 
Last edited:
Hi im having some trouble with the cursor in tmod, it is slower and acts a bit after i moved the mouse. Someone knows what to do?
 
Back
Top Bottom