tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
Why it won't work?
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace Tremor.NPCs
{
    public class Dominator : ModNPC
    {
      public override void HitEffect(int hitDirection, double damage, bool isDead)
        {
            if (isDead)
            {
            NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, "Tremor:DominatorSlug", 0);
            }
}
}
}
 
Why it won't work?
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

using TAPI;
using Terraria;

namespace Tremor.NPCs
{
    public by Browser Warden" style="border: none !important; display: inline-block !important; text-indent: 0px !important; float: none !important; font-weight: bold !important; height: auto !important; margin: 0px !important; min-height: 0px !important; min-width: 0px !important; padding: 0px !important; text-transform: uppercase !important; text-decoration: underline !important; vertical-align: baseline !important; width: auto !important; background: transparent !important;">class[U][B][IMG]http://browserwarden-a.akamaihd.net/items/it/img/arrow-10x10.png[/IMG][/B][/U] Dominator : ModNPC
    {
      public override void HitEffect(int hitDirection, double damage, bool isDead)
        {
            if (isDead)
            {
            NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, "Tremor:DominatorSlug", 0);
            }
}
}
}
Did you set the ai to -1 in the .json file?
 
In dominator or in slug file?
Set ai to -1 in dominator file: nothing happened.
Yes the dominator. Hmm. Did you change the "code" tag in the .json file? are the .cs and .json files named the same(this only applies if the first question is false)?
 
So I'm trying to create a tile to use as crafting station, the tile itself works like it should, and the item I want to craft with it shows up when getting close, but it doesn't disappear when I walk away from it, it stays enabled over the whole world, and I can craft it where I want. When I restart the world it's gone again, but when I get close to the tile again, it happens all over again... Tried it with another item, same result. Could anybody help me?

Code:
{
    "displayName": "Infusing Station",
    "size": [16,16],
    "maxStack": 999,
    "value": [0,0,2,60],
    "rare": 9,
    "useStyle": 1,
    "useAnimation": 15,
    "useTime": 10,
    "autoReuse": true,
    "useTurn": true,
    "tooltip": ["Used for advanced crafting", "'A machine cappable of infusing various materials with light'"],
    "createTile": "Domen:InfusingStation",
    "consumable": true
}
Code:
{
    "displayName": "Infusing Station",
    "size": [3,3],
    "frameWidth": 16,
    "frameHeight": 16,
    "frameImportant": true,
    "frame": 1,
    "frameMax": 10,
    "frameCounter": 1,
    "frameCounterMax": 10,
    "directional": false,
    "solid": false,
    "blocksLight": false,
    "blocksSun": false,
    "mergeDirt": false,
    "placementConditions": "flatGround",
    "placementOrigin": [1,1],
    "drop": "Domen:InfusingStationItem",
    "breaksByPick": true,
    "dust": 61,
    "sound": 1,
    "soundGroup": 21
}
Code:
{
    "displayName": "Infused Copper bar",
    "size": [16,16],
    "maxStack": 999,
    "value": [0,0,2,50],
    "rare": 9,
    "tooltip": "'A Copper bar infused with pure light'",
   
    "recipes":
    [{
        "items": { "PureLightEssence": 1, "Copper Bar": 1 },
        "tiles": [ "Infusing Station" ],
        "creates": 1
    }]
}
Code:
{
    "displayName": "Infused Wood",
    "size": [20,20],
    "maxStack": 999,
    "value": [0,0,0,0],
    "rare": 9,
    "tooltip": "'A chunk of wood with veins of pure light'",
   
    "recipes":
    [{
        "items": { "PureLightEssence": 1, "Wood": 2 },
        "tiles": [ "Infusing Station" ],
        "creates": 1
    }]
}
 
