local thisObj
local dmgCollisionOn = false
function OnScriptLoaded(level, obj)
  thisObj = obj
end
function DamageOn()
  if dmgCollisionOn == false then
    game.Combat.AddSubObjectCombatCollision(thisObj, "Helheim_Firestone")
    dmgCollisionOn = true
  end
end
function DamageOff()
  if dmgCollisionOn == true then
    game.Combat.RemoveSubObjectCombatCollision(thisObj, "Helheim_Firestone")
    dmgCollisionOn = false
  end
end
local immuneChar
local jotunnCheckCooldown = 0
function OnUpdate(level, obj)
  if jotunnCheckCooldown < game.GetGameTime() then
    jotunnCheckCooldown = game.GetGameTime() + 1
    local nearJotunn = false
    local player = game.Player.FindPlayer()
    local livingenemies = player:FindEnemies(100)
    for _, enemy in pairs(livingenemies) do
      if string.find(enemy:GetName(), "jotunn") then
        jotunnCheckCooldown = 0
        if math.abs((enemy:GetCreature():GetWorldPosition() - obj:GetWorldPosition()).length) < 4 then
          nearJotunn = true
          break
        end
      end
    end
    if nearJotunn then
      DamageOff()
    else
      DamageOn()
    end
  end
end
function Enable()
  DamageOn()
end
function Disable()
  DamageOff()
end
