Page 1 of 1
Breakable Cave-ins
Posted: Sun Nov 02, 2014 12:02 pm
by Mysterious
Hi all. I was wondering how I would create a Breakable cave-in? This is how it was done in LOG 1:
Code: Select all
cloneObject{
name = "dungeon_destructible_cave_in",
baseObject = "dungeon_cave_in", -- you might want to change this to temple_cave_in or other. --
brokenModel = "assets/models/env/floor_dirt.fbx",
health = 50, -- adjust this to your needs. --
evasion = -1000,
hitEffect = "hit_dust",
hitSound = "impact_blade",
onProjectileHit = function()
return false -- projectiles (arrows and such) shouldn't be able to destroy it. --
end,
onHit = false, -- this is used to negate the "indestructible" property. --
onDie = function(self)
-- when blockage is destroyed, spawn 1-4 rocks. --
rocks = math.random(1,4)+1
for i = 1,rocks do
spawn("rock", self.level, self.x, self.y, i%4)
party:shakeCamera(0.8,0.8)
playSound("wall_sliding_lock")
end
end
}
Any help would be most welcomed thxs

Re: Breakable Cave-ins
Posted: Sun Nov 02, 2014 6:21 pm
by Mysterious
bump
Re: Breakable Cave-ins
Posted: Sun Nov 02, 2014 7:44 pm
by swampie
If you want to make it breakable you have to add a health component.
Something like
Code: Select all
{
class = "Health",
health = 20,
onDie = function()
party.party:shakeCamera(0.3,0.6)
playSound("wall_sliding_lock")
--etc.
end
}
Re: Breakable Cave-ins
Posted: Sun Nov 02, 2014 10:26 pm
by Mysterious
Ok I tried this and the editor crashes while trying to spawn the random rocks dammmm.
Code: Select all
defineObject{
name = "breakable_cave_in",
components = {
{
class = "Model",
model = "mod_assets/models/cave_in/dungeon_cave_in.fbx",
},
{
class = "Obstacle",
hitSound = "barrel_hit",
hitEffect = "hit_wood",
},
{
class = "Health",
health = 15,
immunities = { "poison" },
spawnOnDeath = "cave_in_broken",
onDie = function()
-- when blockage is destroyed, spawn 1-4 rocks. --
rocks = math.random(1,4)+1
for i = 1,rocks do
spawn("rock", self.level, self.x, self.y,0,0,i%4)
party.party:shakeCamera(0.3,0.6)
playSound("wall_sliding_lock")
end
end
},
},
placement = "floor",
editorIcon = 144,
}
Re: Breakable Cave-ins
Posted: Mon Nov 03, 2014 4:33 am
by Eleven Warrior
swampie wrote:If you want to make it breakable you have to add a health component.
Something like
Code: Select all
{
class = "Health",
health = 20,
onDie = function()
party.party:shakeCamera(0.3,0.6)
playSound("wall_sliding_lock")
--etc.
end
}
Was this useful Mysterious? Not really I can see where you are coming from here, he gave you some code but does not answer your question. I wish when you ask for help if your not good at coding as I am, the good scripters would give the solution properly. I can see your having a problem with the random rock spawning not sure how to help you, If the good scripters could do this, it could be added to the sticky thread ahy. As with all things. Sorry just saying. Everyone is doing there best I can see this.
Re: Breakable Cave-ins
Posted: Mon Nov 03, 2014 3:01 pm
by swampie
Sorry if I was not usefull

But this time I will be!! You are trying to do
try
and choose a valid id in your spawn call (you can omitt the id, it's optional)
Code: Select all
onDie = function(self)
-- when blockage is destroyed, spawn 1-4 rocks. --
local rocks = math.random(1,4)+1
for i = 1,rocks do
spawn("rock", self.level, self.x, self.y,0,0,)
end
end
works for me

Edit: I am trying to add a check for the item the obstacle has been hit so you could destroy it only with let's say a pickaxe... if anyone knows the right hook I would be very pleased if you told me
Edit #2:
I feel somewhat dirty, BUT I added a Door component and used onAttackedByChampion to register hits and hitters. Buuut I had to manualy decrese the object health, because the door comp somewhat overwrites the health one

So workaround after workaround I came up with the following:
Code: Select all
class = "Door",
onAttackedByChampion = function(self, champion, weapon, attack, slot)
if weapon ~= nil then
if weapon.go.name == "pickaxe" then
self.go.health:setHealth(self.go.health:getHealth()-10)
if self.go.health:getHealth() <= 0 then
spawn("rock", self.level, self.x, self.y,0,0)
spawn("floor_dirt", self.level, self.x, self.y,0,0)
party.party:shakeCamera(0.1,0.6)
playSound("wall_sliding_lock")
self.go:destroy()
end
end
end
end,
Sadly :destroy does not trigger the onDie hook... It is not pretty (as the console remembers me with a "Warning: no gate node"), but it works

Re: Breakable Cave-ins
Posted: Tue Nov 04, 2014 7:51 am
by Eleven Warrior
Sorry about that Swampie awesome work mate, it makes it easier for me, because I only know very basic lua stuff. Anhow keep up the good work and sorry about the post before

Re: Breakable Cave-ins
Posted: Tue Nov 04, 2014 9:35 am
by Mysterious
Thxs for the help swampie cool now I can continue. Yeah I'm not very good at this scripting stuff. Thank you
