Standalone [1.3] tModLoader - A Modding API

Code:
public override bool PreShoot(Player player, Vector2 position, Vector2 velocity, int projType, int damage, float knockback)
        {
            /*Grox's Code*/
            usePos = Main.mouseWorld - player.position;
            UseStyle(player);
            position.X = Main.mouseWorld.X; //Makes the position equal to your mouse
            position.X += MathHelper.Lerp(-120f, 120f, (float)Main.rand.NextDouble()); //Allows you have the projectile spawn at random in the x direction
            position.Y -= 500; //Make the projectile spawn 500 pixels above you (About 32 tiles)
            velocity.Y = (float)(item.shootSpeed); //Makes it fall down
            velocity.X = 0; //Makes it not stray from direct path to ground
            /*End of Grox's Code*/
C:\Program Files (x86)\Steam\steamapps\common\terraria

See how octopus does it. Basically check above rocklayer, and make sure x position is in outer 250 tiles.
https://github.com/bluemagic123/tModLoader/blob/master/ExampleMod/NPCs/Octopus.cs#L112

You just change the position and speed in shoot to spawn above the player and point at Main.MouseWorld. Then you can use PreKill or OnTileCollide to call Projectile.NewProjectile to spawn other projectiles.
So something like this?
 
I tried using it in tmodloader
Looks right. The method isn't preshoot though.

NPC.wet I think.
upload_2016-1-25_19-39-1.png

My code
Code:
        public override bool Shoot(Player player, Vector2 position, Vector2 velocity, int projType, int damage, float knockback)
        {
            usePos = Main.mouseWorld - player.position;
            UseStyle(player);
            position.X = Main.mouseWorld.X;
            position.X += MathHelper.Lerp(-120f, 120f, (float)Main.rand.NextDouble());
            position.Y -= 500;
            velocity.Y = (float)(item.shootSpeed);
            velocity.X = 0;
        }
 
I tried using it in tmodloader

View attachment 94090
My code
Code:
        public override bool Shoot(Player player, Vector2 position, Vector2 velocity, int projType, int damage, float knockback)
        {
            usePos = Main.mouseWorld - player.position;
            UseStyle(player);
            position.X = Main.mouseWorld.X;
            position.X += MathHelper.Lerp(-120f, 120f, (float)Main.rand.NextDouble());
            position.Y -= 500;
            velocity.Y = (float)(item.shootSpeed);
            velocity.X = 0;
        }
Don't just make up the methods, just look it up in the documentation. https://github.com/bluemagic123/tModLoader/wiki/ModItem

Making a new AI is hard. Start by utilizing existing AI and when you learn more about programming AI you can make your own.
Right now, my NPCs only spawn if the main blocks and walls are WOOD. How do I make it to where they can spawn in a house made out of any block (excluding dirt and other blocks like that)?
Well, what code did you put in to make it do that behavior?
 
I can help you by showing how I've done it. Take a look at the following code:
Code:
pubic override bool PreAI()
{
    if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3)
    {
        projectile.tileCollide = false;
        projectile.ai[1] = 0f;
        projectile.alpha = 255;

        projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
        projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
        projectile.width = 80; // This is the actual damaging size of this projectile.
        projectile.height = 80;
        projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
        projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);
        projectile.knockBack = 8f;
        return false;
    }

    return true;
}

public override bool OnTileCollide(Vector2 oldVelocity)
{
    projectile.velocity *= 0f;
    projectile.alpha = 255;
    projectile.timeLeft = 3;

    return false;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
    projectile.velocity *= 0f;
    projectile.alpha = 255;
    projectile.timeLeft = 3;
}

public override void Kill(int timeLeft)
{
    if (!projectile.active)
    {
        return;
    }
   
    Main.projectileIdentity[projectile.owner, projectile.identity] = -1;
    int num = projectile.timeLeft;
    projectile.timeLeft = 0;

    Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14);

    projectile.position.X = projectile.position.X + (float)(projectile.width / 2);
    projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2);
    projectile.width = 22;
    projectile.height = 22;
    projectile.position.X = projectile.position.X - (float)(projectile.width / 2);
    projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2);

    for (int num459 = 0; num459 < 7; num459++)
    {
        Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f);
    }
    for (int num460 = 0; num460 < 3; num460++)
    {
        int num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f);
        Main.dust[num461].noGravity = true;
        Main.dust[num461].velocity *= 3f;
        num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f);
        Main.dust[num461].velocity *= 2f;
    }
    int num462 = Gore.NewGore(new Vector2(projectile.position.X - 10f, projectile.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
    Main.gore[num462].velocity *= 0.3f;
    Main.gore[num462].velocity.X += (float)Main.rand.Next(-10, 11) * 0.05f;
    Main.gore[num462].velocity.Y += (float)Main.rand.Next(-10, 11) * 0.05f;

    projectile.active = false;
}

Why this works is because there is a cooldown on how often projectiles can hit NPCs.
If this still doesn't work for you, let me know ;)
Works, but still small issues(including that left "l" of "public"!).
It does area damage, but wherever it hits, it can once hit once. Even if it obviously touched several mobs, it will only hit one of them. Why is this?
 
Don't just make up the methods, just look it up in the documentation. https://github.com/bluemagic123/tModLoader/wiki/ModItem


Making a new AI is hard. Start by utilizing existing AI and when you learn more about programming AI you can make your own.

Well, what code did you put in to make it do that behavior?
public override bool CheckConditions(int left, int right, int top, int bottom)
{
int score = 0;
for (int x = left; x <= right; x++)
{
for (int y = top; y <= bottom; y++)
{
int type = Main.tile[x, y].type;
if (type == TileID.WoodBlock || type == TileID.Chairs || type == TileID.WorkBenches || type == TileID.ClosedDoor || type == TileID.OpenDoor)
{
score++;
}
if (Main.tile[x, y].wall == WallID.Wood)
{
score++;
}
}
}
return score >= (right - left) * (bottom - top) / 2;
}
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;

namespace Enderuim.Projectiles
{
    public class Icicle : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.name = "Icicle";
            projectile.damage = 70;
            projectile.width = 60;
            projectile.height = 16;
            projectile.hostile = false;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.penetrate = 10;
            projectile.tileCollide = true;
            projectile.alpha = 100;
            projectile.aiStyle = 51;
            projectile.knockBack = 40;
            projectile.light = 0.5f;
            aiType = 51;
           
        }
    }
}
Help My code is supposed to summon a projectile that homes in on monsters (51 is the same ID of lost soul) but it just doesnt work. But when I change AiStyle to 1 it works, but doesnt home. pls help
 
Can you help me with a few things... I need the method and code... since im dumb and cant figure it out...

  1. How do I make a boss go through blocks, and face the player (like eoc) but not summon eyes, do the charge and wait thing, or the half health boost?
  2. How do I animate a spritesheet that has 200x200 pixel sections (4 total) for 20 FPS
 
I have a question for sprite sheets. If you are making your own sprite sheet, what are the limits or rules, like how far apart each have to be?
 
Back
Top Bottom