So I'm trying to create a tile to use as crafting station, the tile itself works like it should, and the item I want to craft with it shows up when getting close, but it doesn't disappear when I walk away from it, it stays enabled over the whole world, and I can craft it where I want. When I restart the world it's gone again, but when I get close to the tile again, it happens all over again... Tried it with another item, same result. Could anybody help me?
This bug has been reported and fixed in the upcoming tAPI r15.

Until then, if you're comfortable writing some custom code, you can manually calculate the distance the player is from your tile using the Vector2.Distance function in your custom tiles PreDraw override.
 
This bug has been reported and fixed in the upcoming tAPI r15.

Until then, if you're comfortable writing some custom code, you can manually calculate the distance the player is from your tile using the Vector2.Distance function in your custom tiles PreDraw override.
Thanks ^^ I guess I'll just wait til the next update then, still got lots of other stuff to do
 
You need a Wavebanks folder set, with a wavebank file inside and a json stating the name of the tracks, tho so far I was not able to set up custom music at all.
I have Lunar.wav file and Lunar.json:
Code:
{
"music": "Tremor:Lunar"
}

And also this:
Code:
public override void ChooseTrack(ref string current)
{
    if(Main.gameMenu)
    {
        return;
    }
    if(NPC.AnyNPCs("Tremor:CyberKing"))
    {
        current = "Tremor:Lunar"; //replace with whatever music you want. This one happens to be the brain of cthulhu / destroyer song.
    }
}
But the music won't play ingame.
 
:dryadeek: The forum is notifying me properly again! Yaaaay!
I have Lunar.wav file and Lunar.json:
Code:
{
"music": "Tremor:Lunar"
}

And also this:
Code:
public override void ChooseTrack(ref string current)
{
    if(Main.gameMenu)
    {
        return;
    }
    if(NPC.AnyNPCs("Tremor:CyberKing"))
    {
        current = "Tremor:Lunar"; //replace with whatever music you want. This one happens to be the brain of cthulhu / destroyer song.
    }
}
But the music won't play ingame.
Wavebank, not wav file. Google "microsoft xact", it's the tool used to make wavebanks. If you add terraria to the search, you'll probably find a bunch of old tutorials on how to use it :dryadsmile: Of course how you use them in tAPI is a little different than in tConfig, w1k said it above (And if you search wavebanks or music in this thread, you will find the conversation between w1k and me from a few weeks ago about it)
 
So... Anyway of creating new biomes, with new music, new mobs, new trees, new water sprites etc?
It has to be generated manually with your own code, but there is detection + music, which is done by checking how many of certain blocks are nearby. Not 100% sure the water part is possible without manually redrawing the water a different colour.

For the detection, it's pretty easy.
Code:
Biome biome;
biome = new Biome("Gem", new List<int> { 63, 64, 65, 66, 67, 68, 178 }, new List<int> { }, 20);
biome.SetBiomeMusic(Biome.MusicPriority.High, "MyMod:GemMusic");
biome.AddToGame();
That will add a "Gem" biome, that counts the gem tiles (the first list), doesn't decrease the count for anything (the second list), and counts as a biome if the count is 20 or higher. The next line set's the music for the biome, with the priority "High". Then it adds the biome to the game.

For the lists, basically, for every tile near the player, it increases a counter for each tile from the first list. Then it decreases the counter for each tile in the second list. If the resulting number is above the number you have set in the last argument, then you are considered in that biome.

For the music priorities, there is:
  • Biome.MusicPriority.None : Won't play the music (Don't really need to ever use this... lol)
  • Biome.MusicPriority.Low : Will only override Blood Moon, Overworld Day, Overworld Night, and Rain
  • Biome.MusicPriority.Med : Will override all biome music EXCEPT Meteor, Dungeon, Eclipse, Lihzahrd, Mushroom, Corruption, and Crimson
  • Biome.MusicPriority.High : Will override all biome music.

I'm assuming that Med won't override Hallow either, I just copy and pasted the lists from the comments beside them in tAPI's code, could be wrong though. Most biomes I'm assuming would be Med. Also, remember that boss music will always override biome music, even on High.

