• PC NEWS: 1.4.2.3 update is out! More info here. Report bugs here
  • CONSOLE 1.4 NEWS: The current plan is to have Terraria: Journey's End out for Xbox and PlayStation in Q3 2021 (Jul-Sep). Switch will follow shortly afterwards. More info here. Stay up to date with console news here
  • MOBILE NEWS: Stay up to date with the latest mobile news here. Report mobile bugs here

tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.

Mirsario

Spazmatism
Hi, me again with questions.
If there are conditions spawn monsters, for example Main.hardMode or Main.bloodMoon, is there anything for the goblin invasion? :indifferent:
Code:
if(Main.invasionType==1) //0 - None, 1 - Goblins, 2 - Frost [s]Moon[/s] Legion, 3 - Pirates
 
Last edited:
Im having trouble with setbonuses. all the armour pieces have the setname silken, yet the bonus isn't activating.
{
"displayName": "Silken Hood",
"size": [20,20],
"maxStack": 1,
"value": [0,0,75,0],
"rare": 1,
"tooltip": ["5% increased magic damage", "increases maximum mana by 20"],
"defense": 2,
"armorHead": true,
"hairType": 0,
"setName": "Silken",
"recipes":
[{
"items": { "Silk": 5 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
{
"displayName": "Silken Robe",
"size": [20,20],
"maxStack": 1,
"value": [0,0,75,0],
"rare": 1,
"tooltip": "3% increased magic critical strike chance",
"defense": 3,
"hasHands": true,
"armorBody": true,
"setName": "Silken",

"recipes":
[{
"items": { "Silk": 10 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
{
"displayName": "Silken Pants",
"size": [20,20],
"maxStack": 1,
"value": [0,0,60,0],
"rare": 1,
"tooltip": "1% increased magic critical strike chance",
"defense": 1,
"armorLegs": true,
"setName": "Silken",
"recipes":
[{
"items": { "Silk": 5 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
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 MageMod.Items
{
public class SilkenRobe : ModItem
{


public override void Effects(Player player)
{
player.magicCrit += 4;
}

public override void ArmorSetBonus(Player p)
{
p.setBonus = "+4% Magic Damage!";
p.magicDamage += 0.04f;

}

}
}
 

blushiemagic

Retinazer
tModLoader
Code:
if(Main.invasionType==1) //0 - None, 1 - Goblins, 2 - Frost Moon, 3 - Pirates
Just a correction. The Frost Moon isn't an invasion; it's determined by Main.snowMoon. So what you probably meant was the Frost Legion.

Im having trouble with setbonuses. all the armour pieces have the setname silken, yet the bonus isn't activating.
{
"displayName": "Silken Hood",
"size": [20,20],
"maxStack": 1,
"value": [0,0,75,0],
"rare": 1,
"tooltip": ["5% increased magic damage", "increases maximum mana by 20"],
"defense": 2,
"armorHead": true,
"hairType": 0,
"setName": "Silken",
"recipes":
[{
"items": { "Silk": 5 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
{
"displayName": "Silken Robe",
"size": [20,20],
"maxStack": 1,
"value": [0,0,75,0],
"rare": 1,
"tooltip": "3% increased magic critical strike chance",
"defense": 3,
"hasHands": true,
"armorBody": true,
"setName": "Silken",

"recipes":
[{
"items": { "Silk": 10 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
{
"displayName": "Silken Pants",
"size": [20,20],
"maxStack": 1,
"value": [0,0,60,0],
"rare": 1,
"tooltip": "1% increased magic critical strike chance",
"defense": 1,
"armorLegs": true,
"setName": "Silken",
"recipes":
[{
"items": { "Silk": 5 },
"tiles": [ "Loom" ],
"creates": 1
}]
}
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 MageMod.Items
{
public class SilkenRobe : ModItem
{


public override void Effects(Player player)
{
player.magicCrit += 4;
}

public override void ArmorSetBonus(Player p)
{
p.setBonus = "+4% Magic Damage!";
p.magicDamage += 0.04f;

}

}
}
Did you make sure your .json file, .cs file, and class name for the robe all share the same name?
 

Vallode

Terrarian
Hiya guys, Im kind of new to the terraria modding scene and I cannot for the hell of me figure out why this bit of code in my item does not want to compile:
Code:
Validating Jsons...
Compiling code...
AegisOfTheImmortals.cs  (30,14)
  'MM.Items.Aegis.OnEquip(Terraria.Player, int)': no suitable method found to override
        public override void OnEquip(Player player, int slot) {     //On equip?:
                             ^
AegisOfTheImmortals.cs  (30,18)
  'MM.Items.Aegis.OnUnEquip(Terraria.Player, int)': no suitable method found to override
        public override void OnUnEquip(Player player, int slot) {   //On unequip?:
                             ^
Failed to build MM.
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 MM.Items
{
    public class Aegis : ModItem                                    //Item name
    {
        public static bool playerDeath;
        public override void OnEquip(Player player, int slot) {     //On equip?:
            bool playerDeath = true;                                //Set the variable to true
        }

        public override void OnUnEquip(Player player, int slot) {   //On unequip?:
            bool playerDeath = false;                               //Set the variable to false
        }
    }
}
Anyone to the rescue?
 

Sin Costan

Eye of Cthulhu
Hiya guys, Im kind of new to the terraria modding scene and I cannot for the hell of me figure out why this bit of code in my item does not want to compile:
Code:
Validating Jsons...
Compiling code...
AegisOfTheImmortals.cs  (30,14)
  'MM.Items.Aegis.OnEquip(Terraria.Player, int)': no suitable method found to override
        public override void OnEquip(Player player, int slot) {     //On equip?:
                             ^
AegisOfTheImmortals.cs  (30,18)
  'MM.Items.Aegis.OnUnEquip(Terraria.Player, int)': no suitable method found to override
        public override void OnUnEquip(Player player, int slot) {   //On unequip?:
                             ^
Failed to build MM.
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 MM.Items
{
    public class Aegis : ModItem                                    //Item name
    {
        public static bool playerDeath;
        public override void OnEquip(Player player, int slot) {     //On equip?:
            bool playerDeath = true;                                //Set the variable to true
        }

        public override void OnUnEquip(Player player, int slot) {   //On unequip?:
            bool playerDeath = false;                               //Set the variable to false
        }
    }
}
Anyone to the rescue?

You have to have "using TAPI.UIKit" with your using lines. By the way, OnEquip and OnUnEquip do their opposites, so OnUnEquip is OnEquip and OnEquip is OnUnEquip... I've tested it.
 

Blardow

Skeletron Prime
So if I wanted to make an NPC drop an item depending on if you're in corruption or crimson, how would I go about that? As well, how do I add chances of different amounts of an item dropped in the CS portion while making sure it always drops a certain minimum amount? Basically how to use Item.NewItem to do the same thing the JSON does except with a crimson/corruption thing.
 

Vallode

Terrarian
You have to have "using TAPI.UIKit" with your using lines. By the way, OnEquip and OnUnEquip do their opposites, so OnUnEquip is OnEquip and OnEquip is OnUnEquip... I've tested it.
THANK YOU. I already knew the thing about doing the opposite but thanks! I was wondering if there is a way of exploring the methods that are not listed on the official documentation?
 

blushiemagic

Retinazer
tModLoader
So if I wanted to make an NPC drop an item depending on if you're in corruption or crimson, how would I go about that? As well, how do I add chances of different amounts of an item dropped in the CS portion while making sure it always drops a certain minimum amount? Basically how to use Item.NewItem to do the same thing the JSON does except with a crimson/corruption thing.
You do not want to use Item.NewItem (I don't know why everyone keeps using that). Use LootRule instead. I have a tutorial here (you'll have to scroll down to the Example LootRule spoiler): http://forums.terraria.org/index.php?threads/tutorial-custom-bosses-npc-ai-and-server-syncing.10474/
For the crimson/corruption condition, you'll have to use LootRule.Rules to set conditionals for your LootRule, and LootRule.rulePlayerCorruption and LootRule.rulePlayerCrimson will give you all the information you need (that's what's used for key molds at least).

THANK YOU. I already knew the thing about doing the opposite but thanks! I was wondering if there is a way of exploring the methods that are not listed on the official documentation?
In order to do that, you'll have to decompile tAPI. It's pretty difficult to get used to the code, but once you do it becomes easy to do almost whatever (I almost never look at the documentation anymore).
 

Vallode

Terrarian
Alright, well then I'll just keep practicing and see how it goes!
And sorry for bothering again but Im lost on what to do still with my code:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using TAPI.UIKit;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MM.Items
{
    public class Aegis : ModItem
    {
        public static bool playerDeath;

        public override void OnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on UN equip
           playerDeath = false;                                //Set the variable to false
        }
        public override void OnUnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on EQUIP
           playerDeath = true;                                 //Set the variable to true
        }
    }
}
My item now works and compiles but onequip (OnUnEquip) it does not set the variable to true and vice versa. Its quite a mind boggle for me!
 

Sin Costan

Eye of Cthulhu
Alright, well then I'll just keep practicing and see how it goes!
And sorry for bothering again but Im lost on what to do still with my code:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using TAPI.UIKit;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MM.Items
{
    public class Aegis : ModItem
    {
        public static bool playerDeath;

        public override void OnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on UN equip
           playerDeath = false;                                //Set the variable to false
        }
        public override void OnUnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on EQUIP
           playerDeath = true;                                 //Set the variable to true
        }
    }
}
My item now works and compiles but onequip (OnUnEquip) it does not set the variable to true and vice versa. Its quite a mind boggle for me!
Instead of putting that bool in the item cs file, try putting it in a ModPlayer cs file instead?
 

Vallode

Terrarian
Instead of putting that bool in the item cs file, try putting it in a ModPlayer cs file instead?
Yeah that worked out, would you know like why? Just for reference here are the codes to how it looks like after working for anyone who ever stumbles on this:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Terraria;
using TAPI;

namespace MM
{
    public class MPlayer : TAPI.ModPlayer
    {
        public static bool playerDeath = true;

        #region Aegis Of The Immortals
        public override bool? PreKill(double damage, int hitDirection, bool pvp, string deathText) //Right before death
        {
            if (playerDeath == true && player.statLifeMax >= 21)                    //If the player has above 21 health (To avoid your hero having 0 health forever) and has aegis
            {
                player.statLifeMax -= 20;
                player.statLife = player.statLifeMax;
                playerDeath = false;
                return false;
            }else {

                return true;
            }
        }
        #endregion
    }
}
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using TAPI;
using TAPI.UIKit;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MM.Items
{
    public class Aegis : ModItem
    {
        public override void OnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on UN equip
           MM.MPlayer.playerDeath = false;                                //Set the variable to false
        }
        public override void OnUnEquip(Player p, TAPI.UIKit.ItemSlot slot) { //on EQUIP
           MM.MPlayer.playerDeath = true;                                 //Set the variable to true
        }
    }
}
Thanks sin!
 

13Bug

Skeletron Prime
I know I already posted this, but I really want help:
Where am I supposed to Install this? No matter where I put it, it tells me that it's not a valid directory. In fact, this includes where it wants me to put it.
 

Vallode

Terrarian
I know I already posted this, but I really want help:
Where am I supposed to Install this? No matter where I put it, it tells me that it's not a valid directory. In fact, this includes where it wants me to put it.
Do you have anything else in terrarias folder? The path should look something like this
Code:
C:\program files (x86)\steam\steamapps\common\Terraria
 

Blardow

Skeletron Prime
Two questions.
1. Is it possible to adjust the drops of already existing mobs?
2. Is it possible to adjust/remove recipes to existing items?
 

Jupa

Terrarian
Hey guys i'm trying to add some more traps into terraria and I looked around and couldn't find much revolving around the code, is there any template you could toss to me or at least example i could use?
 
Status
Not open for further replies.
Top Bottom