tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Hello! Here I have again a question appeared. Is it possible to do interactive tile? For instance, when you click the right mouse button on it was applied buff? I will be glad if you help. :D
I assume you need to override this method in the ModTileType class:
Code:
public virtual bool RightClick(int x, int y)
I'm not completely sure what the return value is for though. Looking through the source code, I can't find any context for this method that I can make sense of, so you might have to experiment with this.

I want to make an NPC orbit (go in circles) around a player. How would I go about doing that?
A simple way would be to use the NPC's ai array. You would use one slot to keep track of the current angle, increment the angle each tick, and update the NPC's position using trigonometry. It would go something like this:
Code:
Player player = Main.player[npc.target];
float rotateSpeed = 0.01f; //change this
float distance = 10f; //change this
npc.ai[0] += rotateSpeed;
npc.ai[0] %= (float)Math.PI * 2f;
Vector2 offset = new Vector2((float)Math.Cos(npc.ai[0]), (float)Math.Sin(npc.ai[0]));
npc.position = player.position + distance * offset;


Anybody know how to get gores working in r14? I need some for one of my projectiles.
You simply add a .png image to the Gores folder in your mod, then you call this method:
Code:
public static int NewGore(Vector2 Position, Vector2 Velocity, string name, float Scale = 1f, int overrideType = -1)
Where name is the name of your image file.
 
You simply add a .png image to the Gores folder in your mod, then you call this method:
Code:
public static int NewGore(Vector2 Position, Vector2 Velocity, string name, float Scale = 1f, int overrideType = -1)
Where name is the name of your image file.

I tried using this code:
public static int NewGore(Vector2 Position, Vector2 Velocity, string JoshyEggGore, float Scale = 1f, int overrideType = -1)
{
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore1", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore2", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore3", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore4", 1f, -1);


}
And I got this error:
JoshyEgg.cs (27,78)
'Dinosauria.Projectiles.JoshyEgg.NewGore(Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Vector2, string, float, int)': not all code paths return a value
public static int NewGore(Vector2 Position, Vector2 Velocity, string JoshyEggGore, float Scale = 1f, int overrideType = -1)
^
Failed to build Dinosauria.
 
I tried using this code:
public static int NewGore(Vector2 Position, Vector2 Velocity, string JoshyEggGore, float Scale = 1f, int overrideType = -1)
{
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore1", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore2", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore3", 1f, -1);
Gore.NewGore(Position, Velocity, "Dinosauria:JoshyEggGore4", 1f, -1);


}
And I got this error:
JoshyEgg.cs (27,78)
'Dinosauria.Projectiles.JoshyEgg.NewGore(Microsoft.Xna.Framework.Vector2, Microsoft.Xna.Framework.Vector2, string, float, int)': not all code paths return a value
public static int NewGore(Vector2 Position, Vector2 Velocity, string JoshyEggGore, float Scale = 1f, int overrideType = -1)
^
Failed to build Dinosauria.
You're supposed to just use the NewGore part like this for projectiles (I have covered this in my projectile tutorial)...

Code:
Gore.NewGore(projectile.position, projectile.velocity, "ModInternalName:GoreImage", 1f, -1);
//Notes, you can make a new velocity vector using "new Vector(x, y)"
 
You're supposed to just use the NewGore part like this for projectiles (I have covered this in my projectile tutorial)...

Code:
Gore.NewGore(projectile.position, projectile.velocity, "ModInternalName:GoreImage", 1f, -1);
//Notes, you can make a new velocity vector using "new Vector(x, y)"
Are you sure that code is for 1.2.4 ? I tried it but the system couldn't find "projectile" anywhere
 
Are you sure that code is for 1.2.4 ? I tried it but the system couldn't find "projectile" anywhere
Did you put this code inside your projectile's CS file? Because putting "projectile.position" only works within projectile CS files... Here's an example of the Gore spawning from a projectile from my Projectile Tutorial...