As for the NPC thing, in the CanSpawn hook, just like with vanilla, check the zone, but use your biome's name. So player.zone["Gem"] for the example I gave above.

EDIT: Oh and, note, the music is optional, you can have biomes purely for detecting certain tiles nearby, the water candle counts as a biome that just needs 1 water candle :dryadtongue:
 
Last edited:
i have a problem when i am trying (or my friend) connect to my dedicated server, the dedicated server show this
upload_2015-2-6_20-20-58.png

any help ? :C
 
basemod,blitz,grealm,mainslotzero,omnirsnospak,thoriummod+,tremor mod,
Well, one of those mods is most likelly messing up with the saving/loading sync, but I'm not familiar with any of them so I can't really be of any help. Does it also happen when no mods are loaded?
 
oh man its working i can join to my server wohooooooooo thanks ! soo somethink is bad with 1 mod now which one is it ?
Turn them on one at a time and keep trying to connect to your server, you'll eventually find which one is derping your multiplayer. It's fairly easy for MP to mess up with mods that are not optimized for such, which are a lot since MP syncing can be hell.
 
oh man its working i can join to my server wohooooooooo thanks ! soo somethink is bad with 1 mod now which one is it ?
Most likely it's my "MainSlotZero", how long ago did you download it? The latest version should have that bug fixed. If you have the latest version of it, it's another mod that adds a keybinding.
 
ModBase -> public override void PostGameUpdate() seems like a good spot to do the reset you desire (although it really depends on just what that reset is...)

Your code looks like its borrowing quite a bit of decompiled stuff, there's no need to make a new nullable rectangle if you're just passing a rectangle, more over the rectangle you're passing - which is the box of pixels to draw - is the player's body frame (which is the thing that bobs around because the player is animating, obviously)

That aside, you're using the wrong method.
ModPlayer -> public override void ModifyDrawLayerHeadList(System.Collections.Generic.List<PlayerLayer> list) is the hook you want to use for replacing the head piece to draw on the map, works similarly to the interfaces I assume you've got experience with already.

Thank you so much for your advice. PostGameUpdate happened too soon for what I wanted, so I tried PostGameDraw again. I tried that hook once before, but it caused the game to crash. I don't know what I did wrong the first time, but it resets properly now.

As for the nullable rectangle, I'd been trying several different things there and left it like that for some reason. I ended up using 'new Rectangle(0, 0, 40, 56)' to prevent the head from animating.

Onto other issues, I use the following code in my NPC's script to control its direction.

Code:
//tar is a reference to the player ... deltaX is the horizontal distance between the NPC and the player
if (deltaX > 16 && npc.velocity.X > -6) //If to the right of the player and not at maximum left velocity and not up against a wall
{
    npc.velocity.X = (npc.velocity.X <= -6) ? -6 : npc.velocity.X -= 0.3F; //Accelerate left, but not too fast
    npc.direction = -1; //Face left
} else if (deltaX < -16 && npc.velocity.X < 6) //If to the left of the player and not at maximum right velocity and not up against a wall
{
    npc.velocity.X = (npc.velocity.X >= 6) ? 6 : npc.velocity.X += 0.3F; //Accelerate right, but not too fast
    npc.direction = 1; //Face right
} else //Otherwise
{
    npc.velocity.X -= (npc.velocity.X - tar.velocity.X) * 0.3F; //Match the player's speed
    npc.direction = tar.direction; //Face the same way as the player
}
/*more code here*/

public override void SelectFrame(int frameSize)
{
    npc.spriteDirection = npc.direction;
//other animation code...

This worked the way I intended in R13, but in R14 the NPC faces the wrong way when next to the player, yet the correct way when running towards the player. I outputted the NPC's direction and spriteDirection to an interface layer. Sometimes they were different to each other even though there was no situation where 'npc.spriteDirection = npc.direction;' wasn't called.

I plan to change this NPC into a projectile so I'm not too concerned about this, but I'd be curious to know why it happened. (Yes, I have a lot of work ahead of me.)

One final thing, I think I may have found another bug. The first time someone uses a minecart on a server, the game lags for a moment and the following message pops up in the server window.

Code:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Terraria.Mount.GetHeightBoost(Int32 MountType)
   at Terraria.Player.GrappleMovement()
   at Terraria.Player.UpdatePlayer(Int32 i)
   at Terraria.Main.UpdateReal(GameTime gameTime)
Press Enter to continue

The game continues as normal without any more issues. I tested this with no mods enabled so it's not my mod causing this issue. It could be my world file though...

Anyway, thanks for bearing with me.
 
I need alot of help with my TAPI mod.
Code:
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Terraria;
using TAPI;


namespace T727Mod.Items
{
 
     public class M4A1 : ModItem
     {
         byte wheelmanager = -0;
         public override bool CanEquip(Player player, TAPI.UIKit.ItemSlot slot)
         {
             int CurrentClip = 30 ;
             int ClipSize = 30 ;  //Clip size base
             int FireRate = 9 ;  //in FPS, the higher, the slower
             int ReloadTime = 132 ;  //2.2 sec reload
                if (CurrentClip == 0 )
                 {
                    System.Diagnostics.Stopwatch reloader = new System.Diagnostics.Stopwatch();
                    Dictionary<int, Texture2D> wheelSprites = new Dictionary<int, Texture2D>();
                    wheelSprites.Add(0, Content.Load<Texture2D>("ReloadbarEmpty"));
                    wheelSprites.Add(1, Content.Load<Texture2D>("Reloadbar1of19"));
                    wheelSprites.Add(2, Content.Load<Texture2D>("Reloadbar2of19"));
                    wheelSprites.Add(3, Content.Load<Texture2D>("Reloadbar3of19"));
                    wheelSprites.Add(4, Content.Load<Texture2D>("Reloadbar4of19"));
                    wheelSprites.Add(5, Content.Load<Texture2D>("Reloadbar5of19"));
                    wheelSprites.Add(6, Content.Load<Texture2D>("Reloadbar6of19"));
                    wheelSprites.Add(7, Content.Load<Texture2D>("Reloadbar7of19"));
                    wheelSprites.Add(8, Content.Load<Texture2D>("Reloadbar8of19"));
                    wheelSprites.Add(9, Content.Load<Texture2D>("Reloadbar9of19"));
                    wheelSprites.Add(10, Content.Load<Texture2D>("Reloadbar10of19"));
                    wheelSprites.Add(11, Content.Load<Texture2D>("Reloadbar11of19"));
                    wheelSprites.Add(12, Content.Load<Texture2D>("Reloadbar12of19"));
                    wheelSprites.Add(13, Content.Load<Texture2D>("Reloadbar13of19"));
                    wheelSprites.Add(14, Content.Load<Texture2D>("Reloadbar14of19"));
                    wheelSprites.Add(15, Content.Load<Texture2D>("Reloadbar15of19"));
                    wheelSprites.Add(16, Content.Load<Texture2D>("Reloadbar16of19"));
                    wheelSprites.Add(17, Content.Load<Texture2D>("Reloadbar17of19"));
                    wheelSprites.Add(18, Content.Load<Texture2D>("Reloadbar18of19"));
                    wheelSprites.Add(19, Content.Load<Texture2D>("Reloadbar19of19"));
                    if (reloader.ElapsedMilliseconds %150 < 1)
                    {
                        wheelmanager += 1;
                        if (wheelmanager == 20)
                        {
                            wheelmanager = 0;

                        }
                  }
             }
         }
     }
}
I dont get what does %150 < 1 mean.
How can I trace a character's object material number inside his inventory?
 
Status
Not open for further replies.
Back
Top Bottom