tAPI tAPI Community Resources - Development assistance for developers, by developers.

Hello, I hope I'm not interrupting anything. I'm just starting with tAPI, and I've got version r15.

However, I've got a problem: I can't get anything to work. My mod will compile fine, and it will show up on the mod list, but the crafting recipe isn't showing. I'll just paste the code for the item below:

(I apologize for not using a code box, but I'm not sure of the formatting here. I'll edit it when I find out how to make one.)

{
"displayname": "Shimmering Alloy",
"size": [30,24],
"maxStack": 99,
"value": [0,0,10,0],
"rare": 1,
"tooltip": "'It's very shiny.'",

"recepies":
[{
"items": {"Dirt Block": 3},
"tiles": [ "Work Bench" ],
"creates": 1
}]
}


And the Mod Info code:

{
"internalName":"CreatiaMod",
"displayName":"Creatia Mod",
"author":"Crimera",
"info":"No Information",
"version":"0.0.0"
}

I've got an image file with the same name as the .json. The image is 30x24 so that's what I put in as the size- but using 15x15 didn't work either. The item .json and the image are in the same folder titled "Items". Is there something I'm missing out? I'd be happy to share any relevant information if I've forgotten to say something important.
 
Hello, I hope I'm not interrupting anything. I'm just starting with tAPI, and I've got version r15.

However, I've got a problem: I can't get anything to work. My mod will compile fine, and it will show up on the mod list, but the crafting recipe isn't showing. I'll just paste the code for the item below:

(I apologize for not using a code box, but I'm not sure of the formatting here. I'll edit it when I find out how to make one.)

{
"displayname": "Shimmering Alloy",
"size": [30,24],
"maxStack": 99,
"value": [0,0,10,0],
"rare": 1,
"tooltip": "'It's very shiny.'",

"recepies":
[{
"items": {"Dirt Block": 3},
"tiles": [ "Work Bench" ],
"creates": 1
}]
}


And the Mod Info code:

{
"internalName":"CreatiaMod",
"displayName":"Creatia Mod",
"author":"Crimera",
"info":"No Information",
"version":"0.0.0"
}

I've got an image file with the same name as the .json. The image is 30x24 so that's what I put in as the size- but using 15x15 didn't work either. The item .json and the image are in the same folder titled "Items". Is there something I'm missing out? I'd be happy to share any relevant information if I've forgotten to say something important.
You mispelled recipes.
 
Well, that's embarrassing! Thanks for the quick reply. It works now (I also noticed that I wrote displayname instead of displayName. Corrected that too.)
 
  • Like
Reactions: Azu
Can someone check my code? I can pack it with TAPI Builder, but the armor effects don't work.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DemonFleshArmor.Items
{
    public class DemonFleshScalemail : ModItem
    {
        public override void Effects(Player player)
        {
            if (item.type == ItemDef.byName["DemonFleshArmor:DemonFleshGreaves"].type)
            {
                player.lifeRegen = 10;
                player.statLifeMax += 18;
            }
            else if (item.type == ItemDef.byName["DemonFleshArmor:DemonFleshHelmet"].type)
            {
                player.lifeRegen = 10;
                player.statLifeMax += 12;
            }
            else
            {
                player.lifeRegen = 10;
                player.statLifeMax += 20;
            }
        }
        public override void ArmorSetBonus(Player player)
        {
            player.setBonus = "Hey look, set bonus! :D";
                player.moveSpeed += 12;
        }
    }
}
 
Can someone check my code? I can pack it with TAPI Builder, but the armor effects don't work.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DemonFleshArmor.Items
{
    public class DemonFleshScalemail : ModItem
    {
        public override void Effects(Player player)
        {
            if (item.type == ItemDef.byName["DemonFleshArmor:DemonFleshGreaves"].type)
            {
                player.lifeRegen = 10;
                player.statLifeMax += 18;
            }
            else if (item.type == ItemDef.byName["DemonFleshArmor:DemonFleshHelmet"].type)
            {
                player.lifeRegen = 10;
                player.statLifeMax += 12;
            }
            else
            {
                player.lifeRegen = 10;
                player.statLifeMax += 20;
            }
        }
        public override void ArmorSetBonus(Player player)
        {
            player.setBonus = "Hey look, set bonus! :D";
                player.moveSpeed += 12;
        }
    }
}
Post the JSON file for one of the items, please.
 
