i followed Al0n37 tutorial on youtube and created an NPC but he wont spawn.
here is my code -
here is my code -
Code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria;
using Terraria.ModLoader;
namespace ancientTimes.NPCs //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
public class Alchemist : ModNPC
{
public override void SetDefaults()
{
npc.townNPC = true; //This defines if the npc is a town Npc or not
npc.friendly = true; //this defines if the npc can hur you or not()
npc.width = 18; //the npc sprite width
npc.height = 46; //the npc sprite height
npc.aiStyle = 7; //this is the npc ai style, 7 is Pasive Ai
npc.defense = 25; //the npc defense
npc.lifeMax = 250;// the npc life
npc.HitSound = SoundID.NPCHit1; //the npc sound when is hit
npc.DeathSound = SoundID.NPCDeath1; //the npc sound when he dies
npc.knockBackResist = 0.5f; //the npc knockback resistance
Main.npcFrameCount[npc.type] = 25; //this defines how many frames the npc sprite sheet has
NPCID.Sets.ExtraFramesCount[npc.type] = 9;
NPCID.Sets.AttackFrameCount[npc.type] = 4;
NPCID.Sets.DangerDetectRange[npc.type] = 150; //this defines the npc danger detect range
NPCID.Sets.AttackType[npc.type] = 3; //this is the attack type, 0 (throwing), 1 (shooting), or 2 (magic). 3 (melee)
NPCID.Sets.AttackTime[npc.type] = 30; //this defines the npc attack speed
NPCID.Sets.AttackAverageChance[npc.type] = 10;//this defines the npc atack chance
NPCID.Sets.HatOffsetY[npc.type] = 4; //this defines the party hat position
animationType = NPCID.Guide; //this copy the guide animation
}
public override bool CanTownNPCSpawn(int numTownNPCs, int money) //Whether or not the conditions have been met for this town NPC to be able to move into town.
{
if (NPC.downedBoss2) //so after the wof is killed
{
return true;
}
return true;// ussely its false
}
public override bool CheckConditions(int left, int right, int top, int bottom) //Allows you to define special conditions required for this town NPC's house
{
return true; //so when a house is available the npc will spawn
}
public override string TownNPCName() //Allows you to give this town NPC any name when it spawns
{
switch (WorldGen.genRand.Next(4))
{
case 0:
return "Hermes Trismegistus";
case 1:
return "Ostanes";
case 2:
return "Nicolas Flamel";
default:
return "Perenelle Flamel";
}
}
public override void SetChatButtons(ref string button, ref string button2) //Allows you to set the text for the buttons that appear on this town NPC's chat window.
{
button = "Buy Potions"; //this defines the buy button name
}
public override void OnChatButtonClicked(bool firstButton, ref bool openShop) //Allows you to make something happen whenever a button is clicked on this town NPC's chat window. The firstButton parameter tells whether the first button or second button (button and button2 from SetChatButtons) was clicked. Set the shop parameter to true to open this NPC's shop.
{
if (firstButton)
{
openShop = true; //so when you click on buy button opens the shop
}
}
public override void SetupShop(Chest shop, ref int nextSlot) //Allows you to add items to this town NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot.
{
if (NPC.downedBoss2) //this make so when the WOF is killed the town npc will sell this
{
shop.item[nextSlot].SetDefaults(ItemID.SwiftnessPotion); //an example of how to add a vanilla terraria item
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.IronskinPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.RegenerationPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.GillsPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.AmmoReservationPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.ArcheryPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.ManaRegenerationPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.MagicPowerPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.BattlePotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.CalmingPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.BuilderPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.CratePotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.FishingPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.FlipperPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.EndurancePotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.RagePotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.HeartreachPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.HunterPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.InfernoPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.LifeforcePotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.InvisibilityPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.MiningPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.WrathPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.SpelunkerPotion);
nextSlot++;
shop.item[nextSlot].SetDefaults(ItemID.SummoningPotion);
nextSlot++;
}
if (NPC.downedBoss3) //this make so when Skeletron is killed the town npc will sell this
{
shop.item[nextSlot].SetDefaults(ItemID.ThornsPotion);
nextSlot++;
}
}
public override string GetChat() //Allows you to give this town NPC a chat message when a player talks to it.
{
switch (Main.rand.Next(4)) //this are the messages when you talk to the npc
{
case 0:
return "Did you know that gold is the perfact material?";
case 1:
return "I will find the recipe for immortality!";
case 2:
return "What is that you seak?";
case 3:
return "Let me tell you a secret...";
default:
return "Gold is happiness";
}
}
public override void TownNPCAttackStrength(ref int damage, ref float knockback)// Allows you to determine the damage and knockback of this town NPC attack
{
damage = 40; //npc damage
knockback = 2f; //npc knockback
}
public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown) //Allows you to determine the cooldown between each of this town NPC's attack. The cooldown will be a number greater than or equal to the first parameter, and less then the sum of the two parameters.
{
cooldown = 5;
randExtraCooldown = 10;
}
//------------------------------------This is an example of how to make the npc use a sward attack-------------------------------
public override void DrawTownAttackSwing(ref Texture2D item, ref int itemSize, ref float scale, ref Vector2 offset)//Allows you to customize how this town NPC's weapon is drawn when this NPC is swinging it (this NPC must have an attack type of 3). Item is the Texture2D instance of the item to be drawn (use Main.itemTexture[id of item]), itemSize is the width and height of the item's hitbox
{
scale = 1f;
item = Main.itemTexture[mod.ItemType("CustomSword")]; //this defines the item that this npc will use
itemSize = 56;
}
public override void TownNPCAttackSwing(ref int itemWidth, ref int itemHeight) // Allows you to determine the width and height of the item this town NPC swings when it attacks, which controls the range of this NPC's swung weapon.
{
itemWidth = 56;
itemHeight = 56;
}
}
}
Last edited: