Page 2 of 4

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 12:17 am
by Xardas
It works perfect in a new dungeon. I might have a bug in my Project :|

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 6:52 am
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.

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 2:58 pm
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!

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 4:38 pm
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...?

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 5:19 pm
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!

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 6:30 pm
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.

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 8:44 pm
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.

Re: Wooden floor breaking definition

Posted: Thu Sep 07, 2017 9:57 pm
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

Re: Wooden floor breaking definition

Posted: Fri Sep 08, 2017 1:15 am
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.

Re: Wooden floor breaking definition

Posted: Fri Sep 08, 2017 10:10 am
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