Try this as your drop_floor script: (You will need to edit the exceptions table within.)Xardas wrote:* One that never breaks (dummy), since it could be important that some path have to be accessible no matter how many times the Player steps on it.
* One that breaks with 100% Chance and without a delay.
Code: Select all
--drop_floor
exceptions = {
-- ["wooden_floor_break_apart_5"] = 0, --never
-- ["wooden_floor_break_apart_9"] = .6,
-- ["wooden_floor_break_apart_11"] = 1, -- always
-- Add or relace object Ids here, in the above format to create special case floors
--____________________________________________________________________
--____________________________________________________________________
}
randomCollapse = true --randomCollapse = true --make false to have the floors always break when trigged
defaultChanceOfBreak = .40 --default percent chance to break
furtherFalling = true
debrisModel = "barrel_crate_block_broken"
function breakAway(target)
if randomCollapse then
if type(target) == "string" then
target = findEntity(target)
elseif target and type(target) == "table" then
target = target.go
else return false --print("Error in "..self.go.id..".script.breakAway type(target) == "..type(target) )
end
if target then --References to target would sometimes fail for some unknown reason.
local roll = .00000001+math.random()
local chanceOfBreak = defaultChanceOfBreak
--option to alter chanceOfBreak per trigger
if exceptions[target.id] then
chanceOfBreak = exceptions[target.id]
end
if roll < chanceOfBreak then --doesn't always break
--This uses the default broken crate debris model as a placeholder for a custom debris model.
local debris = target:spawn(debrisModel):createComponent('Gravity')
debris.go.gravity:setDestroySelf(true)
target:playSound("barrel_die")
if party.x == target.x and party.y == target.y then
party.party:shakeCamera(.5,1)
end
if furtherFalling then
for otherDebris in target.map:entitiesAt(target.x, target.y) do
if otherDebris.name == debrisModel and otherDebris.elevation == target.elevation then
otherDebris:createComponent('Gravity')
otherDebris.gravity:enable()
otherDebris.gravity:setDestroySelf(true)
end
end
end
target:destroyDelayed()
end
else return false --print("Error in "..self.go.id..".script.breakAway type(target) == "..type(target) )
end
end
end
function setRandomBreak(self, bool) if type(bool) == 'boolean' then randomCollapse = bool end end
function setChanceOfBreak(self, chance) if type(chance) == 'number' and chance >= 1 then chanceOfBreak = chance end end
function getRandomBreak() return randomCollapse end
function getChanceOfBreak() return chanceOfBreak end
function effects(trigger)
trigger.go:createComponent("Particle")
trigger.go.particle:setParticleSystem("hit_wood")
trigger.go.particle:setDestroySelf(true)
trigger.go.particle:fadeOut(1)
trigger.go:playSound("creaky_floor")
self.go:playSound("creaky_floor")
if party.x == trigger.go.x and party.x == trigger.go.x then
party.party:shakeCamera(.1,1)
end
end
Use this new floor definition, and simply add the word 'instantly' or 'never' to the object id.The delay shouldn´t be a Problem. I can just change the time of delayedCall in the Definition then.
Code: Select all
defineObject{
name = "wooden_floor_break_apart",
baseObject = "base_floor_decoration",
components = {
{
class = "Model",
model = "assets/models/env/mine_support_ceiling_01.fbx",
staticShadow = true,
offset = vec(0,-3,0),
},
{
class = "Model",
name = 'layer2',
model = "assets/models/env/mine_support_ceiling_01.fbx",
staticShadow = true,
offset = vec(0,-2.9,0),
onInit = function(self) self.go.model:setRotationAngles(0, 90, 0) end
},
{
class = "Platform",
},
{
class = "Null",
onInit = function(self)
if not findEntity("drop_floor") then
spawn("script_entity",1,0,0,0,0,"drop_floor")
drop_floor.script:setSource([[
exceptions = {
-- ["wooden_floor_break_apart_5"] = 0, --never
-- ["wooden_floor_break_apart_9"] = .6,
-- ["wooden_floor_break_apart_11"] = 1, -- always
-- Add or relace object Ids here, in the above format to create special case floors
--____________________________________________________________________
--____________________________________________________________________
}
randomCollapse = true --randomCollapse = true --make false to have the floors always break when trigged
defaultChanceOfBreak = .40 --default percent chance to break
furtherFalling = true
debrisModel = "barrel_crate_block_broken"
function breakAway(target)
if randomCollapse then
if type(target) == "string" then
target = findEntity(target)
elseif target and type(target) == "table" then
target = target.go
else return false --print("Error in "..self.go.id..".script.breakAway type(target) == "..type(target) )
end
if target then --References to target would sometimes fail for some unknown reason.
local roll = .00000001+math.random()
local chanceOfBreak = defaultChanceOfBreak
--option to alter chanceOfBreak per trigger
if exceptions[target.id] then
chanceOfBreak = exceptions[target.id]
end
if roll < chanceOfBreak then --doesn't always break
--This uses the default broken crate debris model as a placeholder for a custom debris model.
local debris = target:spawn(debrisModel):createComponent('Gravity')
debris.go.gravity:setDestroySelf(true)
target:playSound("barrel_die")
if party.x == target.x and party.y == target.y then
party.party:shakeCamera(.5,1)
end
if furtherFalling then
for otherDebris in target.map:entitiesAt(target.x, target.y) do
if otherDebris.name == debrisModel and otherDebris.elevation == target.elevation then
otherDebris:createComponent('Gravity')
otherDebris.gravity:enable()
otherDebris.gravity:setDestroySelf(true)
end
end
end
target:destroyDelayed()
end
else return false --print("Error in "..self.go.id..".script.breakAway type(target) == "..type(target) )
end
end
end
function setRandomBreak(self, bool) if type(bool) == 'boolean' then randomCollapse = bool end end
function setChanceOfBreak(self, chance) if type(chance) == 'number' and chance >= 1 then chanceOfBreak = chance end end
function getRandomBreak() return randomCollapse end
function getChanceOfBreak() return chanceOfBreak end
function effects(trigger)
trigger.go:createComponent("Particle")
trigger.go.particle:setParticleSystem("hit_wood")
trigger.go.particle:setDestroySelf(true)
trigger.go.particle:fadeOut(1)
trigger.go:playSound("creaky_floor")
self.go:playSound("creaky_floor")
if party.x == trigger.go.x and party.x == trigger.go.x then
party.party:shakeCamera(.1,1)
end
end
]])
end
end,
},
{
class = "FloorTrigger",
onInit = function(self)
self.go.floortrigger:setTriggeredByItem(false)
end,
onActivate = function(self)
local delay = 1.5
drop_floor.script.effects(self)
if self.go.id:match("instantly") then --To use, just put the word 'instantly' in the object id
delayedCall("drop_floor", 0.01, "breakAway", self.go.id )
return
elseif self.go.id:match("never") then --To use, just put the word 'never' in the object id and it won't break
return
end
delayedCall("drop_floor", delay, "breakAway", self.go.id )
end,
},
},
editorIcon = 184,
}
defineSound{
name = "creaky_floor",
filename = {
"assets/samples/monsters/mimic_walk_01.wav",
"assets/samples/monsters/mimic_walk_02.wav",
},
loop = false,
volume = 0.7,
minDistance = 1,
maxDistance = 10,
clipDistance = 5,
}
**The previous project link has been updated for this.