Breakable Cave-ins

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Breakable Cave-ins

Post 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 :)
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Breakable Cave-ins

Post by Mysterious »

bump
swampie
Posts: 9
Joined: Sun Nov 02, 2014 1:12 am

Re: Breakable Cave-ins

Post by swampie »

If you want to make it breakable you have to add a health component.
Something like
SpoilerShow

Code: Select all

{
	class = "Health",		
	health = 20,		
	onDie = function()			
		party.party:shakeCamera(0.3,0.6)
		playSound("wall_sliding_lock")	
                --etc.
	end
}
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Breakable Cave-ins

Post 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,
}
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Breakable Cave-ins

Post by Eleven Warrior »

swampie wrote:If you want to make it breakable you have to add a health component.
Something like
SpoilerShow

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.
swampie
Posts: 9
Joined: Sun Nov 02, 2014 1:12 am

Re: Breakable Cave-ins

Post by swampie »

Sorry if I was not usefull :( But this time I will be!! You are trying to do

Code: Select all

rock=math.random(1,4)+1
try

Code: Select all

local rock = math.random(1,4)+1
and choose a valid id in your spawn call (you can omitt the id, it's optional)
SpoilerShow

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 :D

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:
SpoilerShow

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 ;)
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Breakable Cave-ins

Post 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 :)
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Breakable Cave-ins

Post by Mysterious »

Thxs for the help swampie cool now I can continue. Yeah I'm not very good at this scripting stuff. Thank you :)
Post Reply