Files
ashlar/files/lua_api/openmw/self.lua
T
claudeandClaude Opus 5.5 4e152c7c4e Add active blocking for NPCs and creatures
With real time combat and the new [Game] 'ai active blocking' setting
(on by default), NPCs and creatures block through the same stance and
arc rules as the player instead of the classic roll.

In combat, an actor with a shield ready and its weapon drawn raises the
stance when an enemy in front of it winds up a melee attack within
reach. Whether it reacts is rolled once per wind-up (10% at 0 Block
skill and agility, up to 90%, scaled by fatigue), and its reaction
delay falls from 0.6 s to 0.15 s with skill. It keeps the block up for
half a second after the wind-up ends so it catches the swing, drops it
after two seconds at most so a held wind-up can't pin it, and starts
no attacks while blocking.

The decision lives in mwmechanics/aiblock.cpp. Combat AI sets a
separate, unsaved CreatureStats flag that is cleared every frame before
AI runs, so a block never outlives the combat package and a Lua block
request is left alone. Actors without a shield never block, and a
creature blocks only if it can carry a shield.

Closes #20

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 04:31:38 -05:00

59 lines
2.5 KiB
Lua

---
-- Provides full access to the object the script is attached to.
-- All fields and function of `GameObject` are also available for `openmw.self`.
-- @context local
-- @module Self
-- @extends openmw.core#GameObject
-- @usage local self = require('openmw.self')
-- local types = require('openmw.types')
-- if self.type == types.Player then -- All fields and functions of `GameObject` are available.
-- self:sendEvent("something", self.position)
-- end
---
-- Returns true if the script isActive (the object it is attached to is in an active cell).
-- If it is not active, then `openmw.nearby` can not be used.
-- @function [parent=#Self] isActive
-- @param Self
-- @return #boolean
---
-- The object the script is attached to (readonly)
-- @field [parent=#Self] openmw.core#GameObject object
---
-- Movement controls (only for actors)
-- @field [parent=#Self] #ActorControls controls
---
-- @type ATTACK_TYPE
-- @field #number NoAttack
-- @field #number Any
-- @field #number Chop
-- @field #number Slash
-- @field #number Thrust
---
-- Allows to view and/or modify controls of an actor. All fields are mutable.
-- @type ActorControls
-- @field [parent=#ActorControls] #number movement +1 - move forward, -1 - move backward
-- @field [parent=#ActorControls] #number sideMovement +1 - move right, -1 - move left
-- @field [parent=#ActorControls] #number yawChange Turn right (radians); if negative - turn left
-- @field [parent=#ActorControls] #number pitchChange Look down (radians); if negative - look up
-- @field [parent=#ActorControls] #boolean run true - run, false - walk
-- @field [parent=#ActorControls] #boolean sneak If true - sneak
-- @field [parent=#ActorControls] #boolean jump If true - initiate a jump
-- @field [parent=#ActorControls] #boolean block Ashlar: if true, hold the block stance. Has an effect with real time combat on (for NPCs and creatures, also ai active blocking) and the weapon drawn, with a shield or a melee weapon equipped. Combat AI raises its own block separately, and that is not reported here.
-- @field [parent=#ActorControls] #ATTACK_TYPE use Activates the readied weapon/spell according to a provided value. For weapons, keeping this value modified will charge the attack until set to @{#ATTACK_TYPE.NoAttack}. If an @{#ATTACK_TYPE} not appropriate for a currently equipped weapon provided - an appropriate @{#ATTACK_TYPE} will be used instead.
---
-- Enables or disables standard AI (enabled by default).
-- @function [parent=#Self] enableAI
-- @param Self
-- @param #boolean v
return nil