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

Wooden floor breaking definition

Post by Xardas » Tue Sep 05, 2017 12:23 am

I made a Breaking Floor via script yesterday and tried to figure out how to make the object Definition for it, because i intend to use it more often.
Failed miserably, since i haven´t really defined anything for now. Here are the versions of the plates i want as objects.
Version 1: Instant Break
SpoilerShow
function makeplate()

local trapplate = self.go:spawn("urban_town_wooden_floortrigger")

trapplate.floortrigger:addConnector("onActivate", self.go.id, "Trap")
trapplate.floortrigger:setDisableSelf(true)

function Trap(plate)

---[[ particle effects:
plate.go:createComponent("Particle")
plate.go.particle:setParticleSystem("hit_wood")
plate.go.particle:setDestroySelf(true)
plate.go.particle:fadeOut(.7)
--]]

party.party:shakeCamera(.5,.5)
playSound("barrel_die")
delayedCall(self.go.id, .7, "erasePlate", plate.go.id)
end
end

makeplate()

function erasePlate(plateId)
findEntity(plateId):destroy()
end
Version 2: delayed break
SpoilerShow
function makeplate()

local trapplate = self.go:spawn("urban_town_wooden_floortrigger")

trapplate.floortrigger:addConnector("onActivate", self.go.id, "Trap")
trapplate.floortrigger:setDisableSelf(true)

function Trap(plate)

---[[ particle effects:
plate.go:createComponent("Particle")
plate.go.particle:setParticleSystem("hit_wood")
plate.go.particle:setDestroySelf(true)
plate.go.particle:fadeOut(.7)
--]]
playSound("barrel_hit")
delayedCall(self.go.id, 1, "next", plate.go.id)

function next(plate)
---[[ particle effects:
local plate = findEntity(plate)
plate:createComponent("Particle")
plate.particle:setParticleSystem("hit_wood")
plate.particle:setDestroySelf(true)
plate.particle:fadeOut(.7)
--]]
party.party:shakeCamera(.5,.5)
playSound("barrel_die")
delayedCall(self.go.id, .7, "erasePlate", plate.id)
end
end
end

makeplate()

function erasePlate(plateId)
findEntity(plateId):destroy()
end
And here is the attempt to make a Definition for Version 1
SpoilerShow
defineObject{
name = "urban_town_wooden_floortrigger_instant",
baseObject = "floor_trigger",
components = {
{
class = "Model",
model = "mod_assets/sx_urban_town/models/sx_house01_wooden_ceiling.fbx",
},
{
class = "Platform",
},
{
class = "FloorTrigger",
self.go.floortrigger:setDisableSelf(true),
onActivate = function(self)
self.go:createComponent("Particle")
self.go.particle:setParticleSystem("hit_wood")
self.go.particle:setDestroySelf(true)
self.go.particle:fadeOut(.7)


party.party:shakeCamera(.5,.5)
playSound("barrel_die")
delayedCall(self.go.id, .7, "erasePlate", self.go.id)
end,

erasePlate = function(plateId)
findEntity(plateId):destroy()
end,
},
},
placement = "floor",
editorIcon = 184,
}
The pressure plate I use in the script is made from the urban_town_wooden_ceiling from The Winter Tileset made by Skuggasvein.
It is nothing more than a platform with wooden texture combined with a floortrigger.
I welcome any help for my Problem. :)
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 » Tue Sep 05, 2017 1:59 am

Code: Select all

defineObject{
name = "urban_town_wooden_floortrigger_instant",
baseObject = "urban_town_wooden_ceiling",
components = {
		{
		class = "FloorTrigger",
		onActivate = function(self)
						self.go.floortrigger:setDisableSelf(true)
						self.go:createComponent("Particle")
						self.go.particle:setParticleSystem("hit_wood")
						self.go.particle:setDestroySelf(true)
						self.go.particle:fadeOut(.7)
						---[[  This uses the default broken crate debris model as a placeholder for a custom debris model.
							local   debris = self.go:spawn("barrel_crate_block_broken"):createComponent('Gravity')
								  debris.go.gravity:setDestroySelf(true)
						--]]	
						playSound("barrel_die")
						party.party:shakeCamera(.5,.5)
						self.go:destroyDelayed()
					 end,
		}
	}
}
**It should be noted that the definition must appear in the files after the definition for urban_town_wooden_ceiling, otherwise there is no baseObject definition to derive from, and an error will result.

Also: Have you looked at the forest_bridge model? It is also a wooden floor that could be used instead.

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

Re: Wooden floor breaking definition

Post by Xardas » Tue Sep 05, 2017 8:31 pm

I like the broken Barrel you added. The forest Bridge doesn´t fit when making a room with different heights. There would be little gaps between the tiles.
Is there a possible way to make the destruction of the plate more delayed, so the Player has the Chance to react and can avoid falling down?
Something like the delayedCall command or adding a timer component could work.
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 » Wed Sep 06, 2017 12:47 am

Xardas wrote:I like the broken Barrel you added. The forest Bridge doesn´t fit when making a room with different heights. There would be little gaps between the tiles.
It is possible to dynamically scale & deform the models at runtime. Small gaps are easily fixed. ;)
Is there a possible way to make the destruction of the plate more delayed, so the Player has the Chance to react and can avoid falling down?
Something like the delayedCall command or adding a timer component could work.
Yes it's doable.

Here is a quick modification that does the trick:
___________
**Update: There was a snag, but minmay reminded me of the reason for it. It's fixed and working as intended. I have rewriten this to use a shared script among all break-away floors.
SpoilerShow

Code: Select all

defineObject{
name = "urban_town_wooden_floor_break_apart",
baseObject = "urban_town_wooden_ceiling",
components = {
     {
         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([[
	                  			 function breakAway(target) 
                                       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.
                                         local debris = target:spawn("barrel_crate_block_broken"):createComponent('Gravity')
                                                 debris.go.gravity:setDestroySelf(true)   
                                       target:playSound("barrel_die")
                                       target:destroyDelayed()
                                 end
	                  		]])
	                  end
                  end,      
      },

      {
       class = "FloorTrigger",
       onInit = function(self) 
            self.go.floortrigger:setTriggeredByItem(false)
             end,
       onActivate = function(self)
                local delay = 1.5
                   
                   self.go.floortrigger:setDisableSelf(true)
                   self.go:createComponent("Particle")
                   self.go.particle:setParticleSystem("hit_wood")
                   self.go.particle:setDestroySelf(true)
                   self.go.particle:fadeOut(delay)
                party.party:shakeCamera(.5,.5)
                self.go:playSound("creaky_floor")
                  delayedCall("drop_floor", delay, "breakAway", self.go.id)
                end,
      },

   }
}

defineSound{
	name = "creaky_floor",
	filename = {
		"assets/samples/monsters/mimic_walk_01.wav",
		"assets/samples/monsters/mimic_walk_02.wav",
		"assets/samples/weapons/hit_wood_die_01.wav"  --barrel_hit
		},
	loop = false,
	volume = 0.7,
	minDistance = 1,
	maxDistance = 10,
	clipDistance = 5,
}
}
This new floor is fun. I just made a room full of them, and the party leaves a path of collapsed floors behind them, as they traverse the room.
Last edited by Isaac on Wed Sep 06, 2017 6:37 pm, edited 7 times in total.

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

Re: Wooden floor breaking definition

Post by Xardas » Wed Sep 06, 2017 1:51 pm

That really looks nice! :D
Thanks for your help. I don´t think i could have done the Definition.

The current Version seems to cause some Trouble in my Project. For some reason the Floor is unable to spawn the script in the first Level, which i don´t understand. For now i added the script myself and it works fine, but as soon as i remove it, the Floor doesn´t call the function, so it only performs the particle effects and the first shake of the camera. When placing the Floor object in the first Level i can´t even run the Editor :shock: . I´m trying to figure out what is happening here, but at the Moment i´m helpless.
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 » Wed Sep 06, 2017 5:50 pm

Is it the updated version (above); I made several changes from the original; (repeatedly updating the same post).
*I just updated it today too.

In your preview, what do you get when you type print(findEntity("drop_floor").id) into the console? (*The console must be enabled in the game.)

*You should see it print 'drop_floor'; if not, something is wrong.

If it prints drop_floor, then next, copy/paste/Enter this line into the console:

Code: Select all

for each in party.map:allEntities() do if each.name == "urban_town_wooden_floor_break_apart" then drop_floor.script.breakAway(each.id) end end
This line should trigger run the drop_floor script for every floor asset in your map.

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

Re: Wooden floor breaking definition

Post by Xardas » Wed Sep 06, 2017 8:18 pm

Wow this Floor is getting better and better ;) . Didn´t realize you put up a new Version. Unfortunately i have the same Problem as in the old Version.
Well at least i do now know that the plates do spawn the script.
The Entity was found, so it printed out drop_floor
The second line i got was this:
SpoilerShow
[string "user-Input"]:1: attempt to call field 'breakAway' (a nil value)
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 » Wed Sep 06, 2017 8:22 pm

Xardas wrote:The second line i got was this:
SpoilerShow
[string "user-Input"]:1: attempt to call field 'breakAway' (a nil value)
A quick question: Do you have a script_entity on the map named drop_floor? It is no longer needed. If you have one, and didn't add anything else to it, you can delete it; otherwise change it's name if you don't erase it. You only need the floor objects now.

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

Re: Wooden floor breaking definition

Post by Xardas » Wed Sep 06, 2017 8:26 pm

Yep i know. I only have the Floor now. I think the Problem is somewhere in Setting the source to the script.
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 » Wed Sep 06, 2017 10:36 pm

Does the floor object work in a new map?

Or try mine:
**Updated version
https://www.dropbox.com/s/2qh1gxxvdpcou ... r.zip?dl=0
(Which anyone is welcome to take apart and use.)

Image
Last edited by Isaac on Thu Sep 07, 2017 7:42 pm, edited 4 times in total.

Post Reply