tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Code:
if ((!Main.dayTime &&  Main.bloodMoon && Main.rand.Next(20) == 0) ||
                (!Main.dayTime &&  Main.bloodMoon && Main.rand.Next(10) == 0))
            {
                return true;
            }
            return false;
like this?
Kind of, I think you meant NOT a bloodmoon on the first one though more like this:
Code:
            if ((!Main.dayTime &&  !Main.bloodMoon && Main.rand.Next(20) == 0) ||
                (!Main.dayTime &&  Main.bloodMoon && Main.rand.Next(10) == 0))
            {
                return true;
            }
            return false;
That would make it a 5% chance at night when it's not a blood moon, and a 10% chance at night when it is a blood moon.
 
Well the best part is it spawns at night now... but I still notice it spawns in places like Hell (kinda obvious since spawn level isn't stated in the code) But I feel like if I want it to spawn above "level" or 0 it goes like
Code:
if (y >= (Main.maxTilesY * 0.3f))
This is just editing the code of SonicR so it's all guesswork.
 
Well the best part is it spawns at night now... but I still notice it spawns in places like Hell (kinda obvious since spawn level isn't stated in the code) But I feel like if I want it to spawn above "level" or 0 it goes like
Code:
if (y >= (Main.maxTilesY * 0.3f))
This is just editing the code of SonicR so it's all guesswork.
Forgot that part of your question, derp, here you go :p
Code:
            if (y <= Main.worldSurface &&
                ((!Main.dayTime &&  !Main.bloodMoon && Main.rand.Next(20) == 0) ||
                 (!Main.dayTime &&  Main.bloodMoon && Main.rand.Next(10) == 0)) )
            {
                return true;
            }
            return false;
Remember for y values, 0 is the sky and Main.maxTilesY is the bottom of the world, so you want less than, not greater than.

EDIT:

With this i tried to make a mod for a bow and arrow, but it wont work, i think the bow works, but i can't craft the arrows i made, heres the code for the material, bow, and the arrow.
https://www.dropbox.com/sh/72wb1fofxbaceyp/AAD0BCOqLWU3eyVZJ1V4joE_a?dl=0

https://www.dropbox.com/sh/72wb1fofxbaceyp/AAD0BCOqLWU3eyVZJ1V4joE_a?dl=0
Codes for my bow and arrow. I don't know if my other message posted, but here, i made a bow and arrow using tapi for my dragon scale mod. Oh, code for the bar too, dirt is recipe for testing. But the bow might work, but i can't craft the arrows. Why is this? Thats what im wondering.
That arrow is just a projectile, you need to make an item version of it, look in the template mod for examples. The recipe has to be on the item, not the projectile.
 
Last edited:
Worked things out.

OP:
I can't seem to be able to get functions to work at all. When I use the Chains weapon, it shoots the projectile, but it doesn't rotate, accelerate, emit dust, or play sounds on tile collision.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace Assortica.Projectiles
{
public class ChainsProjectile : ModProjectile
{
public override void AI()
{
projectile.rotation = (float)System.Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
projectile.velocity.X *= 2.0f;
projectile.velocity.Y *= 2.0f;
if(projectile.timeLeft % 2 == 0 && Main.netMode != 2)
{
Color color = new Color();
color.R = 100;
color.G = 100;
color.B = 100;
int dustID = Dust.NewDust(projectile.position, projectile.width, projectile.height, 60, projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 100, color, 1.6f);
}
}

public override bool OnTileCollide(ref Vector2 velocityChange)
{
if (Main.netMode != 2){ Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1); }
if (projectile.velocity.X != velocityChange.X) { projectile.velocity.X = -velocityChange.X; }
if (projectile.velocity.Y != velocityChange.Y) { projectile.velocity.Y = -velocityChange.Y; }
return false;
}

public override void PostKill()
{
if(Main.netMode != 2)
{
Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y, 1);
for (int m = 0; m < 10; m++) //projectile dust
{
Color color = new Color();
color.R = 100;
color.G = 100;
color.B = 100;
int dustID = Dust.NewDust(projectile.position, projectile.width, projectile.height, 60, 0, 0, 100, color, 3.2f);
Main.dust[dustID].velocity = new Vector2(Main.rand.Next(-10, 10) * 0.5f, Main.rand.Next(-10, 10) * 0.5f);
Main.dust[dustID].noGravity = true;
}
}
}

public static Vector2 RotateVector(Vector2 origin, Vector2 vecToRot, float rot)
{
float newPosX = (float)(Math.Cos(rot) * (vecToRot.X - origin.X) - Math.Sin(rot) * (vecToRot.Y - origin.Y) + origin.X);
float newPosY = (float)(Math.Sin(rot) * (vecToRot.X - origin.X) + Math.Cos(rot) * (vecToRot.Y - origin.Y) + origin.Y);
return new Vector2(newPosX, newPosY);
}

public override void DamageNPC(NPC npc, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
{
npc.AddBuff(32,300,false);
}
}
}

EDIT: looking into it, the TemplateMod's ExampleProjMagic doesn't work either.
 
Last edited:
I guess NPC's aren't my cup of tea. That's too bad, I love making them :(
My Lava Mite has two issues:
1. It doesn't let any other enemies spawn in the Underworld.
2. It isn't hostile at daytime.
Here is a JSON and CS sample:
Code:
{
    "displayName": "Lava Mite",
    "size": [50,30],
    "value": [0,0,2,0],
    "npcSlots": 2,
    "aiStyle": 3,
    "animationType": 236,
    "lifeMax": 50,
    "damage": 72,
    "defense": 8,
    "frameCount": 3,
    "soundHit": 1,
    "soundKilled": 1,
    "knockbackResist": 0.4,
    "lavaImmune": true,
   
    "drops":
    [
        {
            "item": "berberborscing:Lifesaver",
            "chance": 0.10,
            "stack": 5
        }
    ]
}
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace berberborscing.NPCs
{
    public class Lavamite : ModNPC
    {
        public override bool CanSpawn( int x, int y, int type, Player spawnedOn)
        {   
            if (y >= (Main.hellLayer))
            {
                return true;
            }
            return false;
        }
    }
}
 
Hey, I want to make a custom summon item to summon Skeletron Prime that costs 1 dirt, or at least edit the vanilla recipe, anyone know the code? I'm almost thinking about giving up with the code, anyone have the code? Cuz i need this skele prime summoner for testing purposes, like code for the cs and json, I have the texture. Actually, I just need a .cs, like the actual summon code.
 
Hey, I want to make a custom summon item to summon Skeletron Prime that costs 1 dirt, or at least edit the vanilla recipe, anyone know the code? I'm almost thinking about giving up with the code, anyone have the code? Cuz i need this skele prime summoner for testing purposes, like code for the cs and json, I have the texture. Actually, I just need a .cs, like the actual summon code.
You should just get Shockah's Fancy Cheat Menu, and spawn him from the NPC menu
 
I guess NPC's aren't my cup of tea. That's too bad, I love making them :(
My Lava Mite has two issues:
1. It doesn't let any other enemies spawn in the Underworld.
2. It isn't hostile at daytime.
Here is a JSON and CS sample:
Code:
{
    "displayName": "Lava Mite",
    "size": [50,30],
    "value": [0,0,2,0],
    "npcSlots": 2,
    "aiStyle": 3,
    "animationType": 236,
    "lifeMax": 50,
    "damage": 72,
    "defense": 8,
    "frameCount": 3,
    "soundHit": 1,
    "soundKilled": 1,
    "knockbackResist": 0.4,
    "lavaImmune": true,
  
    "drops":
    [
        {
            "item": "berberborscing:Lifesaver",
            "chance": 0.10,
            "stack": 5
        }
    ]
}
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace berberborscing.NPCs
{
    public class Lavamite : ModNPC
    {
        public override bool CanSpawn( int x, int y, int type, Player spawnedOn)
        {  
            if (y >= (Main.hellLayer))
            {
                return true;
            }
            return false;
        }
    }
}
That's because your NPC has a 100% spawn chance. Add a random chance, so that it's 10% or something instead.

Hey, I want to make a custom summon item to summon Skeletron Prime that costs 1 dirt, or at least edit the vanilla recipe, anyone know the code? I'm almost thinking about giving up with the code, anyone have the code? Cuz i need this skele prime summoner for testing purposes, like code for the cs and json, I have the texture. Actually, I just need a .cs, like the actual summon code.
You should just get Shockah's Fancy Cheat Menu, and spawn him from the NPC menu
Or, you can use the dev console. Admittedly, its not really documented well anywhere, but it does exist!

1) Go to the Mods menu.
2) Hit Escape.
3) A button should show up in the bottom left, that lets you configure what button to use.
4) Enter the game.
5) Press the button, and a text bar will appear at the bottom of the screen.
6) Enter the following:
Code:
NPC.SpawnOnPlayer(Main.myPlayer, 35);
7) Press Enter. Tah Dah! Skeletron.

Basically, it compiles the code you enter, and runs it. It can't use mod code (no "MBase.blah") but you can give yourself items if you wanted with it too for testing. It has a single special definition, which is "P", which is the same as Main.localPlayer, so you could do:
Code:
P.heldItem.SetDefaults("Excalibur");
And your current hotbar slot will turn into a free Excalibur, yaaay :dryadtongue: This is how I test things in my mods, and test tAPI itself. Oh and, it works with clipboard, so feel free to copy/paste. (For some reason it seems to be pasting twice for me though :dryadconfused: )
 
What is wrong with my code?
Code:
using System;
using System.Collections.Generic;
using System.Text;

using Terraria;
using TAPI;

namespace Tremor.Buffs
{
    public class BloodMoonBuff : TAPI.ModBuff
    {

        public override void Effects(Player player, int index)
        {
            player.enemySpawns = true;
            Main.bloodMoon = true;
        }
    }
}
 
What is wrong with my code?
Code:
using System;
using System.Collections.Generic;
using System.Text;

using Terraria;
using TAPI;

namespace Tremor.Buffs
{
    public class BloodMoonBuff : TAPI.ModBuff
    {

        public override void Effects(Player player, int index)
        {
            player.enemySpawns = true;
            Main.bloodMoon = true;
        }
    }
}

