Terraria.ModLoader.GlobalNPC

This class allows you to modify and use hooks for all NPCs, including vanilla mobs. Create an instance of an overriding class then call Mod.AddGlobalNPC to use this.

Methods

Autoload(System.String@)()
Allows you to automatically load a GlobalNPC instead of using Mod.AddGlobalNPC. Return true to allow autoloading; by default returns the mod's autoload property. Name is initialized to the overriding class name. Use this method to either force or stop an autoload or to control the internal name.
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(Terraria.NPC)()
Allows you to set the properties of any and every NPC that gets created.
ScaleExpertStats(Terraria.NPC,System.Int32,System.Single)()
Allows you to customize an NPC's stats in expert mode.
ResetEffects(Terraria.NPC)()
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.
PreAI(Terraria.NPC)()
Allows you to determine how any NPC behaves. Return false to stop the vanilla AI and the AI hook from being run. Returns true by default.
AI(Terraria.NPC)()
Allows you to determine how any NPC behaves. This will only be called if PreAI returns true.
PostAI(Terraria.NPC)()
Allows you to determine how any NPC behaves. This will be called regardless of what PreAI returns.
FindFrame(Terraria.NPC,System.Int32)()
Allows you to modify the frame from an NPC's texture that is drawn, which is necessary in order to animate NPCs.
HitEffect(Terraria.NPC,System.Int32,System.Double)()
Allows you to make things happen whenever an NPC is hit, such as creating dust or gores.
UpdateLifeRegen(Terraria.NPC,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(Terraria.NPC)()
Whether or not to run the code for checking whether an NPC will remain active. Return false to stop the NPC from being despawned and to stop the NPC from counting towards the limit for how many NPCs can exist near a player. Returns true by default.
CheckDead(Terraria.NPC)()
Whether or not an 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 the NPC from being killed. Returns true by default.
SpecialNPCLoot(Terraria.NPC)()
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(Terraria.NPC)()
Allows you to determine whether or not the NPC will drop anything at all. Return false to stop the NPC from dropping anything. Returns true by default.
NPCLoot(Terraria.NPC)()
Allows you to add drops to an NPC when it dies.
CanHitPlayer(Terraria.NPC,Terraria.Player,System.Int32@)()
Allows you to determine whether an NPC can hit the given player. Return false to block the 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.NPC,Terraria.Player,System.Int32@,System.Boolean@)()
Allows you to modify the damage, etc., that an NPC does to a player.
OnHitPlayer(Terraria.NPC,Terraria.Player,System.Int32,System.Boolean)()
Allows you to create special effects when an NPC hits a player (for example, inflicting debuffs).
CanHitNPC(Terraria.NPC,Terraria.NPC)()
Allows you to determine whether an NPC can hit the given friendly NPC. Return true to allow hitting the target, return false to block the 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,Terraria.NPC,System.Int32@,System.Single@,System.Boolean@)()
Allows you to modify the damage, knockback, etc., that an NPC does to a friendly NPC.
OnHitNPC(Terraria.NPC,Terraria.NPC,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when an NPC hits a friendly NPC.
CanBeHitByItem(Terraria.NPC,Terraria.Player,Terraria.Item)()
Allows you to determine whether an 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.NPC,Terraria.Player,Terraria.Item,System.Int32@,System.Single@,System.Boolean@)()
Allows you to modify the damage, knockback, etc., that an NPC takes from a melee weapon.
OnHitByItem(Terraria.NPC,Terraria.Player,Terraria.Item,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when an NPC is hit by a melee weapon.
CanBeHitByProjectile(Terraria.NPC,Terraria.Projectile)()
Allows you to determine whether an 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.NPC,Terraria.Projectile,System.Int32@,System.Single@,System.Boolean@,System.Int32@)()
Allows you to modify the damage, knockback, etc., that an NPC takes from a projectile.
OnHitByProjectile(Terraria.NPC,Terraria.Projectile,System.Int32,System.Single,System.Boolean)()
Allows you to create special effects when an NPC is hit by a projectile.
StrikeNPC(Terraria.NPC,System.Double@,System.Int32,System.Single@,System.Int32,System.Boolean@)()
Allows you to use a custom damage formula for when an 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(Terraria.NPC,System.Int32@)()
Allows you to customize the boss head texture used by an NPC based on its state.
BossHeadRotation(Terraria.NPC,System.Single@)()
Allows you to customize the rotation of an NPC's boss head icon on the map.
BossHeadSpriteEffects(Terraria.NPC,Microsoft.Xna.Framework.Graphics.SpriteEffects@)()
Allows you to flip an NPC's boss head icon on the map.
GetAlpha(Terraria.NPC,Microsoft.Xna.Framework.Color)()
Allows you to determine the color and transparency in which an NPC is drawn. Return null to use the default color (normally light and buff color). Returns null by default.
DrawEffects(Terraria.NPC,Microsoft.Xna.Framework.Color@)()
Allows you to add special visual effects to an NPC (such as creating dust), and modify the color in which the NPC is drawn.
PreDraw(Terraria.NPC,Microsoft.Xna.Framework.Graphics.SpriteBatch,Microsoft.Xna.Framework.Color)()
Allows you to draw things behind an NPC, or to modify the way the 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(Terraria.NPC,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(Terraria.NPC,System.Byte,System.Single@,Microsoft.Xna.Framework.Vector2@)()
Allows you to control how the health bar for the given 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).
EditSpawnRate(Terraria.Player,System.Int32@,System.Int32@)()
Allows you to modify the chance of NPCs spawning around the given player and the maximum number of NPCs that can spawn around the player. Lower spawnRates mean a higher chance for NPCs to spawn.
EditSpawnRange(Terraria.Player,System.Int32@,System.Int32@,System.Int32@,System.Int32@)()
Allows you to modify the range at which NPCs can spawn around the given player. The spawnRanges determine that maximum distance NPCs can spawn from the player, and the safeRanges determine the minimum distance.
EditSpawnPool(System.Collections.Generic.IDictionary{System.Int32,System.Single},Terraria.ModLoader.NPCSpawnInfo)()
Allows you to control which NPCs can spawn and how likely each one is to spawn. The pool parameter maps NPC types to their spawning weights (likelihood to spawn compared to other NPCs). A type of 0 in the pool represents the default vanilla NPC spawning.
SpawnNPC(System.Int32,System.Int32,System.Int32)()
Allows you to customize an NPC (for example, its position or ai array) after it naturally spawns and before it is synced between servers and clients. As of right now, this only works for modded NPCs.
CanChat(Terraria.NPC)()
Allows you to determine whether this NPC can talk with the player. Return true to allow talking with the player, return false to block this NPC from talking with the player, and return null to use the vanilla code for whether the NPC can talk. Returns null by default.
GetChat(Terraria.NPC,System.String@)()
Allows you to modify the chat message of any NPC that the player can talk to.
PreChatButtonClicked(Terraria.NPC,System.Boolean)()
Allows you to determine if something can 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. Return false to prevent the normal code for this button from running. Returns true by default.
OnChatButtonClicked(Terraria.NPC,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.
SetupShop(System.Int32,Terraria.Chest,System.Int32@)()
Allows you to add items to an NPC's shop. The type parameter is the type of the NPC that this shop belongs to. 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. If you want to remove an item, you will have to be familiar with programming.
SetupTravelShop(System.Int32[],System.Int32@)()
Allows you to add items to the traveling merchant's shop. Add an item by setting shop[nextSlot] to the ID of the item you are adding then incrementing nextSlot. In the end, nextSlot must have a value of 1 greater than the highest index in shop that represents an item ID. If you want to remove an item, you will have to be familiar with programming.
BuffTownNPC(System.Single@,System.Int32@)()
Allows you to modify the stats of town NPCs. Useful for buffing town NPCs when certain bosses are defeated, etc.
TownNPCAttackStrength(Terraria.NPC,System.Int32@,System.Single@)()
Allows you to determine the damage and knockback of a town NPC's attack before the damage is scaled. (More information on scaling in GlobalNPC.BuffTownNPCs.)
TownNPCAttackCooldown(Terraria.NPC,System.Int32@,System.Int32@)()
Allows you to determine the cooldown between each of a 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(Terraria.NPC,System.Int32@,System.Int32@)()
Allows you to determine the projectile type of a 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(Terraria.NPC,System.Single@,System.Single@,System.Single@)()
Allows you to determine the speed at which a 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(Terraria.NPC,System.Boolean@)()
Allows you to tell the game that a 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(Terraria.NPC,System.Single@)()
Allows you to control the brightness of the light emitted by a town NPC's aura when it performs a magic attack. Only used when the town NPC has an attack type of 2 (magic)
TownNPCAttackSwing(Terraria.NPC,System.Int32@,System.Int32@)()
Allows you to determine the width and height of the item a town NPC swings when it attacks, which controls the range of the NPC's swung weapon. Only used when the town NPC has an attack type of 3 (swinging).
DrawTownAttackGun(Terraria.NPC,System.Single@,System.Int32@,System.Int32@)()
Allows you to customize how a town NPC's weapon is drawn when the NPC is shooting (the 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(Terraria.NPC,Microsoft.Xna.Framework.Graphics.Texture2D@,System.Int32@,System.Single@,Microsoft.Xna.Framework.Vector2@)()
Allows you to customize how a town NPC's weapon is drawn when the NPC is swinging it (the 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.