Hi,
It's been a while, but it's nice to see that someone still uses my framework. And DesperateGames is right, I forgot that repeatFunction is used in the framework, here is a fixed version of the damage_dealing_doors script-entity:
Code: Select all
damagePowers = {
wooden=10,iron=25,ornament=15,
metal=20,portcullis=15,secret=35
}
function deactivate()
fw.removeHooks('doors','damage_dealing_doors')
fw.removeHooks('monsters','damage_dealing_doors')
end
function activate()
fw.addHooks('doors','damage_dealing_doors',
{
onClose = function(door)
if data.get(door,'opening') then
return true
end
local damagePower = 10 --default for custom doors
for doorType,damage in pairs(damage_dealing_doors.damagePowers) do
if string.find(door.name,doorType) then
damagePower = damage
end
end
data.set(door,'closing',1)
timers.repeatCall(1,1,false,function(door_id) data.removeEntity(door_id) end,{door.id});
damage_dealing_doors.dealDamage(door,damagePower)
end,
onOpen = function(door)
if data.get(door,'closing') then
return true
end
data.set(door,'opening',1)
timers.repeatCall(2.5,1,false,function(door_id) data.removeEntity(door_id) end,{door.id});
end
}
)
fw.addHooks('monsters','damage_dealing_doors',
{
onMove=function(monst,dir)
data.set(monst,"dir",dir)
end,
onDie = function(monst)
-- clear dead monsters from data-table
data.removeEntity(monst)
end,
onAttack = function (monst, attack)
data.set(monst,"dir",monst.facing)
end,
onDamage = function(monst)
data.unset(monst,"dir")
end,
}
)
end
function dealDamage(door, damagePower)
-- do some damage to monsters on same tile as the door and moving through it
local monstersAtDoor = entitiesAt(door.level,door.x,door.y)
for monst in monstersAtDoor do
if door.facing == data.get(monst,"dir") then
damageTile(door.level,door.x,door.y,door.facing,5,"physical",damagePower)
end
end
-- do some damage to monsters at other side of the door if it's moving through it
local monstersAtOtherSideOfDoor = help.entitiesAtAhead(door)
local door_opposite_facing = help.getOppositeFacing(door)
for monst in monstersAtOtherSideOfDoor do
if door_opposite_facing == data.get(monst,"dir") then
damageTile(monst.level,monst.x,monst.y,door_opposite_facing,5,"physical",damagePower)
end
end
end
You can replace the script-entity part (the part inside double square brackets[[...]]) of the damage_dealing_doors.lua file with it. Or you can create a script entity named damage_dealing_doors and copy paste this script in it, so it will be used instead of the script included in framework, this solution allows you to make tweaks on this script if you will. Eg. you might like to adjust the damagePowers table or adjust the time how long the door stays open before it can be closed again by changing the inteval argument of the timers.repeatCall at line 33
For example:
Code: Select all
timers.repeatCall(4,1,false,function(door_id) data.removeEntity(door_id) end,{door.id});
Makes doors stay open for 4 seconds before they can be closed again (to prevent crushing monsters with doors repeatedly)
And I will update this in my framework too soon.