tModLoader v2024.02
A mod to make and play Terraria mods
GlobalNPC Class Reference

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. More...

Inherits GlobalType< NPC, GlobalNPC >.

Inherited by PylonShopNPC, and UnloadedGlobalNPC.

Public Member Functions

virtual void AI (NPC npc)
 Allows you to determine how any NPC behaves. This will only be called if PreAI returns true. More...
 
virtual void ApplyDifficultyAndPlayerScaling (NPC npc, int numPlayers, float balance, float bossAdjustment)
 Allows you to customize this NPC's stats when the difficulty is expert or higher.
This runs after NPC.value, NPC.lifeMax, NPC.damage, NPC.knockBackResist have been adjusted for the current difficulty, (expert/master/FTW)
It is common to multiply lifeMax by the balance factor, and sometimes adjust knockbackResist.

Eg:
More...
 
virtual void BossHeadRotation (NPC npc, ref float rotation)
 Allows you to customize the rotation of an NPC's boss head icon on the map. More...
 
virtual void BossHeadSlot (NPC npc, ref int index)
 Allows you to customize the boss head texture used by an NPC based on its state. Set index to -1 to stop the texture from being displayed. More...
 
virtual void BossHeadSpriteEffects (NPC npc, ref SpriteEffects spriteEffects)
 Allows you to flip an NPC's boss head icon on the map. More...
 
virtual void BuffTownNPC (ref float damageMult, ref int defense)
 Allows you to modify the stats of town NPCs. Useful for buffing town NPCs when certain bosses are defeated, etc. More...
 
virtual ? bool CanBeCaughtBy (NPC npc, Item item, Player player)
 Allows you to determine whether the given item can catch the given NPC.
Return true or false to say the given NPC can or cannot be caught, respectively, regardless of vanilla rules.
Returns null by default, which allows vanilla's NPC catching rules to decide the target's fate.
If this returns false, CombinedHooks.OnCatchNPC is never called.

NOTE: this does not classify the given item as an NPC-catching tool, which is necessary for catching NPCs in the first place.
To do that, you will need to use the "CatchingTool" set in ItemID.Sets. More...
 
