Terraria.ModLoader.ModNPC

This class serves as a place for you to place all your properties and hooks for each NPC. Create instances of ModNPC (preferably overriding this class) to pass as parameters to Mod.AddNPC.

Methods

#ctor()
ModNPC constructor.
Autoload(System.String@)()
Allows you to automatically load an NPC instead of using Mod.AddNPC. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name, texture is initialized to the namespace and overriding class name with periods replaced with slashes, and altTextures is initialized to null. Use this method to either force or stop an autoload, or to change the default display name.
Clone()
Returns a clone of this ModNPC. Allows you to decide which fields of your ModNPC class are copied over when a new NPC is created. By default this will return a memberwise clone; you will want to override this if your GlobalNPC contains object references. Only called if CloneNewInstances is set to true.
NewInstance(Terraria.NPC)()
Create a new instance of this GlobalNPC for an NPC instance. Called at the end of NPC.SetDefaults. If CloneNewInstances is true, just calls Clone() Otherwise calls the default constructor and copies fields
SetDefaults()
Allows you to set all your NPC's properties, such as width, damage, aiStyle, lifeMax, etc.
SetStaticDefaults()
Allows you to set all your NPC's static properties, such as names/translations and the arrays in NPCID.Sets.
AutoStaticDefaults()
Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.
ScaleExpertStats(System.Int32,System.Single)()
Allows you to customize this NPC's stats in expert mode. This is useful because expert mode's doubling of damage and life might be too much sometimes (for example, with bosses). Also useful for scaling life with the number of players in the world.
ResetEffects()
This is where you reset any fields you add to your subclass to their default states. This is necessary in order to reset your fields if they are conditionally set by a tick update but the condition is no longer satisfied. (Note: This hook is only really useful for GlobalNPC, but is included in ModNPC for completion.)
PreAI()
Allows you to determine how this NPC behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default.
AI()
Allows you to determine how this NPC behaves. This will only be called if PreAI returns true.
SendExtraAI(System.IO.BinaryWriter)()
If you are storing AI information outside of the npc.ai array, use this to send that AI information between clients and servers.
ReceiveExtraAI(System.IO.BinaryReader)()
Use this to receive information that was sent in SendExtraAI.
FindFrame(System.Int32)()
Allows you to modify the frame from this NPC's texture that is drawn, which is necessary in order to animate NPCs.
HitEffect(System.Int32,System.Double)()
Allows you to make things happen whenever this NPC is hit, such as creating dust or gores.
UpdateLifeRegen(System.Int32@)()
Allows you to make the NPC either regenerate health or take damage over time by setting npc.lifeRegen. Regeneration or damage will occur at a rate of half of npc.lifeRegen per second. The damage parameter is the number that appears above the NPC's head if it takes damage over time.
CheckActive()
Whether or not to run the code for checking whether this NPC will remain active. Return false to stop this NPC from being despawned and to stop this NPC from counting towards the limit for how many NPCs can exist near a player. Returns true by default.
CheckDead()
Whether or not this NPC should be killed when it reaches 0 health. You may program extra effects in this hook (for example, how Golem's head lifts up for the second phase of its fight). Return false to stop this NPC from being killed. Returns true by default.
SpecialNPCLoot()
Allows you to call NPCLoot on your own when the NPC dies, rather then letting vanilla call it on its own. Useful for things like dropping loot from the nearest segment of a worm boss. Returns false by default.
PreNPCLoot()
Allows you to determine whether or not this NPC will drop anything at all. Return false to stop the NPC from dropping anything. Returns true by default.
NPCLoot()
Allows you to make things happen when this NPC dies (for example, dropping items).
BossLoot(System.String@,System.Int32@)()
Allows you to customize what happens when this boss dies, such as which name is displayed in the defeat message and what type of potion it drops.
CanHitPlayer(Terraria.Player,System.Int32@)()
Allows you to determine whether this NPC can hit the given player. Return false to block this NPC from hitting the target. Returns true by default. CooldownSlot determines which of the player's cooldown counters to use (-1, 0, or 1), and defaults to -1.
ModifyHitPlayer(Terraria.Player,System.Int32@,System.Boolean@)()
Allows you to modify the damage, etc., that this NPC does to a player.
OnHitPlayer(Terraria.Player,System.Int32,System.Boolean)()
Allows you to create special effects when this NPC hits a player (for example, inflicting debuffs).
CanHitNPC(Terraria.NPC)()
Allows you to determine whether this NPC can hit the given friendly NPC. Return true to allow hitting the target, return false to block this NPC from hitting the target, and return null to use the vanilla code for whether the target can be hit. Returns null by default.
ModifyHitNPC(Terraria.NPC,System.Int32@,System.Single@,System.Boolean@)()
Allows you to modify the damage, knockback, etc., that this NPC does to a friendly NPC.
OnHitNPC(Terraria.NPC,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when this NPC hits a friendly NPC.
CanBeHitByItem(Terraria.Player,Terraria.Item)()
Allows you to determine whether this NPC can be hit by the given melee weapon when swung. Return true to allow hitting the NPC, return false to block hitting the NPC, and return null to use the vanilla code for whether the NPC can be hit. Returns null by default.
ModifyHitByItem(Terraria.Player,Terraria.Item,System.Int32@,System.Single@,System.Boolean@)()
Allows you to modify the damage, knockback, etc., that this NPC takes from a melee weapon.
OnHitByItem(Terraria.Player,Terraria.Item,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when this NPC is hit by a melee weapon.
CanBeHitByProjectile(Terraria.Projectile)()
Allows you to determine whether this NPC can be hit by the given projectile. Return true to allow hitting the NPC, return false to block hitting the NPC, and return null to use the vanilla code for whether the NPC can be hit. Returns null by default.
ModifyHitByProjectile(Terraria.Projectile,System.Int32@,System.Single@,System.Boolean@,System.Int32@)()
Allows you to modify the damage, knockback, etc., that this NPC takes from a projectile.
OnHitByProjectile(Terraria.Projectile,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when this NPC is hit by a projectile.
StrikeNPC(System.Double@,System.Int32,System.Single@,System.Int32,System.Boolean@)()
Allows you to use a custom damage formula for when this NPC takes damage from any source. For example, you can change the way defense works or use a different crit multiplier. Return false to stop the game from running the vanilla damage formula; returns true by default.
BossHeadSlot(System.Int32@)()
Allows you to customize the boss head texture used by this NPC based on its state.
BossHeadRotation(System.Single@)()
Allows you to customize the rotation of this NPC's boss head icon on the map.
BossHeadSpriteEffects(Microsoft.Xna.Framework.Graphics.SpriteEffects@)()
Allows you to flip this NPC's boss head icon on the map.
GetAlpha(Microsoft.Xna.Framework.Color)()
Allows you to determine the color and transparency in which this NPC is drawn. Return null to use the default color (normally light and buff color). Returns null by default.
DrawEffects(Microsoft.Xna.Framework.Color@)()
Allows you to add special visual effects to this NPC (such as creating dust), and modify the color in which the NPC is drawn.
PreDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Color)()
Allows you to draw things behind this NPC, or to modify the way this NPC is drawn. Return false to stop the game from drawing the NPC (useful if you're manually drawing the NPC). Returns true by default.
PostDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Color)()
Allows you to draw things in front of this NPC. This method is called even if PreDraw returns false.
DrawHealthBar(System.Byte,System.Single@,Microsoft.Xna.Framework.Vector2@)()
Allows you to control how the health bar for this NPC is drawn. The hbPosition parameter is the same as Main.hbPosition; it determines whether the health bar gets drawn above or below the NPC by default. The scale parameter is the health bar's size. By default, it will be the normal 1f; most bosses set this to 1.5f. Return null to let the normal vanilla health-bar-drawing code to run. Return false to stop the health bar from being drawn. Return true to draw the health bar in the position specified by the position parameter (note that this is the world position, not screen position).
SpawnChance(Terraria.ModLoader.NPCSpawnInfo)()
Whether or not this NPC can spawn with the given spawning conditions. Return the weight for the chance of this NPC to spawn compared to vanilla mobs. All vanilla mobs combined have a total weight of 1. Returns 0 by default, which disables natural spawning. Remember to always use spawnInfo.player and not Main.LocalPlayer when checking Player or ModPlayer fields, otherwise your mod won't work in Multiplayer.
SpawnNPC(System.Int32,System.Int32)()
Allows you to customize how this NPC is created when it naturally spawns (for example, its position or ai array). Return the return value of NPC.NewNPC. By default this method spawns this NPC on top of the tile at the given coordinates.
CanTownNPCSpawn(System.Int32,System.Int32)()
Whether or not the conditions have been met for this town NPC to be able to move into town. For example, the Demolitionist requires that any player has an explosive.
CheckConditions(System.Int32,System.Int32,System.Int32,System.Int32)()
Allows you to define special conditions required for this town NPC's house. For example, Truffle requires the house to be in an aboveground mushroom biome.
TownNPCName()
Allows you to give this town NPC any name when it spawns. By default returns something embarrassing.
UsesPartyHat()
Allows you to determine whether this town NPC wears a party hat during a party. Returns true by default.
CanChat()
Allows you to determine whether this NPC can talk with the player. By default, returns if the NPC is a town NPC.
GetChat()
Allows you to give this NPC a chat message when a player talks to it. By default returns something embarrassing.
SetChatButtons(System.String@,System.String@)()
Allows you to set the text for the buttons that appear on this NPC's chat window. A parameter left as an empty string will not be included as a button on the chat window.
OnChatButtonClicked(System.Boolean,System.Boolean@)()
Allows you to make something happen whenever a button is clicked on this 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.
SetupShop(Terraria.Chest,System.Int32@)()
Allows you to add items to this NPC's shop. Add an item by setting the defaults of shop.item[nextSlot] then incrementing nextSlot. In the end, nextSlot must have a value of 1 greater than the highest index in shop.item that contains an item.
TownNPCAttackStrength(System.Int32@,System.Single@)()
Allows you to determine the damage and knockback of this town NPC's attack before the damage is scaled. (More information on scaling in GlobalNPC.BuffTownNPCs.)
TownNPCAttackCooldown(System.Int32@,System.Int32@)()
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.
TownNPCAttackProj(System.Int32@,System.Int32@)()
Allows you to determine the projectile type of this town NPC's attack, and how long it takes for the projectile to actually appear. This hook is only used when the town NPC has an attack type of 0 (throwing), 1 (shooting), or 2 (magic).
TownNPCAttackProjSpeed(System.Single@,System.Single@,System.Single@)()
Allows you to determine the speed at which this town NPC throws a projectile when it attacks. Multiplier is the speed of the projectile, gravityCorrection is how much extra the projectile gets thrown upwards, and randomOffset allows you to randomize the projectile's velocity in a square centered around the original velocity. This hook is only used when the town NPC has an attack type of 0 (throwing), 1 (shooting), or 2 (magic).
TownNPCAttackShoot(System.Boolean@)()
Allows you to tell the game that this town NPC has already created a projectile and will still create more projectiles as part of a single attack so that the game can animate the NPC's attack properly. Only used when the town NPC has an attack type of 1 (shooting).
TownNPCAttackMagic(System.Single@)()
Allows you to control the brightness of the light emitted by this town NPC's aura when it performs a magic attack. Only used when the town NPC has an attack type of 2 (magic)
TownNPCAttackSwing(System.Int32@,System.Int32@)()
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. Only used when the town NPC has an attack type of 3 (swinging).
DrawTownAttackGun(System.Single@,System.Int32@,System.Int32@)()
Allows you to customize how this town NPC's weapon is drawn when this NPC is shooting (this NPC must have an attack type of 1). Scale is a multiplier for the item's drawing size, item is the ID of the item to be drawn, and closeness is how close the item should be drawn to the NPC.
DrawTownAttackSwing(Microsoft.Xna.Framework.Graphics.Texture2D@,System.Int32@,System.Single@,Microsoft.Xna.Framework.Vector2@)()
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 (the same values for TownNPCAttackSwing), scale is the multiplier for the item's drawing size, and offset is the offset from which to draw the item from its normal position.