Post the JSON file for one of the items, please.
Here ya go:
Code:
{
    "displayName": "Demon Flesh Scalemail",
    "size": [30,20],
    "maxStack": 1,
    "value": [0,10,0,0],
    "rare": 2,
    "defense": 11,
    "armorBody": true,
    "hasHands": false,
    "setName": "Demon Flesh",

    "recipes":
    [{
        "items": { "Shadow Scalemail":1, "Crimson Scalemail":1, "Soul of Night":10 },
        "tiles": [ "Anvil" ],
        "creates": 1   
    }]   
}
 
Can someone help me fix loading the images in-game?
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 Terraria;
using TAPI;


namespace T727Mod.Items
{

    public class M4A1 : ModItem
    {
              byte wheelmanager = -0;
              public override bool PreShoot(Player player, Vector2 position, Vector2 velocity, int projType, int damage, float knockback)
        {
             int CurrentClip = 0 ;
             int ClipSize = 30 ;  //Clip size base
             int FireRate = 9 ;  //in FPS, the higher, the slower
             int ReloadTime = 132 ;  //2.2 sec reload
             int PenetrationStandard = 2 ;
             int PenetrationArmourPiercing = 4 ;
             int PenetrationAPCR = 6 ;
             int PenetrationHighExplosive = 1 ;
                  if (CurrentClip >= 0)
                  {
                  CurrentClip -= 1 ;
                  }
                     else 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>("Reloadbar1of19"));
                 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 % 220 < 1)
                 {
                     CurrentClip += 1;
                     if (CurrentClip == ClipSize)
                     {
                         CurrentClip = 0;
                     }
                    {
                    wheelmanager += 1;
                     if (wheelmanager == 20)
                      {
                    wheelmanager = 0;

                      }
                      }
                    Vector2 wheelplace = new Vector2(100,100);
                    spriteBatch.Draw(wheelSprites[wheelmanager],wheelplace,Color.White);
                 }
             }
                  return false;
         }

    }
}
 
Last edited:
Can someone help me fix loading the images in-game?
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 Terraria;
using TAPI;


namespace T727Mod.Items
{

    public class M4A1 : ModItem
    {
              byte wheelmanager = -0;
              public override bool PreShoot(Player player, Vector2 position, Vector2 velocity, int projType, int damage, float knockback)
        {
             int CurrentClip = 0 ;
             int ClipSize = 30 ;  //Clip size base
             int FireRate = 9 ;  //in FPS, the higher, the slower
             int ReloadTime = 132 ;  //2.2 sec reload
             int PenetrationStandard = 2 ;
             int PenetrationArmourPiercing = 4 ;
             int PenetrationAPCR = 6 ;
             int PenetrationHighExplosive = 1 ;
                  if (CurrentClip >= 0)
                  {
                  CurrentClip -= 1 ;
                  }
                     else 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>("Reloadbar1of19"));
                 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 % 220 < 1)
                 {
                     CurrentClip += 1;
                     if (CurrentClip == ClipSize)
                     {
                         CurrentClip = 0;
                     }
                    {
                    wheelmanager += 1;
                     if (wheelmanager == 20)
                      {
                    wheelmanager = 0;

                      }
                      }
                    Vector2 wheelplace = new Vector2(100,100);
                    spriteBatch.Draw(wheelSprites[wheelmanager],wheelplace,Color.White);
                 }
             }
                  return false;
         }

    }
}
Add a folder called 'Textures' to your mod folder like so:
ORCOeuo.png

Add your images to that folder.

In your MBase.cs file create Texture2D variables for each image.
In the OnLoad() function assign your textures to the variables.
Make sure to check for a server and return instead of loading the images if it is a server.
Here's an example:
1qGwIc5.png

To use your textures do this:
Code:
wheelSprites.Add(0, MBase.TimerTexture; // An example of loading it into your dictionary

sb.draw(MBase.TimerTexture, etc., etc., etc.); // An example of drawing your image
 
It it me, or does the modNPC page under the CS tab in the docs not show up?
It's not just you. Here's a list of hooks if you need them, taken from the source code, then with brief explanations added by me:

public virtual void UpdateSpawnRate(Player player)
Allows you to change the spawn rate and spawn cap. I recommend using this only for a class with the GlobalMod attribute.

public virtual System.Collections.Generic.List<int> EditSpawnPool(int x, int y, System.Collections.Generic.List<int> pool, Player player)
You can modify the "pool" list to determine the possible NPCs that can spawn. Again, I only recommend this for a GlobalMod class.

public virtual bool CanSpawn(int x, int y, int type, Player spawnedOn)
Lets you determine the conditions under which an NPC can spawn. "type" is the type of the NPC that this method is getting called for.

public virtual bool CanTownNPCSpawn()
Lets you determine the conditions required for a town NPC to spawn.

public virtual void OnSpawn()
If you want your mod to be server-compatible, I don't recommend using this.

public virtual string CheckConditions(int minX, int maxX, int minY, int maxY)
I've never actually used this yet, so I don't know what it does.

public virtual bool PreAI()
Lets you do AI stuff before the main AI is called. Also lets you determine whether the AI should run at all; if you return false then the normal AI will not run. By default it will return true.

public virtual void AI()
This is where you put all your main AI stuff. Not called if PreAI returns false.

public virtual void PostAI()
This is where you put AI stuff that happens after the main AI. Note that this will always run no matter what PreAI returns.

public virtual void SetupLootRules(NPC npc)
Allows you to determine what will happen when the NPC dies. For a full explanation you'll need to see the TAPI.LootRule class in the source code.

public virtual bool PreNPCLoot()
An alternative to determine what happens when the NPC dies. It's easier to learn than LootRules but more tedious to use. Returns true if NPCLoot should be called, return false to stop NPCLoot from running.

public virtual void NPCLoot()
This gets called when the NPC dies and PreNPCLoot returns true. To make items drop you'll have to use Item.NewItem.

public virtual void PostNPCLoot()
This gets called when the NPC dies after everything else gets called, regardless of what PreNPCLoot returns.

public virtual void ItemsDropped(System.Collections.Generic.List<Item> items)
Huh, I never actually new this existed. It sounds way easier than the alternatives listed above. Not as much freedom though.

public virtual void SelectFrame(int frameSize)
Modify npc.frame.Y here to run your NPC's animations.

public virtual void HitEffect(int hitDirection, double damage, bool isDead)
This gets called whenever the NPC gets damaged. It's normally used to make dust and gores.

public virtual void DamagePlayer(Player player, int hitDir, ref int damage, ref bool crit, ref float critChance)
This lets you modify the damage dealt to a player and the crit chance against a player. It also lets you set 100% crits under certain conditions.

public virtual void DealtPlayer(Player player, int hitDir, int dmgDealt, bool crit)
This gets called when the NPC actually damages the player. I personally use it for things like inflicting debuffs.

public virtual void DamageNPC(Player player, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
You can use this to modify the damage a player does to this NPC. You can also modify the knockback and the critical hit multiplier, and change whether or not it's a critical hit.

public virtual void DealtNPC(Player player, int hitDir, int dmgDealt, float knockback, bool crit)
This gets called whenever a player damages this NPC.

public virtual void DamageNPC(Projectile projectile, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
Same as the above ones except for a projectile damaging this NPC.

public virtual void DealtNPC(Projectile projectile, int hitDir, int dmgDealt, float knocback, bool crit)
Same as the above ones except for a projectile damaging this NPC.

public virtual bool? CanHitPlayer(Player player)
Whether or not this NPC can damage the player. Return false if it can't, true if it always will, and null for to let other sources decide. (If everything returns null then it counts as true.)

public virtual bool? CanHitNPC(Player player)
Same as above, except for whether the player can damage this NPC.

public virtual bool? CanHitFriendNPC(NPC npc)
I've never actually used this; I assume it's for things like critters and town NPCs?

public virtual bool PreDraw(SpriteBatch sb)
Here you can draw stuff that is behind the NPC, such as Pumpking's cloak. If you return false, then the NPC itself will not be drawn.

public virtual void PostDraw(SpriteBatch sb)
Here you can draw stuff in front of the NPC. It will always be called even if PreDraw returns false.

public virtual void DrawMapIcon(SpriteBatch sb, Vector2 drawPosition, float scale, Color color, ref string cursorText)
I've never actually used this. I'm not sure what it does.

public virtual Color ModifyDrawColor(Color color)
Let's you determine the shade of color that the NPC should be drawn in. The parameter is a combination of the lighting color and the colors resulting from (de)buffs.

public virtual string SetName()
Returns a string that will be the town NPC's name.

public virtual string SetChat()
Returns a string which is what the town NPC will say when you talk to him/her.

public virtual string PostSetChat(string chat)
This gets called after SetChat. The parameter is what you chose for the NPC to say.

public virtual void SetupShop(Chest chest, ref int index)
I've never used anything related to shops yet, but other people know how to use it. If you need help feel free to ask.

public virtual bool ResetShop(Chest chest)

public virtual void PostSetupShop(Chest chest, ref int lastIndex)

public virtual void PostSetupTravelShop(int[] shop, ref int lastIndex)

public virtual void SetChatButtons(ref string[] buttons)
You can modify the list of strings to determine the buttons that appear in the chat window. For example, the guide has a "Crafting" button, the old man has a "Curse" button, and many people have "Shop" buttons.

public virtual void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
This lets you determine what happens when a chat button is clicked. You can modify openShop to determine whether or not the button opens a shop.
 
It's not just you. Here's a list of hooks if you need them, taken from the source code, then with brief explanations added by me:

public virtual void UpdateSpawnRate(Player player)
Allows you to change the spawn rate and spawn cap. I recommend using this only for a class with the GlobalMod attribute.

public virtual System.Collections.Generic.List<int> EditSpawnPool(int x, int y, System.Collections.Generic.List<int> pool, Player player)
You can modify the "pool" list to determine the possible NPCs that can spawn. Again, I only recommend this for a GlobalMod class.

public virtual bool CanSpawn(int x, int y, int type, Player spawnedOn)
Lets you determine the conditions under which an NPC can spawn. "type" is the type of the NPC that this method is getting called for.

public virtual bool CanTownNPCSpawn()
Lets you determine the conditions required for a town NPC to spawn.

public virtual void OnSpawn()
If you want your mod to be server-compatible, I don't recommend using this.

public virtual string CheckConditions(int minX, int maxX, int minY, int maxY)
I've never actually used this yet, so I don't know what it does.

public virtual bool PreAI()
Lets you do AI stuff before the main AI is called. Also lets you determine whether the AI should run at all; if you return false then the normal AI will not run. By default it will return true.

public virtual void AI()
This is where you put all your main AI stuff. Not called if PreAI returns false.

public virtual void PostAI()
This is where you put AI stuff that happens after the main AI. Note that this will always run no matter what PreAI returns.

public virtual void SetupLootRules(NPC npc)
Allows you to determine what will happen when the NPC dies. For a full explanation you'll need to see the TAPI.LootRule class in the source code.

public virtual bool PreNPCLoot()
An alternative to determine what happens when the NPC dies. It's easier to learn than LootRules but more tedious to use. Returns true if NPCLoot should be called, return false to stop NPCLoot from running.

public virtual void NPCLoot()
This gets called when the NPC dies and PreNPCLoot returns true. To make items drop you'll have to use Item.NewItem.

public virtual void PostNPCLoot()
This gets called when the NPC dies after everything else gets called, regardless of what PreNPCLoot returns.

public virtual void ItemsDropped(System.Collections.Generic.List<Item> items)
Huh, I never actually new this existed. It sounds way easier than the alternatives listed above. Not as much freedom though.

public virtual void SelectFrame(int frameSize)
Modify npc.frame.Y here to run your NPC's animations.

public virtual void HitEffect(int hitDirection, double damage, bool isDead)
This gets called whenever the NPC gets damaged. It's normally used to make dust and gores.

public virtual void DamagePlayer(Player player, int hitDir, ref int damage, ref bool crit, ref float critChance)
This lets you modify the damage dealt to a player and the crit chance against a player. It also lets you set 100% crits under certain conditions.

public virtual void DealtPlayer(Player player, int hitDir, int dmgDealt, bool crit)
This gets called when the NPC actually damages the player. I personally use it for things like inflicting debuffs.

public virtual void DamageNPC(Player player, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
You can use this to modify the damage a player does to this NPC. You can also modify the knockback and the critical hit multiplier, and change whether or not it's a critical hit.

public virtual void DealtNPC(Player player, int hitDir, int dmgDealt, float knockback, bool crit)
This gets called whenever a player damages this NPC.

public virtual void DamageNPC(Projectile projectile, int hitDir, ref int damage, ref float knockback, ref bool crit, ref float critMult)
Same as the above ones except for a projectile damaging this NPC.

public virtual void DealtNPC(Projectile projectile, int hitDir, int dmgDealt, float knocback, bool crit)
Same as the above ones except for a projectile damaging this NPC.

public virtual bool? CanHitPlayer(Player player)
Whether or not this NPC can damage the player. Return false if it can't, true if it always will, and null for to let other sources decide. (If everything returns null then it counts as true.)

public virtual bool? CanHitNPC(Player player)
Same as above, except for whether the player can damage this NPC.

public virtual bool? CanHitFriendNPC(NPC npc)
I've never actually used this; I assume it's for things like critters and town NPCs?

public virtual bool PreDraw(SpriteBatch sb)
Here you can draw stuff that is behind the NPC, such as Pumpking's cloak. If you return false, then the NPC itself will not be drawn.

public virtual void PostDraw(SpriteBatch sb)
Here you can draw stuff in front of the NPC. It will always be called even if PreDraw returns false.

public virtual void DrawMapIcon(SpriteBatch sb, Vector2 drawPosition, float scale, Color color, ref string cursorText)
I've never actually used this. I'm not sure what it does.

public virtual Color ModifyDrawColor(Color color)
Let's you determine the shade of color that the NPC should be drawn in. The parameter is a combination of the lighting color and the colors resulting from (de)buffs.

public virtual string SetName()
Returns a string that will be the town NPC's name.

public virtual string SetChat()
Returns a string which is what the town NPC will say when you talk to him/her.

public virtual string PostSetChat(string chat)
This gets called after SetChat. The parameter is what you chose for the NPC to say.

public virtual void SetupShop(Chest chest, ref int index)
I've never used anything related to shops yet, but other people know how to use it. If you need help feel free to ask.

public virtual bool ResetShop(Chest chest)

public virtual void PostSetupShop(Chest chest, ref int lastIndex)

public virtual void PostSetupTravelShop(int[] shop, ref int lastIndex)

public virtual void SetChatButtons(ref string[] buttons)
You can modify the list of strings to determine the buttons that appear in the chat window. For example, the guide has a "Crafting" button, the old man has a "Curse" button, and many people have "Shop" buttons.

public virtual void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
This lets you determine what happens when a chat button is clicked. You can modify openShop to determine whether or not the button opens a shop.
Any clue as to why a lot of those pages aren't working?
 
I am trying to make an enemy re balance mod and I'm trying to test it out. So far though I don't know how to give NPC's life regen and this code does not add it to them. (it works, but does not add regen). Mind that this is overwriting the stats of existing NPC's, not adding new ones.
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace ModInternalName
{
    [GlobalMod]
    public class MNPC : ModNPC
    {
        public override void OnSpawn()
        {
            if (npc.type == 3)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 1;
            } 
            if (npc.type == 132)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 2;
            }
            if (npc.type == 186)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 4;
            }
            if (npc.type == 187)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 8;
            }
            if (npc.type == 188)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 16;
            }
            if (npc.type == 189)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 32;
            }
            if (npc.type == 200)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 64;
            }
        }
    }
}
 
