Modding:AI Task meleeattack

From Vintage Story Wiki

This task AI deals damage to target entities within melee attack range of the entity. Execution starts when the target enters melee attack range. If the target is again in range at some point after damagePlayerAtMs and before attackDurationMs, then the task hurts the target. This delay allows the target to potentially dodge the attack by getting out of range. Whether the attack was successful or not, there is a cooldown delay before a new attack can be started.

If the attacker is itself attacked, then it reliates by prioritizing the entity that attacked it. This task forgets which entity attacked it last after 30 seconds.

The attacker also has a limited attack angle. If the target is outside that attack angle, then the attacker turn to the target before dealing damage.

The attacker must have a direct line of attack to the target, without any blocks in the middle. The direct line is attempted from the bottom center of the attacker's selection box to the bottom center of the target's selection box. If that fails, it is retried between the center of the attacker and target selection boxes. If that fails, it is retried from the top center of the attacker and target selection boxes.

Note that aside from turning for the attack angle, this task does not move the attacker. This task is usually paired with seekentity to get within attack range of the target.

If the target is not the player (some prey), and the attacker kills it, then this counts as eating a meal for the attacker. Its lastMealEatenTotalHours attribute is updated, and it enters the "saturated" emotional state.

Subclasses

Properties

AiTaskBase partial compliance properties

In addition to the standard properties from AiTaskBase, this task respects the AiTaskBase partial compliance properties.

  • mincooldown
  • maxcooldown
  • initialmincooldown
  • initialmaxcooldown
  • whenSwimming
  • whenInEmotionState
  • whenNotInEmotionState

AiTaskBaseTargetable properties

It inherits the properties from AiTaskBaseTargetable.

  • friendlyTarget
  • retaliateAttacks
  • triggerEmotionState
  • skipEntityCodes
  • entityCodes

AiTaskMeleeAttack properties

These are the properties specific to meleeattack and its subclasses.

tamingGenerations: (float, default 10)
Reduces the attack range as the attacker's generation approaches this value. After it reaches or is above the taming generation, then the attacker will not attack anything. If whenInEmotionState is set, then it overrides this taming behavior.
damage: (float, default 2)
Upon a successful attack, the target receives this much damage, multiplied by the CreatureDamageModifier from the survival config.
damageTier: (int, default 0)
The tier of damage to apply. Higher damage tiers require higher tier armor to block it.
damageType: (string, default "bluntattack")
Type of damage to apply. The string must be one of the values listed in EnumDamageType, case insensitive.
knockbackStrength: (float, default damage/4)
Knockback the player this much when applying damage.
attackAngleRangeDeg: (float, default 20)
The angle portion of the melee attack range. If the target is outside of this range relative to where the attacker is facing, then the attack will fail.
attackDurationMs: (int, default 1500)
Continue playing the animation for this long after applying damage. Also, if the target left the melee attack range, the attacker will keep waiting for this long for them to reenter range and immediately apply damage.
damagePlayerAtMs: (int, default 1000)
After the target enters attack range, wait for this long before applying damage. Since the target must be in attack range at the start of the task and when damage is applied, this gives the target a chance to dodge the attack.
minDist: (float, default 2)
This should be called maxDist. The melee attack range does not extend beyond this distance. The distance is relative to the attacker's position, offset by the radius of the selection box at the attacker's yaw angle.
minVerDist: (float, default 1)
Maximum vertical attack range. minDist already takes vertical distance into account. This property can further restrict the vertical measure of the attack range.


Content Modding
Basics Content Mods Developing a Content Mod Packaging & Release
Tutorials
Concepts Modding Concepts Modinfo Variants Domains Patching Remapping World Properties
Moddable Assets
Uncategorized
 

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityEntity BehaviorsBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsCollectible BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository