Standalone [1.3] tModLoader - A Modding API

How do I make it to where an enemy only spawns on the beach during hardmode?

EDIT: I know how to do the hardmode part, but how do I make it spawn only on the beach?
 
Last edited:
Sorry if this has been asked or the answer is obvious but is it possible to decompile tmod files and if so how can I?

What I'm wanting to do is check out the code to find the exact spawn conditions for some modded mobs, plus maybe the drop rates for items
 
How do I make it to where an enemy only spawns on the beach during hardmode?

EDIT: I know how to do the hardmode part, but how do I make it spawn only on the beach?
https://github.com/bluemagic123/tModLoader/blob/master/ExampleMod/NPCs/Octopus.cs
You can see from this example the logic behind spawning on a beach. Basically, check for a sand tile, check the x coordinate that it is on the outer 250 tiles, make sure the y coordinate is above the rock layer.

Sorry if this has been asked or the answer is obvious but is it possible to decompile tmod files and if so how can I?

What I'm wanting to do is check out the code to find the exact spawn conditions for some modded mobs, plus maybe the drop rates for items
The first post details tModReader, the program to unpack mods. If the modder has decided not to allow unpacking the source code, I'm sure you can PM them and they will be happy to tell you....unless they don't want to.
[DOUBLEPOST=1453422982,1453422958][/DOUBLEPOST]
what situation for multiplayers?
Not working.
 
When I build my mod I get this error on line 50 of this code
upload_2016-1-21_19-46-22.png

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

namespace TEM.Projectiles
{
    public class VortexPulseShot : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Vortex Pulse Shot";
            projectile.width = 22;
            projectile.height = 22;
            projectile.aiStyle = 0;
            projectile.friendly = true;
            projectile.penetrate = -1;
            projectile.tileCollide = false;
            projectile.hide = true;
            projectile.ranged = true;
            projectile.ignoreWater = true;
        }
        public override void AI()
        {
            if (flag && Main.myPlayer == projectile.owner)
                {
                if (player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed)
                    {
                        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, "TEM:PulseShot", projectile.damage, projectile.knockBack, projectile.owner, 0.0f, 0.0f);
                        }
                    }
                    else
                    projectile.Kill();
                }
        }
    }
}
 
When I build my mod I get this error on line 50 of this code
View attachment 93418
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace TEM.Projectiles
{
    public class VortexPulseShot : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Vortex Pulse Shot";
            projectile.width = 22;
            projectile.height = 22;
            projectile.aiStyle = 0;
            projectile.friendly = true;
            projectile.penetrate = -1;
            projectile.tileCollide = false;
            projectile.hide = true;
            projectile.ranged = true;
            projectile.ignoreWater = true;
        }
        public override void AI()
        {
            if (flag && Main.myPlayer == projectile.owner)
                {
                if (player.channel && player.HasAmmo(player.inventory[player.selectedItem], true) && !player.noItems && !player.CCed)
                    {
                        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, "TEM:PulseShot", projectile.damage, projectile.knockBack, projectile.owner, 0.0f, 0.0f);
                        }
                    }
                    else
                    projectile.Kill();
                }
        }
    }
}
Yup, that's this line, right:
Code:
Projectile.NewProjectile(vector2_5.X, vector2_5.Y, spinningpoint.X, spinningpoint.Y, "TEM:PulseShot", projectile.damage, projectile.knockBack, projectile.owner, 0.0f, 0.0f);
It's the part that says
Code:
"TEM:PulseShot"
where it breaks. You'll probably want to put mod.ProjectileType("PulseShot") there instead ;)
 
Last edited:
Allright, on your ModItem, you'll want to set 'item.noUseGraphic = true;' so that the item spear graphic will not show, 'item.noMelee = true;' so that the animation of the player will not damage enemies (the projectile will take care of that). You also need to make sure that you give 'item.shootSpeed' a value (default spear would be: item.shootSpeed = 3.7f; ;) ).
Then... You know what, I'll make the spear easier on both of us (although maybe a little more confusing, beware :p ).
In the spoiler is AI code for your spear. As you can see, there are two values at the top: retract- and protract speed. 'protractSpeed' will determine the speed at which the spear shoots out, whereas retractSpeed determines how quick the spear is pulled back after it reached its dead point.
You can copy the function right beneath your SetDefaults function. I hope it works!

Code:
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;
}
Now I got really puzzled, use 2 gifs to show the problem:
x.gif

x2.gif
 
Back
Top Bottom