I believe TAPI.ModBuff should just be ModBuff.
 
What is wrong with my code?
Code:
using System;
using System.Collections.Generic;
using System.Text;

using Terraria;
using TAPI;

namespace Tremor.Buffs
{
    public class BloodMoonBuff : TAPI.ModBuff
    {

        public override void Effects(Player player, int index)
        {
            player.enemySpawns = true;
            Main.bloodMoon = true;
        }
    }
}
Whats the problem, it's just not working? Is the buff's json file named "BloodMoonBuff.json", exact capitalization and everything? it must match the class name.

I believe TAPI.ModBuff should just be ModBuff.
That shouldn't ever cause a problem, if anything, it can help avoid some problems (for people like me who name my global classes the same as tAPI's :dryadtongue:
 
What is wrong with my code?
...
[With straight face] Curly brace on new line.

Probably as MiraiMai suggested, misspelling of class name or namespace name. Also name of file should also match class name, though it is not C# requirement, but it is convenient. MiraiMai, correct me if i understand correctly, to be included in mod assembly code files should be processed by mod builder, and it includes only files that referenced from jsons, isn't it?
 
[With straight face] Curly brace on new line.

Probably as MiraiMai suggested, misspelling of class name or namespace name. Also name of file should also match class name, though it is not C# requirement, but it is convenient. MiraiMai, correct me if i understand correctly, to be included in mod assembly code files should be processed by mod builder, and it includes only files that referenced from jsons, isn't it?
Agreed on the first point, yaaay agreed opinions on coding style! XD

And nope, that's part of why I dislike and avoid using the "code" property in json files. ALL cs files no matter where or what they're named, are compiled and included, whether you use them or not. By default, without the "code" property, tAPI looks for a class in the namespace "[internalname].[category]" named "[filename]".

So for his code, the internalName in ModInfo has to be "Tremor", and the json file in the "Buffs" folder must be named "BloodMoonBuff.json" in order to be found by tAPI, assuming he's not using "code", which I honestly discourage the use of anyways.

But ya, you could make a, for instance, "GeneralAI.cs" class that isnt directly linked to anything, but full of utility functions for AI, that will still be compiled and put in the game for you to use. This is basically what Grox did with his BaseMod, its fully of generic code for him to reuse, which makes him adding content much easier :p
 
Status
Not open for further replies.
Back
Top Bottom