minmay wrote:Yes, but it's tricky:...
That did it!
Thank you minmay.
Tricky is an understatement ~that was bizarre.
_______________________
Alright, I have one of my own these spawned chasm assets. It's not perfect (and unfinished). It does not support closed trap doors underneath it; but most items will fall when the chasm is opened, and breakable items will crack when they hit the floor below; including falling through additional pits.
*Call it beta, but it seems to work well enough for my purposes. There is a known bug in that it really doesn't like the beach titleset; but I haven't determined just why that is yet. When I do, I'll fix it.
I had first thought to chain the pits, so that opening one opened them all... but it seems faster to just ensure that all chasm pits are opened at the same time. An easy way for that is to call them all in a loop; or connect them all to an off screen button or lever, and trigger it from a script, or leave the switch accessible to the player (as in the demo).
Code: Select all
defineObject{
name = "forest_spawn_chasm",
baseObject = "base_pit_trapdoor",
replacesFloor = true,
killHeightmap = true,
placement = "floor",
editorIcon = 40,
automapIcon = 108,
components = {
{
class = "Model",
name = "trapDoorModel",
model = "assets/models/env/forest_ground_02.fbx",
},
{
class = "Pit",
onInit = function(self)
local align = {self.go:getPosition()}
align[3] = 1
align[4], align[5] = self.go.elevation, align[4]
self.go:setPosition(unpack(align))
-- spawn edges [asset pack]
local adj = {}
for i=0,3 do
local dx,dy = getForward(i)
local adjacent = false
for e in self.go.map:entitiesAt(self.go.x + dx, self.go.y + dy) do
if string.find(e.name, "_floor") and e.model then
self.go.trapDoorModel:setMaterial(e.name)
end
if e.name == self.go.name then
adjacent = true
--break
end
end
adj[i] = adjacent
if not adjacent then
spawn("forest_chasm_edge", self.go.level, self.go.x, self.go.y, i, 0).model:disable()
end
end
-- spawn corners [asset pack]
for i=0,3 do
if not adj[i] and not adj[(i+3)%4] then
spawn("forest_chasm_corner", self.go.level, self.go.x, self.go.y, i, 0).model:disable()
end
end
end
},
{
class = "Controller",
onInitialOpen = function(self)
self.go.controller:open()
end,
onOpen = function(self)
if not self.go.pit:isOpen() then
self.go.pit:open()
self.go.trapDoorModel:disable()
spawn('forest_pit_fog',self.go.level ,self.go.x, self.go.y, self.go.facing, self.go.elevation)
for e in self.go.map:entitiesAt(self.go.x, self.go.y) do
if string.find(e.name, "chasm" ) and e.model and not e.model:isEnabled() then
e.model:enable()
end
if string.find(e.name, "block" ) and e.name ~= "blocker" or e.name == "chest" then
e:createComponent("Gravity")
local loc = {e:getPosition()}
loc[5] = e.level +1
local recurse = false
local double_tap = false
repeat
for each in Dungeon.getMap(loc[5]):entitiesAt(loc[1], loc[2]) do
for _,comp in each:componentIterator() do
if comp.go.pit then
if loc[5] < Dungeon.getMaxLevels() then
loc[5] = loc[5] +1
recurse = true
break
end
else recurse = false
end
end
end
until(recurse == false)
if e.name == "chest" then
spawn('base_obstacle',loc[5], loc[1], loc[2], loc[3], Dungeon.getMap(loc[5]):getElevation(loc[1], loc[2]))
elseif e.name == "pushable_block" then
else
local trigger = spawn("floor_trigger",loc[5], loc[1], loc[2], loc[3], Dungeon.getMap(loc[5]):getElevation(loc[1], loc[2]))
trigger.floortrigger:addConnector("onActivate", "chasm_fall_damager" , 'breakStuff')
end
end
end
end
end,
onClose = function(self)
if not self.go.pit:isClosed() then
self.go.pit:close()
self.go.trapDoorModel:enable()
for e in self.go.map:entitiesAt(self.go.x, self.go.y) do
if string.find(e.name, "chasm" ) and e.model and e.model:isEnabled() then
e.model:disable()
elseif e.name == 'forest_pit_fog' then
e:destroy()
end
end
end
end,
onToggle = function(self)
if self.go.pit:isOpen() then
self.go.controller:close()
else self.go.controller:open()
end
end,
onInit = function(self)
if not findEntity("chasm_fall_damager") then
spawn("chasm_fall_damager", self.go.level, 0, 0, 0 , 0, "chasm_fall_damager")
chasm_fall_damager.script:setSource("function breakStuff(target) damageTile(target.go.level, target.go.x,target.go.y,target.go.facing,target.go.elevation, 64, 'physical', 90) target.go.floortrigger:setDisableSelf(true) end")
end
end,
}
},
}
defineObject{
name= "chasm_fall_damager",
baseObject = "script_entity",
components = {
{
class = "Script",
name = "chasm_fall_damager",
}
},
}