magicka based attacks: todo

placing stuff on the hitPos: todo

<aside> 💡

IMPORTANT: addOnHitHandler fires at victim so handling hit results easily to loop while in onHitHandler

</aside>

combat functions

<aside> 💡

isn’t automatically removing the reactions without return false

onHit command and event


addOnHitHandler

local I = require('openmw.interfaces')

I.Combat.addOnHitHandler(function(attack)
  --if attack.attacker.type == types.Player then
    print(attack.attacker.recordId)
    if attack.weapon then print(attack.weapon.recordId) end
    print("health", attack.damage.health)
    print("fatigue", attack.damage.fatigue) 
    print("magicka", attack.damage.magicka)
  --end
end)

<aside> 💡

this doesn’t bypass spells so could make wictim invurnelable for weapons thoretically

</aside>

local types = require('openmw.types')
local I = require('openmw.interfaces')

I.Combat.addOnHitHandler(function(attack)
  --if attack.attacker.type == types.Player then
   
    if attack.weapon then print(attack.weapon.recordId) end
    print(attack.damage.health)
    
    if attack.damage.health and attack.damage.health > 10 then
    
       return true --, other stuff after comma  
       else return false --, other stuff after comma
    end
 
  --end
end)

--print("hitpos", tostring(attack.hitPos))
--print(attack.attacker.recordId)

another case to reduce attackers health

<aside> 💡

this is easy to modify for blind, invisibility, summons, weapon change, etc.

local self = require('openmw.self')
local types = require('openmw.types')
local I = require('openmw.interfaces')

I.Combat.addOnHitHandler(function(attack)
    
    if attack.weapon then print(attack.weapon.recordId) end
    print(attack.damage.health)
    
    if attack.damage.health and attack.damage.health > 6 then

      return true, 
            attack.attacker:sendEvent("damages")
      else return false
 
    end
end)

local function damages()
    types.Actor.stats.dynamic.health(self).current = types.Actor.stats.dynamic.health(self).current - 5
end

return { eventHandlers = { damages = damages } }