I am trying to make an enemy re balance mod and I'm trying to test it out. So far though I don't know how to give NPC's life regen and this code does not add it to them. (it works, but does not add regen). Mind that this is overwriting the stats of existing NPC's, not adding new ones.
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace ModInternalName
{
    [GlobalMod]
    public class MNPC : ModNPC
    {
        public override void OnSpawn()
        {
            if (npc.type == 3)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 1;
            }
            if (npc.type == 132)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 2;
            }
            if (npc.type == 186)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 4;
            }
            if (npc.type == 187)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 8;
            }
            if (npc.type == 188)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 16;
            }
            if (npc.type == 189)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 32;
            }
            if (npc.type == 200)
            {
                npc.lifeMax = 160;
                npc.life = 16;
                npc.lifeRegen = 64;
            }
        }
    }
}
The problem is that npc.lifeRegen keeps track of life regeneration for only a single tick. After every tick it gets set back to 0.
So what you'll have to do is either make a buff that modifies npc.lifeRegen every tick, or use the PostAI method to increment npc.lifeRegenCount, which keeps track of how far the npc is in its life regeneration.
What the game does is add npc.lifeRegen to npc.lifeRegenCount every tick, then set npc.lifeRegen back to 0. Then while npc.lifeRegenCount is greater than or equal to 120, it subtracts 120 from npc.lifeRegenCount and adds 1 health to the npc. There are 60 ticks in a second, so setting npc.lifeRegen to 1 or increasing npc.lifeRegenCount by 1 every tick will recover 1 health every 2 seconds.
 
