1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-30 14:04:30 +00:00
openmw/files/data-mw/scripts/omw/combat/local.lua
2025-11-24 17:45:05 +01:00

37 lines
1.1 KiB
Lua

local core = require('openmw.core')
local I = require('openmw.interfaces')
local self = require('openmw.self')
local types = require('openmw.types')
local Actor = types.Actor
local Player = types.Player
local isPlayer = Player.objectIsInstance(self)
local godMode = function() return false end
if isPlayer then
-- openmw.debug is only allowed on player scripts
godMode = function() return require('openmw.debug').isGodMode() end
end
local function getDamage(attack, what)
if attack.damage then
return attack.damage[what] or 0
end
end
local function onHit(data)
if data.successful and not godMode() then
I.Combat.applyArmor(data)
I.Combat.adjustDamageForDifficulty(data)
if getDamage(data, 'health') > 0 then
core.sound.playSound3d('Health Damage', self)
if data.hitPos then
I.Combat.spawnBloodEffect(data.hitPos)
end
end
elseif data.attacker and Player.objectIsInstance(data.attacker) then
core.sound.playSound3d('miss', self)
end
Actor._onHit(self, data)
end
I.Combat.addOnHitHandler(onHit)