[Models] New created Models..

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: [Models] New created Models..

Post by germanny »

The tube fixing..
(The scripts are updated after i find an error!)
SpoilerShow
Tube leak with burning gas..
Image
While burning it can´t fixed, so close the valve..
Image
The metal_patch is inserted, then click with toolbox on it - fixed!
Image
Now the valve work normal as a 'lever' asset!
Video:
Youtube:The fixing process in action!

The idea:
- party finds a tube with handwheel valve (Example: operate an invisible engine via gas steam)
- the valve is reqired to trigger next events (Examples: open a door, dry a flooded level entrance..)
- but the tube has a leakage; gas streams out and burns if the wheel valve is open (activated)
- party must fix the leakage with a metal patch and tools (they have to find the items of course^^)
- for fixing, the handwheel valve has to be closed (deactivated) and metal_patch must attached to the tube.
- one click with the toolbox on the tube leakage while metal_patch is inserted will fix the tube.
- if handwheel is again opened (activated), the burning gas steam + sound is gone and event is triggered.

Parts used:
- tube with leakage asset
- handwheel asset def. as lever
- metal_pach_tube asset def. as decoration
- alcove object placed exactly at leakage position
- 1x metal_patch, 1x toolbox items
- custom sounds: 2x for handwheel, 1x steam burning, 1x fixing sound
- 1x lightsource over the leak, 1x invisible lightsource with burning particle system, placed inside the leak
- 4x script - steam playsound, handwheel actions, alcove actions(yet placed in objects.lua), handwheel sound-replacer
- 1x timer for looped non-loop sound-playback (thx Isaac!)
- 1x counter to make 'tubefixed' event from alcove noticeable to the handwheel script

All works well now - a bit noobish scripted i guess^^
Lots of ifs and elseif checks to prevent errors..
Scripts work in editor and in compiled game file!

The Scripts:

This script is for replace lever sounds;
placed in dungeon without connections.

Script Name: leverSndSet

Code: Select all

----begin -----------------------------------------------
-- Set connectors to all levers in dungeon (thx to Isaac!)

for l = 1, getMaxLevels() do
      for e in allEntities(l) do
         if  e.class == "Lever" then
            e:addConnector('any', 'leverSndSet', 'playLvSnd')
         end
         end
end

-- The function to play custom sounds
function playLvSnd(dmDungLev)

-- define and set variables
local lvState = dmDungLev:getLeverState()
local lvLevl = dmDungLev.level
local lvNam = dmDungLev.name
local lvFac = dmDungLev.facing
local lvPosX = dmDungLev.x
local lvPosY = dmDungLev.y

-- play sounds for each state
	if lvNam == 'dm_lever_wheel' and lvState == 'activated' then 
		playSoundAt("leverwheel_open", lvLevl, lvPosX, lvPosY)
	
	elseif lvNam == 'dm_lever_wheel' and lvState == 'deactivated' then 
		playSoundAt("leverwheel_close", lvLevl, lvPosX, lvPosY)

	end	
end

Script to place in dungeon for the handwheel valve,
added connector from handwheel lever.
initial state: deactivated
Action on connector: any

Script Name: steamChx

Code: Select all

----begin -----------------------------------------------

function togglActivity(self)

local triggerCif = counter_2:getValue()
local lvState = self:getLeverState()
local lvLevl = self.level
local lvNam = self.name
local lvFac = self.facing
local lvPosX = self.x
local lvPosY = self.y
local fxEmit = "dm_conduit_fx_emitter"
local fxLight = "dm_conduit_fx_light"
local fxEmId = "cond_fx_emit_1"
local fxLiId = "cond_fx_light_1"
local timerNam = timer_1

	if lvState == 'activated' and triggerCif == 0 then 
		timerNam:activate()
			spawn(fxEmit, lvLevl, lvPosX, lvPosY, lvFac, fxEmId)
				spawn(fxLight, lvLevl, lvPosX, lvPosY, lvFac, fxLiId)
	elseif lvState == 'activated' and triggerCif > 0 then
		-- begin place further actions here!
		
		if dm_door_steamop:isClosed() then
			dm_door_steamop:open()
		end
		
		-- end place further actions here!	
	elseif lvState == 'deactivated' then
			for i in entitiesAt(lvLevl,lvPosX,lvPosY) do
    			if i.id == fxEmId or i.id == fxLiId then
					i:destroy()
				end
			end

		if timerNam:isActivated() then
			timerNam:deactivate()
		end

	end
end
----end -----------------------------------------------
The alcove definition in objects.lua:

Code: Select all

