tAPI Modding help pls!

Tehrcb

Terrarian
So I've been searching the internet for hours and NOBODY For realz knows ANYTHING about NPC shops! And if they do, nobody is nice enough to share it (Thanks internet.) So if you would like to help me, I'd be eternally and internally grateful and would give you so much credit in my mod it'll come out of your screen and thank you personally. Pls help, I usually know a lot about this but I've hit a wall.

Here is my NPC.JSON
Code:
{
    "displayName": "Herald of Cthulhu"
    "occupation": "Corrupt Herald"
    "lifeMax": 999
    "defense": 999
    "texture": "Midnight:Herald_NPC"
    "shop": true
    "frameCount": 15
    "npcSlots": 1
    "aiStyle": 7
    "male": false
    "textureHead": "Midnight:HeraldH"
  

}

Help please!
 
Last edited:
In my npc i use this json i have a past with much functions of tapi you can download here
https://codetree.net/clicks/track?u...Lg&expiry=1402619888&post_id=753&topic_id=178
the code of npc town is it:
{
"size": [20,40],
"npcSlots": 1,
"aiStyle": 7,
"animationType": 3,
"frameCount": 3,
"lifeMax": 250,
"damage": 10,
"defense": 15,
"soundHit" : 1,
"soundKilled" : 1,
"friendly": true,
"townNPC": true,
"occupation": "Zombie", /* npc title (ie Bob the *occupation*) */
"male": true, /* used for the king and queen statues */
"kid": false, /* Make true to have the npc dissapear and say 'ran away!' instead of 'was slain...' when killed. */
"shop": true
}
 
You have to make a cs file to have your npc sell merchandise, here is an example from my mod COFP...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace COFP.NPCs
{
    public class CWD : ModNPC
    {
        public override bool CanTownNPCSpawn() //Whether the NPC can spawn
        {
            if(NPC.downedBoss1 == true)  //
            {
                return true;
            } 
            return false;
        }
        public override string SetName() //Set the name...
        {
            return "Ed";
        }
        public override void SetChatButtons(ref string[] buttons)
        {
            buttons[0] = "Shop"; //Add a button called Shop.
        }
        public override void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
        {
            if (buttonIndex == 0) openShop = true; //If the button is clicker, open the shop.
        }
        public override void SetupShop(Chest chest, ref int index)
        {
                chest.item[index].SetDefaults("COFP:PoHE"); //Set the item being sold.
                chest.item[index].value = 500; //It's value
                index++; //Go to the next item
                chest.item[index].SetDefaults("COFP:PoIE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:PoFE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:GDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:MDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:GS");
                chest.item[index].value = 100;
                index++;
                chest.item[index].SetDefaults("COFP:OrbOfInfusion");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:CWP");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:UASB");
                chest.item[index].value = 10000;
                index++;
                chest.item[index].SetDefaults("COFP:UABB");
                chest.item[index].value = 10000;
                index++;
        }
        public override string SetChat() //Set what the NPC says.
        {
            string chat = "Hello.";
            return chat;
        }
    }
}
 
You can get the latest examplemod by going onto the #tapi IRC and typing ?examplemod, it has tons of usefull stuff in it. (Including custom NPCs :) )
 
You have to make a cs file to have your npc sell merchandise, here is an example from my mod COFP...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace COFP.NPCs
{
    public class CWD : ModNPC
    {
        public override bool CanTownNPCSpawn() //Whether the NPC can spawn
        {
            if(NPC.downedBoss1 == true)  //
            {
                return true;
            }
            return false;
        }
        public override string SetName() //Set the name...
        {
            return "Ed";
        }
        public override void SetChatButtons(ref string[] buttons)
        {
            buttons[0] = "Shop"; //Add a button called Shop.
        }
        public override void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
        {
            if (buttonIndex == 0) openShop = true; //If the button is clicker, open the shop.
        }
        public override void SetupShop(Chest chest, ref int index)
        {
                chest.item[index].SetDefaults("COFP:PoHE"); //Set the item being sold.
                chest.item[index].value = 500; //It's value
                index++; //Go to the next item
                chest.item[index].SetDefaults("COFP:PoIE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:PoFE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:GDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:MDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:GS");
                chest.item[index].value = 100;
                index++;
                chest.item[index].SetDefaults("COFP:OrbOfInfusion");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:CWP");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:UASB");
                chest.item[index].value = 10000;
                index++;
                chest.item[index].SetDefaults("COFP:UABB");
                chest.item[index].value = 10000;
                index++;
        }
        public override string SetChat() //Set what the NPC says.
        {
            string chat = "Hello.";
            return chat;
        }
    }
}
Thanks, that's just what I needed to know.
[DOUBLEPOST=1431812709,1431812535][/DOUBLEPOST]
You have to make a cs file to have your npc sell merchandise, here is an example from my mod COFP...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace COFP.NPCs
{
    public class CWD : ModNPC
    {
        public override bool CanTownNPCSpawn() //Whether the NPC can spawn
        {
            if(NPC.downedBoss1 == true)  //
            {
                return true;
            }
            return false;
        }
        public override string SetName() //Set the name...
        {
            return "Ed";
        }
        public override void SetChatButtons(ref string[] buttons)
        {
            buttons[0] = "Shop"; //Add a button called Shop.
        }
        public override void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
        {
            if (buttonIndex == 0) openShop = true; //If the button is clicker, open the shop.
        }
        public override void SetupShop(Chest chest, ref int index)
        {
                chest.item[index].SetDefaults("COFP:PoHE"); //Set the item being sold.
                chest.item[index].value = 500; //It's value
                index++; //Go to the next item
                chest.item[index].SetDefaults("COFP:PoIE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:PoFE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:GDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:MDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:GS");
                chest.item[index].value = 100;
                index++;
                chest.item[index].SetDefaults("COFP:OrbOfInfusion");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:CWP");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:UASB");
                chest.item[index].value = 10000;
                index++;
                chest.item[index].SetDefaults("COFP:UABB");
                chest.item[index].value = 10000;
                index++;
        }
        public override string SetChat() //Set what the NPC says.
        {
            string chat = "Hello.";
            return chat;
        }
    }
}
you set the [index] to the name of the item being sold right?
 
Thanks, that's just what I needed to know.
That empty comment next to the if statement inside the CanSpawnTownNPC() hook was supposed to say "If the Eye of Cthullu is defeated in the world then set to true".
[DOUBLEPOST=1431812861,1431812737][/DOUBLEPOST]
you set the [index] to the name of the item being sold right?
No, you put it inside SetDefaults... (chest.item[index].SetDefaults("ModInternalName:ModItem");)
 
That empty comment next to the if statement inside the CanSpawnTownNPC() hook was supposed to say "If the Eye of Cthullu is defeated in the world then set to true".
[DOUBLEPOST=1431812861,1431812737][/DOUBLEPOST]
No, you put it inside SetDefaults... (chest.item[index].SetDefaults("ModInternalName:ModItem");)
thx.
 
You have to make a cs file to have your npc sell merchandise, here is an example from my mod COFP...

Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using TAPI;
using Terraria;

namespace COFP.NPCs
{
    public class CWD : ModNPC
    {
        public override bool CanTownNPCSpawn() //Whether the NPC can spawn
        {
            if(NPC.downedBoss1 == true)  //
            {
                return true;
            }
            return false;
        }
        public override string SetName() //Set the name...
        {
            return "Ed";
        }
        public override void SetChatButtons(ref string[] buttons)
        {
            buttons[0] = "Shop"; //Add a button called Shop.
        }
        public override void OnChatButtonClicked(string[] buttons, int buttonIndex, ref bool openShop)
        {
            if (buttonIndex == 0) openShop = true; //If the button is clicker, open the shop.
        }
        public override void SetupShop(Chest chest, ref int index)
        {
                chest.item[index].SetDefaults("COFP:PoHE"); //Set the item being sold.
                chest.item[index].value = 500; //It's value
                index++; //Go to the next item
                chest.item[index].SetDefaults("COFP:PoIE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:PoFE");
                chest.item[index].value = 500;
                index++;
                chest.item[index].SetDefaults("COFP:GDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:MDK");
                chest.item[index].value = 2500;
                index++;
                chest.item[index].SetDefaults("COFP:GS");
                chest.item[index].value = 100;
                index++;
                chest.item[index].SetDefaults("COFP:OrbOfInfusion");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:CWP");
                chest.item[index].value = 25000;
                index++;
                chest.item[index].SetDefaults("COFP:UASB");
                chest.item[index].value = 10000;
                index++;
                chest.item[index].SetDefaults("COFP:UABB");
                chest.item[index].value = 10000;
                index++;
        }
        public override string SetChat() //Set what the NPC says.
        {
            string chat = "Hello.";
            return chat;
        }
    }
}

Just a quick question about the NPC spawning, is it possible to set it to spawn three nights after the world is created? Like three game nights.
 
Back
Top Bottom