Guide Ray [Yes it's a custom heat ray made out of Guides...]
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace MPT.Projectiles
{
    public class GuideRay : ModProjectile
    {
        public override void AI()
        {
            projectile.light = 0.9f;
            projectile.localAI[0] += 1f;
            if (projectile.localAI[0] > 3f)
            {
                projectile.alpha = 255;
                for (int thickness = 0; thickness < 1; thickness++)
                {
                    int DustID1 = MPTDust.CreateGuideDust(new Vector2(projectile.position.X, projectile.position.Y - projectile.height/4), projectile.width, projectile.height);
                }
            }
        }
        //When it collides on a tile, produces Guide Gore!
        public override bool OnTileCollide(ref Vector2 velocityChange)
        {
            if (projectile.velocity.X != velocityChange.X) 
            {
                projectile.velocity.X = -velocityChange.X; 
            }
            if (projectile.velocity.Y != velocityChange.Y) 
            { 
                projectile.velocity.Y = -velocityChange.Y; 
            }
            int rand = Main.rand.Next(4);
            if (rand == 0)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore1"], 1f);
            else if (rand == 1)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 2)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 3)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            else
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            Main.PlaySound(4, (int)projectile.position.X, (int)projectile.position.Y, 1);
            return false;
        }
        //When it hits things, spawn gore!
        public override void DealtNPC(NPC n, int hitDir, int dmgDealt, float knockback, bool crit)
        {
            int rand = Main.rand.Next(4);
            if (rand == 0)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore1"], 1f);
            else if (rand == 1)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 2)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 3)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            else
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            Main.PlaySound(4, (int)projectile.position.X, (int)projectile.position.Y, 1);
        }
        public override void DealtPlayer(Player p, int hitDir, int dmgDealt, bool crit)
        {
            int rand = Main.rand.Next(4);
            if (rand == 0)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore1"], 1f);
            else if (rand == 1)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 2)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 3)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            else
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            Main.PlaySound(4, (int)projectile.position.X, (int)projectile.position.Y, 1);
        }
        //When the projectile dies, spawn gore!
        public override void PostKill()
        {
            int rand = Main.rand.Next(4);
            if (rand == 0)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore1"], 1f);
            else if (rand == 1)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 2)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore2"], 1f);
            else if (rand == 3)
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            else
            Gore.NewGore(projectile.position, new Vector2(MathHelper.Lerp(-4f, 4f, (float)Main.rand.NextDouble()), -2), GoreDef.gores["MPT:GuideGore3"], 1f);
            Main.PlaySound(4, (int)projectile.position.X, (int)projectile.position.Y, 1);
        }
    }
}
 
  1. Is there a good way to animate the player character with their eyes closed?
  2. What is the most 'correct' way to draw a semi-transparent overlay (or maybe even a filter effect) on the game display itself?
 
  1. Is there a good way to animate the player character with their eyes closed?
  2. What is the most 'correct' way to draw a semi-transparent overlay (or maybe even a filter effect) on the game display itself?