Add a folder called 'Textures' to your mod folder like so:
ORCOeuo.png

Add your images to that folder.

In your MBase.cs file create Texture2D variables for each image.
In the OnLoad() function assign your textures to the variables.
Make sure to check for a server and return instead of loading the images if it is a server.
Here's an example:
1qGwIc5.png

To use your textures do this:
Code:
wheelSprites.Add(0, MBase.TimerTexture; // An example of loading it into your dictionary

sb.draw(MBase.TimerTexture, etc., etc., etc.); // An example of drawing your image
can you show me where should I place it in my code?
I'm not sure how to give the textures a variable. is it like:
Code:
loaded0  = textures["Textures/ReloadTimer0"];
Loaded1 = textures["Textures/ReloadTimer1"];
Loaded2 = textures["Textures/ReloadTimer2"];
Loaded3 = textures["Textures/ReloadTimer3"];
Loaded4 = textures["Textures/ReloadTimer4"];
Loaded5 = textures["Textures/ReloadTimer5"];
can you modify my code with the code you've shown me because I cant understand
 
whenever I put on my Armour it gives me the Armour set effect when i only have the chest piece equipped instead of the whole set, it gives me the desired effects.
upload_2015-6-27_17-7-15.png

Also it says there is no method to override and the type 'player' exists in both terraria version=1.2.4.1 and tAPI version= 1.0.

any help on this would be appreciated, thank you.
 
whenever I put on my Armour it gives me the Armour set effect when i only have the chest piece equipped instead of the whole set, it gives me the desired effects.
View attachment 59402
Also it says there is no method to override and the type 'player' exists in both terraria version=1.2.4.1 and tAPI version= 1.0.

any help on this would be appreciated, thank you.

Do all three pieces have the same setName as designated by their .json? And you're getting 80 mana and 30% magic damage?
 
Found the problem and fixed it, thank you @Hiccup251 for telling me that i had set bonus buff a bit messed up and also the red underline must be VS being an idiot

EDIT: when i take off the helmet/leggings it takes away 1 mana star while when i take off the chestpiece it takes away 2 does anyone know what's wrong?
 
Last edited:
Back
Top Bottom