---begin------------------------------------------
defineObject{
	name = "dm_conduit_leak_socket",
	class = "Alcove",
	anchorPos = vec(-0.0826, 2.2, 0.9),
	anchorRotation = vec(0, 0, 0),
	targetPos = vec(-0.0826, 2.2, 0.175),
	targetSize = vec(0.06, 0.1, 0.1),
	placement = "wall",
	editorIcon = 92,

onInsertItem = function (self, item)

local countNam = counter_2
local triggerCif = countNam:getValue()

		if triggerCif > 0 then
			return false
		end

local metPat = "dm_metal_patch"
local tooBox = "dm_toolbox"
local fxEmit = "dm_conduit_fx_emitter"
local patCon = "dm_patch_conduit"
local patCid = "dm_patch_conduit_1"
local fxEmId = "cond_fx_emit_1"
local fxLiId = "cond_fx_light_1"

	for i in entitiesAt(self.level,self.x,self.y) do
		if i.id == fxEmId and item.name == tooBox or i.id == fxEmId and item.name == metPat then
				hudPrint("You can not fix the leak while burning!")
				return false
		elseif i.id == fxEmId then
				return false
		end
	end

	local px = 0

	for i in self:containedItems() do
		if i.name == metPat then
			px = px + 1
		end
	end

		if item.name ~= metPat or item.name ~= tooBox then
			setMouseItem(spawn(item.name))
		end

		if item.name == metPat and px == 0 then
			patchIsIn = true
				return item.name
			elseif item.name == metPat and px == 1 then
				setMouseItem(spawn(metPat))
					patchIsIn = true
			end

		if item.name == tooBox and px == 1 then
			toolIsIn = true
				setMouseItem(spawn(tooBox))
			elseif item.name == tooBox and px == 0 then
				setMouseItem(spawn(tooBox))
					toolIsIn = false
			end

		if patchIsIn == true and toolIsIn == true and px == 1 then
			playSoundAt("dm_repair",self.level,self.x,self.y)
				spawn(patCon,self.level,self.x,self.y,self.facing,patCid)

				for z in self:containedItems() do
		  			if z.name == metPat then
		  				z:destroy()
		  		end
			end

			hudPrint("The leak is fixed!")
				countNam:increment()
	end
end
}

---end------------------------------------------
The sound script for looped non-loop sound:
Connected to 'timer_1' ; its settings:
timer interval: 1.356, initial state: stopped

Script Name: timedLoopSnd

Code: Select all

----begin -----------------------------------------------
function loopedSound(self)
 playSoundAt('dm_steamburn',dm_lever_wheel_1.level, dm_lever_wheel_1.x, dm_lever_wheel_1.y)
end
----end -----------------------------------------------
A counter placed in dungeon, name: 'counter_2'
initial value: 0
No connector

And the sound definitions in 'sounds.lua':

Code: Select all

	defineSound{
        name = "lever",
        filename = "mod_assets/dmcsb_pack/samples/env/lever_nil.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 8,
    }

	defineSound{
        name = "leverwheel_open",
        filename = "mod_assets/dmcsb_pack/samples/env/dm_valvesqueak_open.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 9,
    }

	defineSound{
        name = "leverwheel_close",
        filename = "mod_assets/dmcsb_pack/samples/env/dm_valvesqueak_close.wav",
        loop = false,
        volume = 1,
        minDistance = 1,
        maxDistance = 9,
    }

    defineSound{
        name = "dm_steamburn",
        filename = "mod_assets/dmcsb_pack/samples/env/dm_steamburn.wav",
        loop = false,
        volume = 0.5,
        minDistance = 1,
        maxDistance = 8,
    }

    defineSound{
        name = "dm_repair",
        filename = "mod_assets/dmcsb_pack/samples/env/dm_repair.wav",
        loop = false,
        volume = 1.2,
        minDistance = 1,
        maxDistance = 6,
    }
Last edited by germanny on Sun Feb 09, 2014 1:21 pm, edited 10 times in total.
Dungeon Master Resource Pack worker and passionated Beer drinker
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Models] New created Models..

Post by Isaac »

That is seriously cool germanny!
chaoscommencer
Posts: 119
Joined: Sun Jan 05, 2014 7:48 pm

Re: [Models] New created Models..

Post by chaoscommencer »

Nice job man! It looks great.
Working on a dungeon that displays a massive collection of assets while sorting them into convenient reusable plugin format (concept from some of leki's mods). Will contribute some of my own models as well eventually and follow that with custom dungeon.
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: [Models] New created Models..

Post by germanny »

Thanks, was not so easy to do.. i am beginner with lua.
Teached me a lot. I had maany crashes and errors while scripting xD
Hopefully there are no conflicts with other things because i tried to use local variables if possible.
The local variables second is to make it easier to use the scripts with other assets, so often used
names are replaced by vars.
Dungeon Master Resource Pack worker and passionated Beer drinker
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Models] New created Models..

