<aside> 💡

This make the nearby npc’s naked and places deadric axe above their head

PLAYER

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

I.AnimationController.addTextKeyHandler('spellcast', function(groupname, key)
  
    if key.sub(key, #key - 6) == 'release' then
        
        if types.Actor.getSelectedSpell(self).id == "fireball" then
          
          print("ok")
          
          local acts = nearby.actors
          for i, _ in pairs(acts) do
            if acts[i].type == types.NPC then
              acts[i]:sendEvent("naked" )
            end
          end
        end
    end
end)

local function onTeleported()
  core.sendGlobalEvent("remove_axes")
end

return {
    engineHandlers = { onTeleported = onTeleported }

NPC:

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

local function naked(var)
  types.Actor.setEquipment(self,{})
  core.sendGlobalEvent("weapon",{ nearby_actor = self })
end

return {
    eventHandlers = { naked = naked }
}

GLOBAL:

local world = require('openmw.world')
local types = require('openmw.types')
local core = require('openmw.core')
local I = require('openmw.interfaces')
local util = require('openmw.util')

local nearbys = {}
local jos
local axes = {}

local function weapon(event)
      table.insert(nearbys, event.nearby_actor)
      
      local axe = world.createObject("daedric war axe",1)
      axe:teleport(event.nearby_actor.cell,event.nearby_actor.position, axe.rotation * util.transform.rotateX(-46) ) --*3.14/360
      table.insert(axes, axe)
      jos = 1
end

local function onUpdate()
   if jos == 1 then
     for i, _ in pairs(axes) do
            local tab = nearbys[i]                          
            if axes[i] then
                axes[i]:teleport(
                          tab.cell, 
                          tab.position + util.vector3(0,0,200), 
                          axes[i].rotation*util.transform.rotateY(0.1) 
                          )
            end
      end
   end
end

local function remove_axes()
    for _, n in pairs(axes) do
      if axes[n] then
        axes[n]:remove()
      end
    end
end

return {
    eventHandlers = { weapon = weapon, remove_axes = remove_axes },
    engineHandlers = { onUpdate = onUpdate }
}