For 2. Use a Semi-transparent picture. This can be achieved by using the eraser with a density of a lower value than 100% in any program that can use an alpha-channel layer (paint.net, GIMP, Photoshop. Most programs that aren't paint basically)
 
For 2. Use a Semi-transparent picture. This can be achieved by using the eraser with a density of a lower value than 100% in any program that can use an alpha-channel layer (paint.net, GIMP, Photoshop. Most programs that aren't paint basically)
"most programs that aren't paint basically" don't say just "paint" the technical term is MS-paint
 
so, a friend of mine has been waiting 6 months (._.) for tapi to work, and i tried to help him. i told him to do what fixed it for me (delete config.json) but that didnt work. any ideas? please?
 
What am I doing wrong
Cs. file for proj
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using TAPI;

namespace MaxsMod.Projectiles.CopperLanceProj
{
    /// <summary>
    /// The Copper Lance
    /// </summary>
    public sealed class CopperLanceProj : ModProjectile
    {
        /// <summary>
        ///
        /// </summary>
        public override void AI()
        {
            projectile.alpha = 0;

            for (int i = 0; i < Main.npc.Length; i++)
                if (Main.npc[i].type == NPCDef.byName["MaxsMod:CopperLanceProj"].type && Main.npc[i].position.X == projectile.position.X && Main.npc[i].position.Y == projectile.position.Y)
                {
                    projectile.position = Main.npc[i].position;
                    projectile.spriteDirection = Main.npc[i].spriteDirection;

                    if (!Main.npc[i].active)
                        projectile.active = false;
                }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="npc"></param>
        /// <param name="hitDir"></param>
        /// <param name="damage"></param>
        /// <param name="knockback"></param>
        /// <param name="crit"></param>
        /// <param name="critMult"></param>
        public override void DamageNPC(NPC npc, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
        {
            npc.AddBuff(80, 600, true);
        }
    }
}
Json file for proj
Code:
{
    "texture": "Projectiles/CopperLanceProj",
    "size": [20, 20],
    "aiStyle": -1,
    "timeLeft": 9999999,
    "friendly": true,
    "hostile": false,   
    "tileCollide": true,
    "penitrate": -1,
    "damage": 7,
    "melee": true,
    "ownerHitCheck": true
}
The spear projectile does not graphically appear, but everything else works fine. It does the correct amount of damage and everything, it just doesn't show up.
 
What am I doing wrong
Cs. file for proj
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using TAPI;

namespace MaxsMod.Projectiles.CopperLanceProj
{
    /// <summary>
    /// The Copper Lance
    /// </summary>
    public sealed class CopperLanceProj : ModProjectile
    {
        /// <summary>
        ///
        /// </summary>
        public override void AI()
        {
            projectile.alpha = 0;

            for (int i = 0; i < Main.npc.Length; i++)
                if (Main.npc[i].type == NPCDef.byName["MaxsMod:CopperLanceProj"].type && Main.npc[i].position.X == projectile.position.X && Main.npc[i].position.Y == projectile.position.Y)
                {
                    projectile.position = Main.npc[i].position;
                    projectile.spriteDirection = Main.npc[i].spriteDirection;

                    if (!Main.npc[i].active)
                        projectile.active = false;
                }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="npc"></param>
        /// <param name="hitDir"></param>
        /// <param name="damage"></param>
        /// <param name="knockback"></param>
        /// <param name="crit"></param>
        /// <param name="critMult"></param>
        public override void DamageNPC(NPC npc, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
        {
            npc.AddBuff(80, 600, true);
        }
    }
}
Json file for proj
Code:
{
    "texture": "Projectiles/CopperLanceProj",
    "size": [20, 20],
    "aiStyle": -1,
    "timeLeft": 9999999,
    "friendly": true,
    "hostile": false,  
    "tileCollide": true,
    "penitrate": -1,
    "damage": 7,
    "melee": true,
    "ownerHitCheck": true
}
The spear projectile does not graphically appear, but everything else works fine. It does the correct amount of damage and everything, it just doesn't show up.

You really don't need the "texture" code in the JSON file, as if you name your JSON and your Texture files the same, tAPI handles that I believe. "damage" doesn't really do anything inside the projectile JSON file, and you don't need to define it as melee, as it doesn't affect anything either. But looking through it, it looks like it should be working. Maybe I could be wrong and the AI you did for the spear is off. If nothing else is working, you should check the tutorial inside my sig, as it has code for a North Pole weapon under "North Pole Type Weapons".

Also what's with all those /'s? o-o
 
This is probably a newbish question, but how do I access non-tAPI characters after I download tAPI?
Okay, if you want to generate ores you'll first have to make your tile, and the sprite for it (I presume you have that). Now, make a .cs file that contains a class that extends ModWorld


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Terraria;
using TAPI;

namespace ModNameHere
{
    class MWorld : ModWorld  //MWorld can be pretty much anything
    {
        public override void WorldGenPostGen()
        {
            AddOres();
        }

Then, copy this code:

Code:
public void AddOres() {
    int LowX = 0;
    int HighX = Main.maxTilesX;
    int LowY = (int)Main.rockLayer;
    int HighY = (int)Main.hellLayer;

    int X = WorldGen.genRand.Next(LowX, HighX);
    int Y = WorldGen.genRand.Next(LowY, HighY);

     int OreMinimumSize = 4;
     int OreMaximumSize = 7;

     int OreMinimumStretch = 2;
     int OreMaximumStretch = 3;

     int OreSize = WorldGen.genRand.Next(OreMinimumSize, OreMaximumSize + 1);  
     int OreStretch = WorldGen.genRand.Next(OreMinimumStretch, OreMaximumStretch + 1);

     WorldGen.OreRunner(X, Y, (double)OreSize, OreStretch, TileDef.byName["internalName:OreName"]);
}
Hey, I know this is an old post, but where would my ore spawn if I did happen to put this code in?
 
Hey, I know this is an old post, but where would my ore spawn if I did happen to put this code in?

In the case of the code I've put there, it would spawn at any X, and at a Y between the rock layer and the hell layer. :p (if that's what you were asking)
 
In the case of the code I've put there, it would spawn at any X, and at a Y between the rock layer and the hell layer. :p (if that's what you were asking)
Strange. when I run the code you gave me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using TAPI;
namespace MageMod
{
class MWorld : ModWorld
{
public override void WorldGenPostGen()
{
AddOres();
}
public void AddOres() {
int LowX = 0;
int HighX = Main.maxTilesX;
int LowY = (int)Main.rockLayer;
int HighY = (int)Main.hellLayer;
int X = WorldGen.genRand.Next(LowX, HighX);
int Y = WorldGen.genRand.Next(LowY, HighY);
int OreMinimumSize = 4;
int OreMaximumSize = 7;
int OreMinimumStretch = 2;
int OreMaximumStretch = 3;
int OreSize = WorldGen.genRand.Next(OreMinimumSize, OreMaximumSize + 1);
int OreStretch = WorldGen.genRand.Next(OreMinimumStretch, OreMaximumStretch + 1);
WorldGen.OreRunner(X, Y, (double)OreSize, OreStretch, TileDef.byName["MageMod:Magicite"]);
}
into the mod bui;der, I get this error
Validating Jsons...
} expected
}
^
MWorld.cs (2,39)
} expected
}
^
Failed to build Mage+
 
Strange. when I run the code you gave me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using TAPI;
namespace MageMod
{
class MWorld : ModWorld
{
public override void WorldGenPostGen()
{
AddOres();
}
public void AddOres() {
int LowX = 0;
int HighX = Main.maxTilesX;
int LowY = (int)Main.rockLayer;
int HighY = (int)Main.hellLayer;
int X = WorldGen.genRand.Next(LowX, HighX);
int Y = WorldGen.genRand.Next(LowY, HighY);
int OreMinimumSize = 4;
int OreMaximumSize = 7;
int OreMinimumStretch = 2;
int OreMaximumStretch = 3;
int OreSize = WorldGen.genRand.Next(OreMinimumSize, OreMaximumSize + 1);
int OreStretch = WorldGen.genRand.Next(OreMinimumStretch, OreMaximumStretch + 1);
WorldGen.OreRunner(X, Y, (double)OreSize, OreStretch, TileDef.byName["MageMod:Magicite"]);
}
into the mod bui;der, I get this error
Validating Jsons...
} expected
}
^
MWorld.cs (2,39)
} expected
}
^
Failed to build Mage+
You need to add more curly braces at the end. Make sure you count how many curly braces you open up so that you can tell how many to close at the end. It also helps if you indent for any code inside curly braces.
 
Status
Not open for further replies.
Back
Top Bottom