Wooden floor breaking definition

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!
User avatar
Isaac
Posts: 2799
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac » Fri Sep 08, 2017 8:40 pm

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.
Try this as your drop_floor script: (You will need to edit the exceptions table within.)
SpoilerShow

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
The delay shouldn´t be a Problem. I can just change the time of delayedCall in the Definition then.
Use this new floor definition, and simply add the word 'instantly' or 'never' to the object id.
SpoilerShow

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,
}
https://www.dropbox.com/s/2qh1gxxvdpcou ... r.zip?dl=1


**The previous project link has been updated for this.
Last edited by Isaac on Sat Sep 09, 2017 7:38 pm, edited 1 time in total.

User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas » Sat Sep 09, 2017 6:41 pm

Hey Isaac,
Nice update! I would have made 3 complete new Floors :lol:
I don´t know if it´s on purpose, but the instant breaking Floor in your sample dungeon doesn´t spawn a debris model, which makes the Floor simply disappear, when no other debris model is lying on that Floor already.

It´s probably not the best solution, but the only one, which i was able to do. You will recognize the Code :lol:
This new FloorTrigger class would do the Job:
SpoilerShow
{
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
local debris = self.go:spawn("barrel_crate_block_broken"):createComponent('Gravity')
debris.go.gravity:setDestroySelf(true)
self.go:playSound("barrel_die")
if party.x == self.go.x and party.y == self.go.y then
party.party:shakeCamera(.5,1)
end
local furtherFalling = true
if furtherFalling then
for otherDebris in self.go.map:entitiesAt(self.go.x, self.go.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
self.go:destroyDelayed()
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,
},
It´s the same Code, you already used in the breakAway function.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!

User avatar
Isaac
Posts: 2799
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac » Sat Sep 09, 2017 7:38 pm

That is a fiendish bug; (thanks for posting it 8-) ). I never once noticed it because It always had debris from the floors above. Reading it, I can't imagine why I put the call to destroy in there. It is fixed by calling the BreakAway function immediately, instead of destroying the floor; which the BreakAway function does automatically.

The previous post and project files are now updated.

This was a fun map to make. The only thing remaining to do (but not for a few days...) is to make the custom debris model. The floors presently drop bits of crate—that didn't exist before it broke apart. I do hope this shows up in more than a few maps. I plan to incorporate it somehow into the one I'm working on.

User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas » Sat Sep 09, 2017 9:12 pm

And with that, i realize that my previous post makes no sense. Sorry for that. Somehow i thought instantly has to break on the first step. I totally forgot with your new Changes you can set the break Chance individually. Now it´s time for me to make a room with this superfloor. :)
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!

User avatar
akroma222
Posts: 982
Joined: Thu Oct 04, 2012 10:08 am

Re: Wooden floor breaking definition

Post by akroma222 » Sun Sep 10, 2017 9:22 am

This really is Gold, nice going Isaac and Xardas :)
Now - not a request :lol: - but an idea I had that I will investigate and test tomorrow....
Thrown Bomb items & Thrown heavy projectile items (like a really large but throwable boulder)
- should be able to break through the floor if detonated over / lands on top of these breakable wood floor objects
Will report back soon!

User avatar
petri
Posts: 1895
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Wooden floor breaking definition

Post by petri » Tue Sep 12, 2017 9:24 am

This looks very nice! I like!

bongobeat
Posts: 903
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Wooden floor breaking definition

Post by bongobeat » Wed Sep 13, 2017 5:47 pm

Very nice stuff! Thanks for sharing! :)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505

Slayer82
Posts: 248
Joined: Thu Feb 05, 2015 10:19 am

Re: Wooden floor breaking definition

Post by Slayer82 » Thu Sep 14, 2017 1:51 am

Excellent work!

I'll use this is my mod as it adds a nice bit of randomness to the adventure. All of these additions to the game really help the modding scene for Grimrock 2.
I hope there are others whom still wish to mod the game. oh, and Xardas; what type of mod are you making (if you are making one)?
Mods - Isle of the Deranged & The Allure of Nightfall
http://grimrock.net/forum/viewtopic.php?f=23&t=9513
viewtopic.php?f=23&t=14762

User avatar
Isaac
Posts: 2799
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac » Thu Sep 14, 2017 1:54 am

@Slayer82 8-)

There might be one more update to this. I have an experimental version that allows the floors to be burned away with fire (and they fall while on fire, and can potentially burn through the floor below if there is one); but it's not ready to upload.

**Also, it still needs a proper debris model. As it is, it drops broken crate panels where there were none to break.
petri wrote:This looks very nice! I like!
This made my my day. 8-) 8-) 8-)
Last edited by Isaac on Thu Sep 14, 2017 2:07 am, edited 1 time in total.

Slayer82
Posts: 248
Joined: Thu Feb 05, 2015 10:19 am

Re: Wooden floor breaking definition

Post by Slayer82 » Thu Sep 14, 2017 2:02 am

There might be one more update to this. I have an experimental version that allows the floors to be burned away with fire; but it's not ready to upload.
Woah! Brutal! I can't wait to see how that turns out, Isaac.

Man, this is the best modding community. I hope the file size of my mod doesn't get too big by adding all of these updates and assets :lol:; Isle of the Deranged was almost 500mb. ;)
Anyway, keep up the good work.
Mods - Isle of the Deranged & The Allure of Nightfall
http://grimrock.net/forum/viewtopic.php?f=23&t=9513
viewtopic.php?f=23&t=14762

Post Reply