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
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas »

It works perfect in a new dungeon. I might have a bug in my Project :|
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: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac »

I updated my previous post with the finished demo project. There are several changes.
Xardas wrote:It works perfect in a new dungeon. I might have a bug in my Project :|
The first thing to do is scrutinize the definition to ensure that it is identical to the one that works in a new project.
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas »

This demo Floor is amazing! the texture fits perfectly to the Floor.
now i´m sure it´s my Project causing the bug. For some reason it´s unable to set the script source. I might just make the script myself and place it in the map, but have to admit it sucks that i can´t find the source for the bug. Anyway, great Job on the Floor. I think a lot of People might use it in their Projects as well!
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: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Wooden floor breaking definition

Post by akroma222 »

Isaac wrote:I updated my previous post with the finished demo project. There are several changes.
This is fantastic - thankyou! ;)

Xardas, have you got it working in your mod yet?
(Confirming the demo files work fine when pasted into my mod files)
If not do you get crashes? An error message? Any further info...?
billb52

Re: Wooden floor breaking definition

Post by billb52 »

Hi Isaac, have tried your breaking wooden floor in my dungeon everything looks ok but when you walk over the floor you get the creaking sounds but the
floor does not destroy itself? I have tried your example dungeon works fine, but when you incorporate it into any other I get the same problem.
Any ideas why this is happening? I have also tried using the 'wooden_floor_break_apart asset in a corridor this also does not destroy itself on standing on it.
Please Help!
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac »

Xardas wrote:...now i´m sure it´s my Project causing the bug. For some reason it´s unable to set the script source.
billb52 wrote:...but the floor does not destroy itself? I have tried your example dungeon works fine, but when you incorporate it into any other I get the same problem.
Any ideas why this is happening?
These do sound like the same issue. Not setting the script source would prevent the collapse & debris effect. It's known that setting the script source has to be done from a component that is defined before the script component... Simply switching the position of the two components in the definition will break it. While that's not exactly the same issue, it does make me wonder if these two projects are using a framework that tinkers with object definitions?

Fortunately, the workaround (when needed) is easy this time; just manually make the drop_floor script—as the floor object would have otherwise done for itself.

Place a script_entity on the map; and name it drop_floor; paste in the following:

Code: Select all

--drop_floor
randomCollapse = true --randomCollapse = true --make false to have the floors always break when trigged
								chanceOfBreak = .40 --percent

								function breakAway(target)
									if randomCollapse and math.random() <= chanceOfBreak then --doesn't always break
									    if target and type(target) == "string" then   
									        target = findEntity(target)
									        else return false, print("Error in "..self.go.id..".script.breakAway type(target) == "..type(target) )   
									    end   
									--This uses the default broken crate debris model as a placeholder for a custom debris model.
									    if target then --References to target would sometimes fail for some unknown reason.
									        local debris = target:spawn("barrel_crate_block_broken"):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
											target:destroyDelayed()
									     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
**BTW: You will notice that the updated version of the floors do not always collapse; it's intentional. A minor update to the drop_floor script allows one to set (or get) the behavior of random breaking, and the chances of it happening when triggered.

Example: drop_floor.script:getChanceOfBreak() returns the current chance that any floor will collapse, and this chance can be set using setChanceOfBreak(.4) using any value between zero and one.

Random breaking can be enabled/disabled using setRandomBreak(true) —or false

**I've updated the previous post and version on dropbox.
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas »

I think i have another way which doesn´t Need an embedded script. Just paste the script in to a lua file (here Breaking_Floor.lua) and Change class Null for this
SpoilerShow
{
class = "Null",
onInit = function(self)
if ( findEntity("drop_floor") == nil ) then
local drop_floor = spawn("script_entity",1,0,0,0,0,"drop_floor")
drop_floor.script:loadFile("mod_assets/....../Breaking_Floor.lua"); --Import the function in the lua file
end
end,
},
Akroma: For some reason setsource doesn´t work, but loading a complete new file to the script does work for me.

Question: Why is the gravity component turned off once the broken Barrel reaches the ground? I want to my different Levels one above another. So once the upper plate breaks first i have a broken Barrel hovering on the underlying plate. When this one breaks to now, i have a hovering broken Barrel in that place.
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: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Wooden floor breaking definition

Post by Isaac »

Xardas wrote:Question: Why is the gravity component turned off once the broken Barrel reaches the ground? I want to my different Levels one above another. So once the upper plate breaks first i have a broken Barrel hovering on the underlying plate. When this one breaks to now, i have a hovering broken Barrel in that place.
Gravity is turned off to prevent the object from processing gravity while on the floor—where it usually does nothing.

Unless you have several stacked floors like the one in my demo, I would recommend that you only enable gravity on those objects that can (ever) fall further at a later time. If that's what you do have, then you can try commenting out the gravity disable line, and test your game performance; but it would probably be better to re-enable the gravity components on a case-by-case basis, as the floor disappears underneath them.

** (yet another) Update:

After experimenting with a way to implement this, I found that I liked the addition, and added it to the script. It now supports the debris falling additional elevation levels, while not having active gravity on objects that will never fall. It has an option to disable the new behavior (presumably if it's not needed).

https://www.dropbox.com/s/2qh1gxxvdpcou ... r.zip?dl=1
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Wooden floor breaking definition

Post by Xardas »

Great! :D
I should have nothing more to add now. This Floor is a hundred times better than the Floor i asked for.

**
Ok i promise this is the last Thing i´m asking now. :lol:
I was trying to make myself a Little set of this floor
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 of your current Version
One that breaks with 100% Chance and without a delay.

The dummy was easy to make, but i´m stuggling with the 100% break. Is there a way to add another line to the breakAway function, so when the objects name, from which the function was called is "wooden_floor_break_apart_instant", the breaking executes ?
The delay shouldn´t be a Problem. I can just change the time of delayedCall in the Definition then.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Wooden floor breaking definition

Post by kelly1111 »

Great to see so much creativity happen !!!!

Thanks for this little gem. I will be using it in my mod (if I ever stop remaking it from scratch) that is
Post Reply