Post by Isaac »

germanny wrote:Thanks, was not so easy to do.. i am beginner with lua.
Teached me a lot. I had maany crashes and errors while scripting xD
Hopefully there are no conflicts with other things because i tried to use local variables if possible.
The local variables second is to make it easier to use the scripts with other assets, so often used
names are replaced by vars.
The most important thing to do is to export your game using your assets ~specifically your scripts, and ensure that the game loads and plays, and saves without crashing.
The editor is more forgiving than the regular game.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Models] New created Models..

Post by JohnWordsworth »

That's awesome Germanny! Nice idea and it looks great.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
chaoscommencer
Posts: 119
Joined: Sun Jan 05, 2014 7:48 pm

Re: [Models] New created Models..

Post by chaoscommencer »

I actually heard something about local variables vs global in another thread recently which made me think in a lot of cases global might be better. Correct me if I'm wrong, but I believe someone mentioned global variables get stored in your save files whereas local ones do not. So if you want to store the state of your pipes, etc. (patched vs. unpatched, for example) you might need those to be stored in a global variable. And don't store objects in those global variables--store IDs instead--because reloading with objects in global variables will crash the game. That's what I took from that post anyways, hopefully it's true and useful to everyone else ;)... I've already started coding around those potential issues since reading it.
Working on a dungeon that displays a massive collection of assets while sorting them into convenient reusable plugin format (concept from some of leki's mods). Will contribute some of my own models as well eventually and follow that with custom dungeon.
User avatar
BuzzJ
Posts: 160
Joined: Sat Jan 12, 2013 4:06 pm

Re: [Models] New created Models..

Post by BuzzJ »

The leaky pipe mechanic you have developed is IMMENSELY useful for a great number of environmental "repair" type puzzles. I hope others take notice of this and copy the technique for use in other areas.

Germanny, heres a related idea I'd be interested to see if you could figure out: building a baricade (blocker) at certain predefined locations using item tools. Thus, the area is passable, has GUI triggers, then impassable. Like, say blocking up a hole spiders are comming from, collapsing part of a tunnel with tnt, etc
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: [Models] New created Models..

Post by germanny »

chaoscommencer wrote:I actually heard something about local variables vs global in another thread recently which made me think in a lot of cases global might be better. Correct me if I'm wrong, but I believe someone mentioned global variables get stored in your save files whereas local ones do not. So if you want to store the state of your pipes, etc. (patched vs. unpatched, for example) you might need those to be stored in a global variable. And don't store objects in those global variables--store IDs instead--because reloading with objects in global variables will crash the game. That's what I took from that post anyways, hopefully it's true and useful to everyone else ;)... I've already started coding around those potential issues since reading it.
Thanks for the tip! I actually tested this again with compiled game - there is true an serialisation error while saving after tube fixing. Damn^^
I have to change some vars from local to global. Hopefully that will fix..
This is a weird trap, because the dungeon compiles without errors, but while game is saved - error.
Last edited by germanny on Mon Mar 10, 2014 12:43 am, edited 1 time in total.
Dungeon Master Resource Pack worker and passionated Beer drinker
User avatar
germanny
Posts: 530
Joined: Sat Apr 07, 2012 10:52 pm
Location: Kiel, Germany

Re: [Models] New created Models..

Post by germanny »

hopefully i have fixed the error now..
Was by saving the game while handwheel lever was 'deactivated'.
Error: "cannot serialize function 'searchTubeFx' with upvalues"

This was my code that caused the error:

Code: Select all

searchTubeFx = entitiesAt(wheelie.level,wheelie.x,wheelie.y)
			for i in searchTubeFx do
    			if i.name == fxEmit or i.name == fxLight then
					i:destroy()
				end
			end
I changed it to this:

Code: Select all

for i in entitiesAt(lvLevl,lvPosX,lvPosY) do
    			if i.id == fxEmId or i.id == fxLiId then
					i:destroy()
				end
			end
The local vars seems to work fine. searchTubeFx was interpreted as function, but is not..
So i removed and call entitiesAT directly. This fixed the issue.
Beside that i now use 'id' instead of 'name' , replaced the var 'wheelie' with 'self' and spawn the fx with specific 'id'
Dungeon Master Resource Pack worker and passionated Beer drinker
Post Reply