I was able to implement this after patch 1.2.8. I't not very nice solution, but works.
This example shows how you can make bashable spiders.
First you need to override the spider asset in init.lua (or in other lua file)
Code: Select all
cloneObject{
name = "spider",
baseObject = "spider",
onMove = function(self, dir)
monsters.directions[self.id] = dir
end,
onAttack = function(self, attack)
monsters.directions[self.id] = self.facing
end,
onDamage = function(self, attack)
-- to prevent continuous bashing with door
monsters.directions[self.id] = nil
end,
}
Then you have to add a script entity named monsters and define table-property named directions there.
monsters moving directions are stored there as you can see from previous code.
Then make another script entity named doors
Code: Select all
function close(door_name)
-- do some damage to monsters at same tile as the door and moving through it
local door = findEntity(door_name)
local monstersAtDoor = entitiesAt(door.level,door.x,door.y)
for monst in monstersAtDoor do
if door.facing == monsters.directions[monst.id] then
damageTile(door.level,door.x,door.y,door.facing,1,"physical",5)
print("door made damage to "..monst.id)
end
end
-- do some damage to monsters at other side of the door and moving through it
local door_x = door.x
local door_y = door.y
if (door.facing == 0) then
door_y = door_y + 1
elseif (door.facing == 2) then
door_y = door_y - 1
elseif (door.facing == 1) then
door_x = door_x + 1
else
door_x = door_x - 1
end
local monstersAtOtherSideOfDoor = entitiesAt(door.level,door_x,door_y)
if door.facing >= 2 then
door_opposite_facing = door.facing - 2
else
door_opposite_facing = door.facing + 2
end
for monst in monstersAtOtherSideOfDoor do
print("monter_found:"..monst.id)
if door_opposite_facing == monsters.directions[monst.id] then
damageTile(door.level,door_x,door_y,door_opposite_facing,1,"physical",5)
print("door made damage to " ..monst.id)
end
end
door:close()
end
function toggle(door_name)
local door = findEntity(door_name)
if door:isOpen() then
self.close(door_name)
else
door:open()
end
end
-- you have to make similar function for every door, if you want it to be able to deal damage to monsters :(
-- I wish there was door:onClose-hook or possibility to pass parameters to actions called by connectors
function toggleMetal1()
self.toggle("dungeon_door_metal_1")
end
add dungeon_door_metal_1 and a wall button which triggers doors.toggleMetal1()
Spiders will receive damage when moving or attacking through dungeon_door_metal_1
Have fun crushing those nasty spiders