virtual ? bool CanBeHitByItem (NPC npc, Player player, Item 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. More...
 
virtual bool CanBeHitByNPC (NPC npc, NPC attacker)
 Allows you to determine whether a friendly NPC can be hit by an NPC. Return false to block the attacker from hitting the NPC, and return true to use the vanilla code for whether the target can be hit. Returns true by default. More...
 
virtual ? bool CanBeHitByProjectile (NPC npc, Projectile 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. More...
 
virtual ? bool CanChat (NPC 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. More...
 
virtual ? bool CanCollideWithPlayerMeleeAttack (NPC npc, Player player, Item item, Rectangle meleeAttackHitbox)
 Allows you to determine whether an NPC can be collided with the player melee weapon when swung.
Use CanBeHitByItem(NPC, Player, Item) instead for Guide Voodoo Doll-type effects. More...
 
virtual ? bool CanFallThroughPlatforms (NPC npc)
 Allows you to determine how and when an NPC can fall through platforms and similar tiles.
Return true to allow an NPC to fall through platforms, false to prevent it. Returns null by default, applying vanilla behaviors (based on aiStyle and type).
 
virtual ? bool CanGoToStatue (NPC npc, bool toKingStatue)
 Whether this NPC can be teleported to a King or Queen statue. Return true to allow the NPC to teleport to the statue, return false to block this NPC from teleporting to the statue, and return null to use the vanilla code for whether the NPC can teleport to the statue. Returns null by default. More...
 
virtual bool CanHitNPC (NPC npc, NPC target)
 Allows you to determine whether an NPC can hit the given friendly NPC. Return false to block the NPC from hitting the target, and return true to use the vanilla code for whether the target can be hit. Returns true by default. More...
 
virtual bool CanHitPlayer (NPC npc, Player target, ref int cooldownSlot)
 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 (ImmunityCooldownID) to use, and defaults to -1 (ImmunityCooldownID.General). More...
 
virtual bool CheckActive (NPC 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. More...
 
virtual bool CheckDead (NPC 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. More...
 
virtual void DrawBehind (NPC npc, int index)
 When used in conjunction with "npc.hide = true", allows you to specify that this npc should be drawn behind certain elements. Add the index to one of Main.DrawCacheNPCsMoonMoon, DrawCacheNPCsOverPlayers, DrawCacheNPCProjectiles, or DrawCacheNPCsBehindNonSolidTiles. More...
 
virtual void DrawEffects (NPC npc, ref Color drawColor)
 Allows you to add special visual effects to an NPC (such as creating dust), and modify the color in which the NPC is drawn. More...
 
virtual ? bool DrawHealthBar (NPC npc, byte hbPosition, ref float scale, ref Vector2 position)
 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). More...
 
virtual void DrawTownAttackGun (NPC npc, ref Texture2D item, ref Rectangle itemFrame, ref float scale, ref int horizontalHoldoutOffset)
 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 Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, and horizontalHoldoutOffset is how far away the item should be drawn from the NPC. More...
 
virtual void DrawTownAttackSwing (NPC npc, ref Texture2D item, ref Rectangle itemFrame, ref int itemSize, ref float scale, ref Vector2 offset)
 
virtual void EditSpawnPool (IDictionary< int, float > pool, NPCSpawnInfo spawnInfo)
 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. More...
 
virtual void EditSpawnRange (Player player, ref int spawnRangeX, ref int spawnRangeY, ref int safeRangeX, ref int safeRangeY)
 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. More...
 
virtual void EditSpawnRate (Player player, ref int spawnRate, ref int maxSpawns)
 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. More...
 
virtual void FindFrame (NPC npc, int frameHeight)
 Allows you to modify the frame from an NPC's texture that is drawn, which is necessary in order to animate NPCs. More...
 
virtual ? Color GetAlpha (NPC npc, Color drawColor)
 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. More...
 
virtual void GetChat (NPC npc, ref string chat)
 Allows you to modify the chat message of any NPC that the player can talk to. More...
 
virtual void HitEffect (NPC npc, NPC.HitInfo hit)
 Allows you to make things happen whenever an NPC is hit, such as creating dust or gores.
Called on local, server and remote clients.
Usually when something happens when an npc dies such as item spawning, you use NPCLoot, but you can use HitEffect paired with a check for if (npc.life <= 0) to do client-side death effects, such as spawning dust, gore, or death sounds.

 
virtual void LoadData (NPC npc, TagCompound tag)
 Allows you to load custom data that you have saved for the given npc. More...
 
virtual void ModifyActiveShop (NPC npc, string shopName, Item[] items)
 Allows you to modify the contents of a shop whenever player opens it.
If possible, use ModifyShop(NPCShop) instead, to reduce mod conflicts and improve compatibility. Note that for special shops like travelling merchant, the shopName may not correspond to a NPCShop in the NPCShopDatabase More...
 
virtual bool ModifyCollisionData (NPC npc, Rectangle victimHitbox, ref int immunityCooldownSlot, ref MultipliableFloat damageMultiplier, ref Rectangle npcHitbox)
 Allows you to modify the NPC's

See also
ID.ImmunityCooldownID

, damage multiplier, and hitbox. Useful for implementing dynamic damage hitboxes that change in dimensions or deal extra damage. Returns false to prevent vanilla code from running. Returns true by default. More...

 
virtual void ModifyGlobalLoot (GlobalLoot globalLoot)
 Allows you to add and modify global loot rules that are conditional, i.e. vanilla's biome keys and souls.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify npc loot. More...
 
virtual void ModifyHitByItem (NPC npc, Player player, Item item, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that an NPC takes from a melee weapon.
Runs on the local client.
More...
 
virtual void ModifyHitByProjectile (NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that an NPC takes from a projectile. More...
 
virtual void ModifyHitNPC (NPC npc, NPC target, ref NPC.HitModifiers modifiers)
 Allows you to modify the damage, knockback, etc., that an NPC does to a friendly NPC. More...
 
virtual void ModifyHitPlayer (NPC npc, Player target, ref Player.HurtModifiers modifiers)
 Allows you to modify the damage, etc., that an NPC does to a player. More...
 
virtual void ModifyHoverBoundingBox (NPC npc, ref Rectangle boundingBox)
 Allows you to modify the bounding box for hovering over the given NPC (affects things like whether or not its name is displayed). More...
 
virtual void ModifyIncomingHit (NPC npc, ref NPC.HitModifiers modifiers)
 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. More...
 
virtual void ModifyNPCLoot (NPC npc, NPCLoot npcLoot)
 Allows you to add and modify NPC loot tables to drop on death and to appear in the Bestiary.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify npc loot.
This hook only runs once per npc type during mod loading, any dynamic behavior must be contained in the rules themselves. More...
 
virtual void ModifyNPCNameList (NPC npc, List< string > nameList)
 Allows you to modify the list of names available to the given town NPC.
 
virtual void ModifyShop (NPCShop shop)
 Allows you to modify existing shop. Be aware that this hook is called just one time during loading. More...
 
virtual ITownNPCProfile ModifyTownNPCProfile (NPC npc)
 Allows you to set the town NPC profile that a given NPC uses. More...
 
virtual void ModifyTypeName (NPC npc, ref string typeName)
 Allows you to modify the type name of this NPC dynamically.
 
virtual bool NeedSaving (NPC npc)
 Allows you to make a npc be saved even if it's not a townNPC and NPCID.Sets.SavesAndLoads[npc.type] is false.
NOTE: A town NPC will always be saved (except the Travelling Merchant that never will).
NOTE: A NPC that needs saving will not despawn naturally. More...
 
virtual void OnCaughtBy (NPC npc, Player player, Item item, bool failed)
 Allows you to make things happen when the given item attempts to catch the given NPC. More...
 
virtual void OnChatButtonClicked (NPC npc, bool firstButton)
 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. More...
 
virtual void OnGoToStatue (NPC npc, bool toKingStatue)
 Allows you to make things happen when this NPC teleports to a King or Queen statue. This method is only called server side. More...
 
virtual void OnHitByItem (NPC npc, Player player, Item item, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when an NPC is hit by a melee weapon. More...
 
virtual void OnHitByProjectile (NPC npc, Projectile projectile, NPC.HitInfo hit, int damageDone)
 Allows you to create special effects when an NPC is hit by a projectile. More...
 
virtual void OnHitNPC (NPC npc, NPC target, NPC.HitInfo hit)
 Allows you to create special effects when an NPC hits a friendly NPC. More...
 
virtual void OnHitPlayer (NPC npc, Player target, Player.HurtInfo hurtInfo)
 Allows you to create special effects when an NPC hits a player (for example, inflicting debuffs).
Only runs on the local client in multiplayer. More...
 
virtual void OnKill (NPC npc)
 Allows you to make things happen when an NPC dies (for example, setting ModSystem fields). This hook runs on the server/single player. For client-side effects, such as dust, gore, and sounds, see HitEffect More...
 
virtual void OnSpawn (NPC npc, IEntitySource source)
 Gets called when any NPC spawns in world
 
virtual ? int PickEmote (NPC npc, Player closestPlayer, List< int > emoteList, WorldUIAnchor otherAnchor)
 Allows you to change the emote that the NPC will pick More...
 
virtual void PostAI (NPC npc)
 Allows you to determine how any NPC behaves. This will be called regardless of what PreAI returns. More...
 
virtual void PostDraw (NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 Allows you to draw things in front of this NPC. Substract screenPos from the draw position before drawing. This method is called even if PreDraw returns false. More...
 
virtual bool PreAI (NPC 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. More...
 
virtual bool PreChatButtonClicked (NPC npc, bool firstButton)
 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. More...
 
virtual bool PreDraw (NPC npc, SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
 Allows you to draw things behind an NPC, or to modify the way the NPC is drawn. Substract screenPos from the draw position before drawing. Return false to stop the game from drawing the NPC (useful if you're manually drawing the NPC). Returns true by default. More...
 
virtual bool PreKill (NPC npc)
 Allows you to determine whether or not NPC from doing anything on death (besides die). Return false to stop the NPC from doing anything special. Returns true by default. More...
 
virtual void ReceiveExtraAI (NPC npc, BitReader bitReader, BinaryReader binaryReader)
 Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncNPC is successfully received.
Can be called on multiplayer clients. More...
 
virtual void ResetEffects (NPC 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. More...
 
virtual void SaveData (NPC npc, TagCompound tag)
 Allows you to save custom data for the given npc.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values.
NOTE: The npc may be saved even if NeedSaving returns false and npc is not a townNPC, if another mod returns true on NeedSaving. More...
 
virtual void SendExtraAI (NPC npc, BitWriter bitWriter, BinaryWriter binaryWriter)
 Use this judiciously to avoid straining the network.
Checks and methods such as GlobalType<TEntity, TGlobal>.AppliesToEntity can reduce how much data must be sent for how many projectiles.
Called whenever MessageID.SyncNPC is successfully sent, for example on NPC creation, on player join, or whenever NPC.netUpdate is set to true in the update loop for that tick.
Can be called on the server. More...
 
virtual void SetBestiary (NPC npc, BestiaryDatabase database, BestiaryEntry bestiaryEntry)
 Allows you to set an NPC's information in the Bestiary. More...
 
virtual void SetDefaultsFromNetId (NPC npc)
 Called after SetDefaults for NPCs with a negative NPC.netID
This hook is required because NPC.SetDefaultsFromNetId only sets NPC.netID after SetDefaults
Remember that NPC.type does not support negative numbers and AppliesToEntity cannot distinguish between NPCs with the same type but differet netID

 
sealed override void SetupContent ()
 
virtual void SetupTravelShop (int[] shop, ref int nextSlot)
 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. More...
 
virtual void SpawnNPC (int npc, int tileX, int tileY)
 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. More...
 
virtual bool SpecialOnKill (NPC npc)
 Allows you to call OnKill on your own when the NPC dies, rather then letting vanilla call it on its own. Returns false by default. More...
 
virtual void TownNPCAttackCooldown (NPC npc, ref int cooldown, ref int randExtraCooldown)
 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. More...
 
virtual void TownNPCAttackMagic (NPC npc, ref float auraLightMultiplier)
 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) More...
 
virtual void TownNPCAttackProj (NPC npc, ref int projType, ref int attackDelay)
 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). More...
 
virtual void TownNPCAttackProjSpeed (NPC npc, ref float multiplier, ref float gravityCorrection, ref float randomOffset)
 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). More...
 
virtual void TownNPCAttackShoot (NPC npc, ref bool inBetweenShots)
 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). More...
 
virtual void TownNPCAttackStrength (NPC npc, ref int damage, ref float knockback)
 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.) More...
 
virtual void TownNPCAttackSwing (NPC npc, ref int itemWidth, ref int itemHeight)
 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). More...
 
virtual void UpdateLifeRegen (NPC npc, ref int damage)
 Allows you to make the NPC either regenerate health or take damage over time by setting NPC.lifeRegen. This is useful for implementing damage over time debuffs such as BuffID.Poisoned or BuffID.OnFire. Regeneration or damage will occur at a rate of half of NPC.lifeRegen per second. Essentially, modders implementing damage over time debuffs should subtract from NPC.lifeRegen a number that is twice as large as the intended damage per second. See DamageOverTimeGlobalNPC.csfor an example of this. The damage parameter is the number that appears above the NPC's head if it takes damage over time. Multiple debuffs work together by following some conventions: NPC.lifeRegen should not be assigned a number, rather it should be subtracted from. damage should only be assigned if the intended popup text is larger then its current value.
More...
 
- Public Member Functions inherited from GlobalType< NPC, GlobalNPC >
virtual bool AppliesToEntity (TEntity entity, bool lateInstantiation)
 Use this to control whether or not this global should be run on the provided entity instance.
More...
 
virtual TGlobal Clone (TEntity? from, TEntity to)
 Create a copy of this instanced global. Called when an entity is cloned. More...
 
TGlobal Instance (TEntity entity)
 
virtual ? TGlobal NewInstance (TEntity target)
 Only called if GlobalType<TGlobal>.InstancePerEntity and AppliesToEntity(target , ...) are both true.

Returning null is permitted but not recommended over AppliesToEntity for performance reasons.
Only return null when the global is disabled based on some runtime property (eg world seed). More...
 
virtual void SetDefaults (TEntity entity)
 Allows you to set the properties of any and every instance that gets created.
 

Protected Member Functions

sealed override void Register ()
 
override void ValidateType ()
 
- Protected Member Functions inherited from GlobalType< NPC, GlobalNPC >
override void Register ()
 If you make a new ModType, seal this override.
 
override void ValidateType ()
 Check for the correct overrides of different hook methods and fields and properties
 

Additional Inherited Members

- Static Public Member Functions inherited from GlobalType< NPC, GlobalNPC >
static TResult GetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals)
 
static TResult GetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, TResult baseInstance)
 
static bool TryGetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, out TResult result)
 
static bool TryGetGlobal< TResult > (int entityType, ReadOnlySpan< TGlobal > entityGlobals, TResult baseInstance, out TResult result)
 
- Properties inherited from GlobalType< NPC, GlobalNPC >
virtual bool CloneNewInstances [get]
 Whether to create new instances of this mod type via Clone or via the default constructor Defaults to false (default constructor).
 
abstract bool ConditionallyAppliesToEntities [get]
 Whether this global applies to some entities but not others
 
sealed override bool ConditionallyAppliesToEntities [get]
 Whether this global applies to some entities but not others.
True if the type overrides AppliesToEntity(TEntity, bool)
 
virtual bool InstancePerEntity [get]
 Whether to create a new instance of this Global for every entity that exists. Useful for storing information on an entity. Defaults to false. Return true if you need to store information (have non-static fields).
 
virtual bool IsCloneable [get]
 Whether or not this type is cloneable. Cloning is supported if
all reference typed fields in each sub-class which doesn't override Clone are marked with [CloneByReference]
 
short PerEntityIndex [get, set]
 Index of this global in a IEntityWithGlobals<TGlobal>.EntityGlobals array
-1 if this global does not have a SlotPerEntity
 
virtual bool SlotPerEntity [get]
 If true, the global will be assigned a PerEntityIndex at load time, which can be used to access the instance in the IEntityWithGlobals<TGlobal>.EntityGlobals array.
If false, the global will be a singleton applying to all entities
 
short StaticIndex [get, set]
 Index of this global in the list of all globals of the same type, in registration order
 

Detailed Description

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.

Member Function Documentation

◆ AI()

virtual void GlobalNPC.AI ( NPC  npc)
virtual

Allows you to determine how any NPC behaves. This will only be called if PreAI returns true.

Parameters
npc

◆ ApplyDifficultyAndPlayerScaling()

virtual void GlobalNPC.ApplyDifficultyAndPlayerScaling ( NPC  npc,
int  numPlayers,
float  balance,
float  bossAdjustment 
)
virtual

Allows you to customize this NPC's stats when the difficulty is expert or higher.
This runs after NPC.value, NPC.lifeMax, NPC.damage, NPC.knockBackResist have been adjusted for the current difficulty, (expert/master/FTW)
It is common to multiply lifeMax by the balance factor, and sometimes adjust knockbackResist.

Eg:

lifeMax = (int)(lifeMax * balance * bossAdjustment)

Parameters
npcThe newly spawned NPC
numPlayersThe number of active players
balanceScaling factor that increases by a fraction for each player
bossAdjustmentAn extra reduction factor to be applied to boss life in high difficulty modes

◆ BossHeadRotation()

virtual void GlobalNPC.BossHeadRotation ( NPC  npc,
ref float  rotation 
)
virtual

Allows you to customize the rotation of an NPC's boss head icon on the map.

Parameters
npc
rotation

◆ BossHeadSlot()

virtual void GlobalNPC.BossHeadSlot ( NPC  npc,
ref int  index 
)
virtual

Allows you to customize the boss head texture used by an NPC based on its state. Set index to -1 to stop the texture from being displayed.

Parameters
npc
indexThe index for NPCID.Sets.BossHeadTextures

◆ BossHeadSpriteEffects()

virtual void GlobalNPC.BossHeadSpriteEffects ( NPC  npc,
ref SpriteEffects  spriteEffects 
)
virtual

Allows you to flip an NPC's boss head icon on the map.

Parameters
npc
spriteEffects

◆ BuffTownNPC()

virtual void GlobalNPC.BuffTownNPC ( ref float  damageMult,
ref int  defense 
)
virtual

Allows you to modify the stats of town NPCs. Useful for buffing town NPCs when certain bosses are defeated, etc.

Parameters
damageMult
defense

◆ CanBeCaughtBy()

virtual ? bool GlobalNPC.CanBeCaughtBy ( NPC  npc,
Item  item,
Player  player 
)
virtual

Allows you to determine whether the given item can catch the given NPC.
Return true or false to say the given NPC can or cannot be caught, respectively, regardless of vanilla rules.
Returns null by default, which allows vanilla's NPC catching rules to decide the target's fate.
If this returns false, CombinedHooks.OnCatchNPC is never called.

NOTE: this does not classify the given item as an NPC-catching tool, which is necessary for catching NPCs in the first place.
To do that, you will need to use the "CatchingTool" set in ItemID.Sets.

Parameters
npcThe NPC that can potentially be caught.
itemThe item with which the player is trying to catch the given NPC.
playerThe player attempting to catch the given NPC.
Returns

◆ CanBeHitByItem()

virtual ? bool GlobalNPC.CanBeHitByItem ( NPC  npc,
Player  player,
Item  item 
)
virtual

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.

Parameters
npc
player
item
Returns

◆ CanBeHitByNPC()

virtual bool GlobalNPC.CanBeHitByNPC ( NPC  npc,
NPC  attacker 
)
virtual

Allows you to determine whether a friendly NPC can be hit by an NPC. Return false to block the attacker from hitting the NPC, and return true to use the vanilla code for whether the target can be hit. Returns true by default.

Parameters
npc
attacker
Returns

◆ CanBeHitByProjectile()

virtual ? bool GlobalNPC.CanBeHitByProjectile ( NPC  npc,
Projectile  projectile 
)
virtual

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.

Parameters
npc
projectile
Returns

◆ CanChat()

virtual ? bool GlobalNPC.CanChat ( NPC  npc)
virtual

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.

Parameters
npc
Returns

◆ CanCollideWithPlayerMeleeAttack()

virtual ? bool GlobalNPC.CanCollideWithPlayerMeleeAttack ( NPC  npc,
Player  player,
Item  item,
Rectangle  meleeAttackHitbox 
)
virtual

Allows you to determine whether an NPC can be collided with the player melee weapon when swung.
Use CanBeHitByItem(NPC, Player, Item) instead for Guide Voodoo Doll-type effects.

Parameters
playerThe player wielding this item.
itemThe weapon item the player is holding.
meleeAttackHitboxHitbox of melee attack.
Returns
Return true to allow colliding with the melee attack, return false to block the weapon from colliding with the NPC, and return null to use the vanilla code for whether the attack can be colliding. Returns null by default.

◆ CanGoToStatue()

virtual ? bool GlobalNPC.CanGoToStatue ( NPC  npc,
bool  toKingStatue 
)
virtual

Whether this NPC can be teleported to a King or Queen statue. Return true to allow the NPC to teleport to the statue, return false to block this NPC from teleporting to the statue, and return null to use the vanilla code for whether the NPC can teleport to the statue. Returns null by default.

Parameters
npcThe NPC
toKingStatueWhether the NPC is being teleported to a King or Queen statue.

◆ CanHitNPC()

virtual bool GlobalNPC.CanHitNPC ( NPC  npc,
NPC  target 
)
virtual

Allows you to determine whether an NPC can hit the given friendly NPC. Return false to block the NPC from hitting the target, and return true to use the vanilla code for whether the target can be hit. Returns true by default.

Parameters
npc
target
Returns

◆ CanHitPlayer()

virtual bool GlobalNPC.CanHitPlayer ( NPC  npc,
Player  target,
ref int  cooldownSlot 
)
virtual

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 (ImmunityCooldownID) to use, and defaults to -1 (ImmunityCooldownID.General).

Parameters
npc
target
cooldownSlot
Returns

◆ CheckActive()

virtual bool GlobalNPC.CheckActive ( NPC  npc)
virtual

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.

Parameters
npc
Returns

◆ CheckDead()

virtual bool GlobalNPC.CheckDead ( NPC  npc)
virtual

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.

Parameters
npc
Returns

◆ DrawBehind()

virtual void GlobalNPC.DrawBehind ( NPC  npc,
int  index 
)
virtual

When used in conjunction with "npc.hide = true", allows you to specify that this npc should be drawn behind certain elements. Add the index to one of Main.DrawCacheNPCsMoonMoon, DrawCacheNPCsOverPlayers, DrawCacheNPCProjectiles, or DrawCacheNPCsBehindNonSolidTiles.

Parameters
npc
index

◆ DrawEffects()

virtual void GlobalNPC.DrawEffects ( NPC  npc,
ref Color  drawColor 
)
virtual

Allows you to add special visual effects to an NPC (such as creating dust), and modify the color in which the NPC is drawn.

Parameters
npc
drawColor

◆ DrawHealthBar()

virtual ? bool GlobalNPC.DrawHealthBar ( NPC  npc,
byte  hbPosition,
ref float  scale,
ref Vector2  position 
)
virtual

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).

Parameters
npc
hbPosition
scale
position
Returns

◆ DrawTownAttackGun()

virtual void GlobalNPC.DrawTownAttackGun ( NPC  npc,
ref Texture2D  item,
ref Rectangle  itemFrame,
ref float  scale,
ref int  horizontalHoldoutOffset 
)
virtual

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 Texture2D instance of the item to be drawn, itemFrame is the section of the texture to draw, and horizontalHoldoutOffset is how far away the item should be drawn from the NPC.

Parameters
npc
item
itemFrame
scale
horizontalHoldoutOffset

◆ EditSpawnPool()

virtual void GlobalNPC.EditSpawnPool ( IDictionary< int, float >  pool,
NPCSpawnInfo  spawnInfo 
)
virtual

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.

Parameters
pool
spawnInfo

◆ EditSpawnRange()

virtual void GlobalNPC.EditSpawnRange ( Player  player,
ref int  spawnRangeX,
ref int  spawnRangeY,
ref int  safeRangeX,
ref int  safeRangeY 
)
virtual

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.

Parameters
player
spawnRangeX
spawnRangeY
safeRangeX
safeRangeY

◆ EditSpawnRate()

virtual void GlobalNPC.EditSpawnRate ( Player  player,
ref int  spawnRate,
ref int  maxSpawns 
)
virtual

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.

Parameters
player
spawnRate
maxSpawns

◆ FindFrame()

virtual void GlobalNPC.FindFrame ( NPC  npc,
int  frameHeight 
)
virtual

Allows you to modify the frame from an NPC's texture that is drawn, which is necessary in order to animate NPCs.

Parameters
npc
frameHeight

◆ GetAlpha()

virtual ? Color GlobalNPC.GetAlpha ( NPC  npc,
Color  drawColor 
)
virtual

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.

Parameters
npc
drawColor
Returns

◆ GetChat()

virtual void GlobalNPC.GetChat ( NPC  npc,
ref string  chat 
)
virtual

Allows you to modify the chat message of any NPC that the player can talk to.

Parameters
npc
chat

◆ LoadData()

virtual void GlobalNPC.LoadData ( NPC  npc,
TagCompound  tag 
)
virtual

Allows you to load custom data that you have saved for the given npc.

Parameters
npc
tag

Reimplemented in UnloadedGlobalNPC.

◆ ModifyActiveShop()

virtual void GlobalNPC.ModifyActiveShop ( NPC  npc,
string  shopName,
Item[]  items 
)
virtual

Allows you to modify the contents of a shop whenever player opens it.
If possible, use ModifyShop(NPCShop) instead, to reduce mod conflicts and improve compatibility. Note that for special shops like travelling merchant, the shopName may not correspond to a NPCShop in the NPCShopDatabase

Parameters
npcAn instance of
See also
NPC
that currently player talks to.
shopNameThe full name of the shop being opened. See NPCShopDatabase.GetShopName for the format.
itemsItems in the shop including 'air' items in empty slots.

Reimplemented in PylonShopNPC.

◆ ModifyCollisionData()

virtual bool GlobalNPC.ModifyCollisionData ( NPC  npc,
Rectangle  victimHitbox,
ref int  immunityCooldownSlot,
ref MultipliableFloat  damageMultiplier,
ref Rectangle  npcHitbox 
)
virtual

Allows you to modify the NPC's

See also
ID.ImmunityCooldownID

, damage multiplier, and hitbox. Useful for implementing dynamic damage hitboxes that change in dimensions or deal extra damage. Returns false to prevent vanilla code from running. Returns true by default.

Parameters
npc
victimHitbox
immunityCooldownSlot
damageMultiplier
npcHitbox
Returns

◆ ModifyGlobalLoot()

virtual void GlobalNPC.ModifyGlobalLoot ( GlobalLoot  globalLoot)
virtual

Allows you to add and modify global loot rules that are conditional, i.e. vanilla's biome keys and souls.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify npc loot.

Parameters
globalLoot

◆ ModifyHitByItem()

virtual void GlobalNPC.ModifyHitByItem ( NPC  npc,
Player  player,
Item  item,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that an NPC takes from a melee weapon.
Runs on the local client.

Parameters
npc
player
item
modifiers

◆ ModifyHitByProjectile()

virtual void GlobalNPC.ModifyHitByProjectile ( NPC  npc,
Projectile  projectile,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that an NPC takes from a projectile.

Parameters
npc
projectile
modifiers

◆ ModifyHitNPC()

virtual void GlobalNPC.ModifyHitNPC ( NPC  npc,
NPC  target,
ref NPC.HitModifiers  modifiers 
)
virtual

Allows you to modify the damage, knockback, etc., that an NPC does to a friendly NPC.

Parameters
npc
target
modifiers

◆ ModifyHitPlayer()

virtual void GlobalNPC.ModifyHitPlayer ( NPC  npc,
Player  target,
ref Player.HurtModifiers  modifiers 
)
virtual

Allows you to modify the damage, etc., that an NPC does to a player.

Parameters
npc
target
modifiers

◆ ModifyHoverBoundingBox()

virtual void GlobalNPC.ModifyHoverBoundingBox ( NPC  npc,
ref Rectangle  boundingBox 
)
virtual

Allows you to modify the bounding box for hovering over the given NPC (affects things like whether or not its name is displayed).

Parameters
npcThe NPC in question.
boundingBoxThe bounding box used for determining whether or not the NPC counts as being hovered over.

◆ ModifyIncomingHit()

virtual void GlobalNPC.ModifyIncomingHit ( NPC  npc,
ref NPC.HitModifiers  modifiers 
)
virtual

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.

Parameters
npc
modifiers

◆ ModifyNPCLoot()

virtual void GlobalNPC.ModifyNPCLoot ( NPC  npc,
NPCLoot  npcLoot 
)
virtual

Allows you to add and modify NPC loot tables to drop on death and to appear in the Bestiary.
The Basic NPC Drops and Loot 1.4 Guideexplains how to use this hook to modify npc loot.
This hook only runs once per npc type during mod loading, any dynamic behavior must be contained in the rules themselves.

Parameters
npcA default npc of the type being opened, not the actual npc instance.
npcLootA reference to the item drop database for this npc type.

◆ ModifyShop()

virtual void GlobalNPC.ModifyShop ( NPCShop  shop)
virtual

Allows you to modify existing shop. Be aware that this hook is called just one time during loading.

Parameters
shopA
See also
NPCShop
instance.

Reimplemented in PylonShopNPC.

◆ ModifyTownNPCProfile()

virtual ITownNPCProfile GlobalNPC.ModifyTownNPCProfile ( NPC  npc)
virtual

Allows you to set the town NPC profile that a given NPC uses.

Parameters
npcThe NPC in question.
Returns
The profile that you want the given NPC to use.
This will only influence their choice of profile if you do not return null.
By default, returns null, which causes no change.

◆ NeedSaving()

virtual bool GlobalNPC.NeedSaving ( NPC  npc)
virtual

Allows you to make a npc be saved even if it's not a townNPC and NPCID.Sets.SavesAndLoads[npc.type] is false.
NOTE: A town NPC will always be saved (except the Travelling Merchant that never will).
NOTE: A NPC that needs saving will not despawn naturally.

Parameters
npc
Returns

Reimplemented in UnloadedGlobalNPC.

◆ OnCaughtBy()

virtual void GlobalNPC.OnCaughtBy ( NPC  npc,
Player  player,
Item  item,
bool  failed 
)
virtual

Allows you to make things happen when the given item attempts to catch the given NPC.

Parameters
npcThe NPC which the player attempted to catch.
playerThe player attempting to catch the given NPC.
itemThe item used to catch the given NPC.
failedWhether or not the given NPC has been successfully caught.

◆ OnChatButtonClicked()

virtual void GlobalNPC.OnChatButtonClicked ( NPC  npc,
bool  firstButton 
)
virtual

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.

Parameters
npc
firstButton

◆ OnGoToStatue()

virtual void GlobalNPC.OnGoToStatue ( NPC  npc,
bool  toKingStatue 
)
virtual

Allows you to make things happen when this NPC teleports to a King or Queen statue. This method is only called server side.

Parameters
npcThe NPC
toKingStatueWhether the NPC was teleported to a King or Queen statue.

◆ OnHitByItem()

virtual void GlobalNPC.OnHitByItem ( NPC  npc,
Player  player,
Item  item,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when an NPC is hit by a melee weapon.

Parameters
npc
player
item
hit
damageDone

◆ OnHitByProjectile()

virtual void GlobalNPC.OnHitByProjectile ( NPC  npc,
Projectile  projectile,
NPC.HitInfo  hit,
int  damageDone 
)
virtual

Allows you to create special effects when an NPC is hit by a projectile.

Parameters
npc
projectile
hit
damageDone

◆ OnHitNPC()

virtual void GlobalNPC.OnHitNPC ( NPC  npc,
NPC  target,
NPC.HitInfo  hit 
)
virtual

Allows you to create special effects when an NPC hits a friendly NPC.

Parameters
npc
target
hit

◆ OnHitPlayer()

virtual void GlobalNPC.OnHitPlayer ( NPC  npc,
Player  target,
Player.HurtInfo  hurtInfo 
)
virtual

Allows you to create special effects when an NPC hits a player (for example, inflicting debuffs).
Only runs on the local client in multiplayer.

Parameters
npc
target
hurtInfo

◆ OnKill()

virtual void GlobalNPC.OnKill ( NPC  npc)
virtual

Allows you to make things happen when an NPC dies (for example, setting ModSystem fields). This hook runs on the server/single player. For client-side effects, such as dust, gore, and sounds, see HitEffect

Parameters
npc

◆ PickEmote()

virtual ? int GlobalNPC.PickEmote ( NPC  npc,
Player  closestPlayer,
List< int >  emoteList,
WorldUIAnchor  otherAnchor 
)
virtual

Allows you to change the emote that the NPC will pick

Parameters
npc
closestPlayerThe Player closest to the NPC. You can check the biome the player is in and let the NPC pick the emote that corresponds to the biome.
emoteListA list of emote IDs from which the NPC will randomly select one
otherAnchorA WorldUIAnchor instance that indicates the target of this emote conversation. Use this to get the instance of the NPC or Player this NPC is talking to.
Returns
Return null to use vanilla mechanic (pick one from the list), otherwise pick the emote by the returned ID. Returning -1 will prevent the emote from being used. Returns null by default

◆ PostAI()

virtual void GlobalNPC.PostAI ( NPC  npc)
virtual

Allows you to determine how any NPC behaves. This will be called regardless of what PreAI returns.

Parameters
npc

◆ PostDraw()

virtual void GlobalNPC.PostDraw ( NPC  npc,
SpriteBatch  spriteBatch,
Vector2  screenPos,
Color  drawColor 
)
virtual

Allows you to draw things in front of this NPC. Substract screenPos from the draw position before drawing. This method is called even if PreDraw returns false.

Parameters
npcThe NPC that is being drawn
spriteBatchThe spritebatch to draw on
screenPosThe screen position used to translate world position into screen position
drawColorThe color the NPC is drawn in

◆ PreAI()

virtual bool GlobalNPC.PreAI ( NPC  npc)
virtual

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.

Parameters
npc
Returns

◆ PreChatButtonClicked()

virtual bool GlobalNPC.PreChatButtonClicked ( NPC  npc,
bool  firstButton 
)
virtual

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.

Parameters
npc
firstButton
Returns

◆ PreDraw()

virtual bool GlobalNPC.PreDraw ( NPC  npc,
SpriteBatch  spriteBatch,
Vector2  screenPos,
Color  drawColor 
)
virtual

Allows you to draw things behind an NPC, or to modify the way the NPC is drawn. Substract screenPos from the draw position before drawing. Return false to stop the game from drawing the NPC (useful if you're manually drawing the NPC). Returns true by default.

Parameters
npcThe NPC that is being drawn
spriteBatchThe spritebatch to draw on
screenPosThe screen position used to translate world position into screen position
drawColorThe color the NPC is drawn in
Returns

◆ PreKill()

virtual bool GlobalNPC.PreKill ( NPC  npc)
virtual

Allows you to determine whether or not NPC from doing anything on death (besides die). Return false to stop the NPC from doing anything special. Returns true by default.

Parameters
npc
Returns

◆ ReceiveExtraAI()

virtual void GlobalNPC.ReceiveExtraAI ( NPC  npc,
BitReader  bitReader,
BinaryReader  binaryReader 
)
virtual

Use this to receive information that was sent in SendExtraAI.
Called whenever MessageID.SyncNPC is successfully received.
Can be called on multiplayer clients.

Parameters
npcThe NPC.
bitReaderThe compressible bit reader.
binaryReaderThe reader.

◆ ResetEffects()

virtual void GlobalNPC.ResetEffects ( NPC  npc)
virtual

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.

Parameters
npc

◆ SaveData()

virtual void GlobalNPC.SaveData ( NPC  npc,
TagCompound  tag 
)
virtual

Allows you to save custom data for the given npc.

NOTE: The provided tag is always empty by default, and is provided as an argument only for the sake of convenience and optimization.
NOTE: Try to only save data that isn't default values.
NOTE: The npc may be saved even if NeedSaving returns false and npc is not a townNPC, if another mod returns true on NeedSaving.

Parameters
npc
tagThe TagCompound to save data into. Note that this is always empty by default, and is provided as an argument

Reimplemented in UnloadedGlobalNPC.

◆ SendExtraAI()

virtual void GlobalNPC.SendExtraAI ( NPC  npc,
BitWriter  bitWriter,
BinaryWriter  binaryWriter 
)
virtual

Use this judiciously to avoid straining the network.
Checks and methods such as GlobalType<TEntity, TGlobal>.AppliesToEntity can reduce how much data must be sent for how many projectiles.
Called whenever MessageID.SyncNPC is successfully sent, for example on NPC creation, on player join, or whenever NPC.netUpdate is set to true in the update loop for that tick.
Can be called on the server.

Parameters
npcThe NPC.
bitWriterThe compressible bit writer. Booleans written via this are compressed across all mods to improve multiplayer performance.
binaryWriterThe writer.

◆ SetBestiary()

virtual void GlobalNPC.SetBestiary ( NPC  npc,
BestiaryDatabase  database,
BestiaryEntry  bestiaryEntry 
)
virtual

Allows you to set an NPC's information in the Bestiary.

Parameters
npc
database
bestiaryEntry

◆ SetupTravelShop()

virtual void GlobalNPC.SetupTravelShop ( int[]  shop,
ref int  nextSlot 
)
virtual

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.

Parameters
shop
nextSlot

◆ SpawnNPC()

virtual void GlobalNPC.SpawnNPC ( int  npc,
int  tileX,
int  tileY 
)
virtual

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.

Parameters
npc
tileX
tileY

◆ SpecialOnKill()

virtual bool GlobalNPC.SpecialOnKill ( NPC  npc)
virtual

Allows you to call OnKill on your own when the NPC dies, rather then letting vanilla call it on its own. Returns false by default.

Returns
Return true to stop vanilla from calling OnKill on its own. Do this if you call OnKill yourself.

◆ TownNPCAttackCooldown()

virtual void GlobalNPC.TownNPCAttackCooldown ( NPC  npc,
ref int  cooldown,
ref int  randExtraCooldown 
)
virtual

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.

Parameters
npc
cooldown
randExtraCooldown

◆ TownNPCAttackMagic()

virtual void GlobalNPC.TownNPCAttackMagic ( NPC  npc,
ref float  auraLightMultiplier 
)
virtual

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)

Parameters
npc
auraLightMultiplier

◆ TownNPCAttackProj()

virtual void GlobalNPC.TownNPCAttackProj ( NPC  npc,
ref int  projType,
ref int  attackDelay 
)
virtual

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).

Parameters
npc
projType
attackDelay

◆ TownNPCAttackProjSpeed()

virtual void GlobalNPC.TownNPCAttackProjSpeed ( NPC  npc,
ref float  multiplier,
ref float  gravityCorrection,
ref float  randomOffset 
)
virtual

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).

Parameters
npc
multiplier
gravityCorrection
randomOffset

◆ TownNPCAttackShoot()

virtual void GlobalNPC.TownNPCAttackShoot ( NPC  npc,
ref bool  inBetweenShots 
)
virtual

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).

Parameters
npc
inBetweenShots

◆ TownNPCAttackStrength()

virtual void GlobalNPC.TownNPCAttackStrength ( NPC  npc,
ref int  damage,
ref float  knockback 
)
virtual

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.)

Parameters
npc
damage
knockback

◆ TownNPCAttackSwing()

virtual void GlobalNPC.TownNPCAttackSwing ( NPC  npc,
ref int  itemWidth,
ref int  itemHeight 
)
virtual

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).

Parameters
npc
itemWidth
itemHeight

◆ UpdateLifeRegen()

virtual void GlobalNPC.UpdateLifeRegen ( NPC  npc,
ref int  damage 
)
virtual

Allows you to make the NPC either regenerate health or take damage over time by setting NPC.lifeRegen. This is useful for implementing damage over time debuffs such as BuffID.Poisoned or BuffID.OnFire. Regeneration or damage will occur at a rate of half of NPC.lifeRegen per second. Essentially, modders implementing damage over time debuffs should subtract from NPC.lifeRegen a number that is twice as large as the intended damage per second. See DamageOverTimeGlobalNPC.csfor an example of this. The damage parameter is the number that appears above the NPC's head if it takes damage over time. Multiple debuffs work together by following some conventions: NPC.lifeRegen should not be assigned a number, rather it should be subtracted from. damage should only be assigned if the intended popup text is larger then its current value.

Parameters
npc
damage