[SCRIPT] Automatic Elevator with Working LEDs

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!
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

[SCRIPT] Automatic Elevator with Working LEDs

Post by ninjanerdbgm »

--
EDIT: For a simpler elevator, here is my original script
--

Hey guys, I made the old elevator script posted in the megathread and decided to expand upon it.

It has gone through a few.. uh, changes. I now present to you an automatic elevator with functional LEDs!

Features

- Functional dynamic LEDs that indicate what level you wish to travel to, and which level you're currently on.
- The floor now gradually changes color as you travel. It makes the journey more interesting.
- Automatic floor detection! You no longer need a button on each floor. Just one and done!
- The player controls which floor to travel to. They cannot change their minds once the elevator is in motion.

--

Here are a few images:

(Here's a link to the imgur album if you have trouble seeing this images)
SpoilerShow
Image
In this image, you see the basic setup. The green LEDs indicate the floor you're currently set to travel to, and the red LEDs indicate the floor you're currently on. The levers control which floor you go to.
The leftmost lever is set to 0 and 1, the middle is 0 and 2, and the right is 0 and 3. Using this setup, you can travel to any floor between 0 and 6.
SpoilerShow
Image
This image shows how the green LEDs update dynamically as soon as a lever is flipped.
SpoilerShow
Image
The elevator in motion! Of course, images don't do that part justice, so I've uploaded a video to youtube to show you how it works: http://youtu.be/edTBrcRdr1M

--

Now for the good stuff. The script is quite large, and involves a number of assets, so instead of pasting everything here, I've just zipped up my dungeon_editor file and folder. Below is a dropbox link. The 7z includes all scripts and assets. Just pop it into your documents/almost human/legend of grimrock 2/dungeons folder, open up the dungeon editor, then load the file.

Feel free to use any part of my script for your mod. I only ask for a little credit when you do use them.

Script HERE: https://www.dropbox.com/s/kkhgnyv32a5qu ... st.7z?dl=0

Hope you guys enjoy!
Last edited by ninjanerdbgm on Tue Nov 11, 2014 5:21 pm, edited 2 times in total.
User avatar
maneus
Posts: 246
Joined: Mon Jun 17, 2013 10:42 pm
Location: Switzerland

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by maneus »

That is really good work, ninjanerdbgm. Thumbs Up!
This elevator with smooth level changes is what I could needed in my LoG1 mod "Lucretius´s Thunder".
But in LoG1 it is only doable with hidden teleporters. :(
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by Drakkan »

thats quite high-tech elevator, well done ! :)
Do you plan also some "oldschool" one without these fancy LED´s ? You know...just some rusty cage going up and down with one lever :)
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by Doridion »

Drakkan wrote:Do you plan also some "oldschool" one without these fancy LED´s ? You know...just some rusty cage going up and down with one lever :)
Drakkan, he always done an old-school elevator, but i agree, giving the both examples on the first post would be great ;)

ninjanerdbgm, just edit your first post and add the first elevator ^^
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by Batty »

Very cool, but I placed a Herder on the bottom floor, it was on the square in front of the elevator when I went up.

When I got out on the higher floor, the Herder blocked me even though it was on the bottom floor. I had to go back down and kill it, then go back up, then I could get out.

Using setWorldPositionY() to move things works visually at least but seems to leave some properties, such as blocking, in their original position.

Edit: setWorldPositonY() might not be the cause, you could scan the floor and get all the entities and move them in the opposite direction that the elevator travels (moveEverything() function).

See petri's post about this.
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by ninjanerdbgm »

Batty wrote:Very cool, but I placed a Herder on the bottom floor, it was on the square in front of the elevator when I went up.

When I got out on the higher floor, the Herder blocked me even though it was on the bottom floor. I had to go back down and kill it, then go back up, then I could get out.

Using setWorldPositionY() to move things works visually at least but seems to leave some properties, such as blocking, in their original position.

Edit: setWorldPositonY() might not be the cause, you could scan the floor and get all the entities and move them in the opposite direction that the elevator travels (moveEverything() function).

See petri's post about this.
I ran into that as well. This script is more of a proof of concept than anything.

In its current state, it would work very well in a cinematic mod. Very cool idea, moving everything around the elevator in the opposite direction. I didn't think of that!
Drakkan wrote:thats quite high-tech elevator, well done ! :)
Do you plan also some "oldschool" one without these fancy LED´s ? You know...just some rusty cage going up and down with one lever :)
If you'd like, you could check out my original elevator script. It's much simpler. It's just up to a designated floor, then back down. If you'd like to use the user-directed elevator without LEDs, you could use the modified scripts below. Warning though, they're untested:

First, delete the script that generates the LED grid. In the modpack I provided in the original post, it's the script just north of the elevatorScript.

Second, use this modified elevatorScript:

Code: Select all

-- Init and positioning --

e_i = 0
elevator:setWorldPositionY(0)
force_field_1:setWorldPositionY(-0.5)
force_field_1.controller:deactivate()
lever_1:setWorldPosition(45,-0.18,46.05,0)
lever_2:setWorldPosition(45,-0.18,46.5,0)
lever_3:setWorldPosition(45,-0.18,46.95,0)
wall_button_1:setWorldPosition(45,0.4,46.5,0)
local wall_h = elvbuttonwall_1:getWorldPosition()
wall_h[1] = wall_h[1] - 0.1
elvbuttonwall_2:setWorldPosition(wall_h)
elv_door:setWorldPositionY(3)
sound_1.sound:stop()
	
-- Get Defaults --
d_emissive_color = force_field_1.model:getEmissiveColor()
d_colo = force_field_1.light:getColor()

-- Begin Functions --

-- MATH OH THE MATH --

function roundFloor(a)
 return math.floor(a+0.5)
end

-- Color Effects --

function rColor()
	return math.random() + math.random(0,2)
end

function changeColor()
	if not col then col = math.random(1,360) end
	local r = math.abs(math.cos(col))
	local g = math.abs(math.sin(col))
	if not b then local b = math.abs((col % 2) - (1 - math.random())) end
	force_field_1.model:setEmissiveColor(vec(r,g,b,0))
	force_field_1.light:setColor(vec(r,g,b,0))
	if col >= 360 then
		goingdown = true
	end
	if col <= 0 then
		goingdown = false
	end
	if goingdown then 
		col = col - 0.005 
		if b then b = b - 0.1 end
	else 
		col = col + 0.005 
		if b then b = b + 0.1 end
	end
end		

-- Find out floor --

function getFloor()
	floor = 0
	if lever_1.lever:isActivated() then 
		floor = floor + 1 
	end
	if lever_2.lever:isActivated() then 
		floor = floor + 2 
	end
	if lever_3.lever:isActivated() then 
		floor = floor + 3 
	end	
	floor = floor * 3
	return floor
end

-- Elevator Door --

function closeDoor()
	elv_door.door:enable()
	if elv_door:getWorldPositionY() > (elevator:getWorldPositionY()) then
		elv_door:setWorldPositionY(elv_door:getWorldPositionY() - 0.1)
		return
	end
end	

function openDoor()
	if elv_door:getWorldPositionY() <= (elevator:getWorldPositionY() + 3) then
		elv_door:setWorldPositionY(elv_door:getWorldPositionY() + 0.05)
		delayedCall(self.go.id,0.05,"openDoor")
		return
	end		
	elv_door.door:disable()
	if party.x == elevator.x then playSound("gate_lock") end
end

openDoor()

-- Move Elevator --

function moveEverything()
	elevator:setWorldPositionY(e_i)
	party:setWorldPositionY(e_i)
	force_field_1:setWorldPositionY(e_i-0.5)
	elvwall_1:setWorldPositionY(e_i)
	elvwall_2:setWorldPositionY(e_i)
	elvcorner_1:setWorldPositionY(e_i)
	elvcorner_2:setWorldPositionY(e_i)
	elvcorner_3:setWorldPositionY(e_i)
	elvcorner_4:setWorldPositionY(e_i)
	elvbuttonwall_1:setWorldPositionY(e_i)
	elvbuttonwall_2:setWorldPositionY(e_i)
	elv_roof:setWorldPositionY(e_i+3)
	elv_door:setWorldPositionY(e_i)
	lever_1:setWorldPositionY(e_i-0.18)
	lever_2:setWorldPositionY(e_i-0.18)
	lever_3:setWorldPositionY(e_i-0.18)
	wall_button_1:setWorldPositionY(e_i+0.4)
end

-- Elevator Movement --

function goUp()
	if getFloor() < e_i and not moving then
		goDown()
		return
	end
	if getFloor() ~= 0 then
		wall_button_1.clickable:setSize(vec(0,0,0))
		lever_1.clickable:setSize(vec(0,0,0))
		lever_2.clickable:setSize(vec(0,0,0))
		lever_3.clickable:setSize(vec(0,0,0))
		if e_i < getFloor() then
			force_field_1.controller:activate()
			if not moving then
				sound_1.sound:play("pushable_block_hover")
				sound_1.sound:fadeIn(1)
				sound_1.sound:setVolume(2.5)
				sound_1.sound:setPitch(0.8)
				--[[ Optional Output
				hudPrint("Going Up...")
				--]]
				playSound("gate_close")
				moving = true
			end
		    closeDoor()
			if elv_door:getWorldPositionY() <= elevator:getWorldPositionY() then
				if not doorclosed then
					playSound("gate_lock")
					doorclosed = true
				end
				mvamt = 0.02
				e_i = e_i + 0.02
				moveEverything()
				changeColor()
				party.party:shakeCamera(0.02,0.05)
			end
			delayedCall(self.go.id,0.05,"goUp")
			return
		else
			if moving then
				playSound("wall_sliding_lock")	
				--[[ Optional Output
				hudPrint("You've arrived at floor "..(getFloor()/3))
				--]]
			end
			elevator:setWorldPositionY(getFloor())
			party:setWorldPositionY(getFloor())
			for i=37,72 do
				local t = findEntity("floor_led_"..i)
				local j = findEntity("floor_led_"..(i-36))
				t:setWorldPositionY(j:getWorldPositionY())
			end
			playSound("gate_open")
			force_field_1.controller:deactivate()
			force_field_1.model:setEmissiveColor(vec(d_emissive_color))
			force_field_1.light:setColor(vec(d_color))
			moving = false
			doorclosed = false
			openDoor()
			wall_button_1.clickable:setSize(vec(.25,.25,.25,0))
			lever_1.clickable:setSize(vec(.4,.6,.4,0))
			lever_2.clickable:setSize(vec(.4,.6,.4,0))
			lever_3.clickable:setSize(vec(.4,.6,.4,0))
			sound_1.sound:fadeOut(1)
		end
	end	
end


function goDown()
	wall_button_1.clickable:setSize(vec(0,0,0))
	lever_1.clickable:setSize(vec(0,0,0))
	lever_2.clickable:setSize(vec(0,0,0))
	lever_3.clickable:setSize(vec(0,0,0))
	if e_i > getFloor() then
		force_field_1.controller:activate()
		if not moving then
			sound_1.sound:play("pushable_block_hover")
			sound_1.sound:fadeIn(1)
			sound_1.sound:setVolume(2.5)
			sound_1.sound:setPitch(0.8)
			--[[ Optional Output
			hudPrint("Going Down...")
			--]]
			playSound("gate_close")
			moving = true
		end
	    closeDoor()
		if elv_door:getWorldPositionY() <= elevator:getWorldPositionY() then
			if not dooropen then
				playSound("gate_lock")
				dooropen = true
			end
			mvamt = -0.02
			moveEverything()
			changeColor()
			party.party:shakeCamera(0.02,0.05)
			e_i = e_i - 0.02
		end
		delayedCall(self.go.id,0.05,"goDown")
		return
	else
		if moving then
			playSound("wall_sliding_lock")	
			--[[ Optional Output
			if getFloor() / 3 ~= 0 then 
				hudPrint("You've arrived at floor "..(getFloor()/3))
			else
				hudPrint("You've arrived at ground floor.")
			--]]
		end
		elevator:setWorldPositionY(getFloor())
		party:setWorldPositionY(getFloor())
		playSound("gate_open")
		force_field_1.controller:deactivate()
		force_field_1.model:setEmissiveColor(vec(d_emissive_color))
		force_field_1.light:setColor(vec(d_color))
		moving = false
		dooropen = false
		openDoor()
		wall_button_1.clickable:setSize(vec(.25,.25,.25,0))
		lever_1.clickable:setSize(vec(.4,.6,.4,0))
		lever_2.clickable:setSize(vec(.4,.6,.4,0))
		lever_3.clickable:setSize(vec(.4,.6,.4,0))
		sound_1.sound:fadeOut(1)
	end
end	
That removes the LEDs. If you don't want LEDs or the multi-colored floor while it's in motion, try this one:

Code: Select all

-- Init and positioning --

e_i = 0
elevator:setWorldPositionY(0)
force_field_1:setWorldPositionY(-0.5)
force_field_1.controller:deactivate()
lever_1:setWorldPosition(45,-0.18,46.05,0)
lever_2:setWorldPosition(45,-0.18,46.5,0)
lever_3:setWorldPosition(45,-0.18,46.95,0)
wall_button_1:setWorldPosition(45,0.4,46.5,0)
local wall_h = elvbuttonwall_1:getWorldPosition()
wall_h[1] = wall_h[1] - 0.1
elvbuttonwall_2:setWorldPosition(wall_h)
elv_door:setWorldPositionY(3)
sound_1.sound:stop()

-- Begin Functions --

-- MATH OH THE MATH --

function roundFloor(a)
 return math.floor(a+0.5)
end

-- Find out floor --

function getFloor()
	floor = 0
	if lever_1.lever:isActivated() then 
		floor = floor + 1 
	end
	if lever_2.lever:isActivated() then 
		floor = floor + 2 
	end
	if lever_3.lever:isActivated() then 
		floor = floor + 3 
	end	
	floor = floor * 3
	return floor
end

-- Elevator Door --

function closeDoor()
	elv_door.door:enable()
	if elv_door:getWorldPositionY() > (elevator:getWorldPositionY()) then
		elv_door:setWorldPositionY(elv_door:getWorldPositionY() - 0.1)
		return
	end
end	

function openDoor()
	if elv_door:getWorldPositionY() <= (elevator:getWorldPositionY() + 3) then
		elv_door:setWorldPositionY(elv_door:getWorldPositionY() + 0.05)
		delayedCall(self.go.id,0.05,"openDoor")
		return
	end		
	elv_door.door:disable()
	if party.x == elevator.x then playSound("gate_lock") end
end

openDoor()

-- Move Elevator --

function moveEverything()
	elevator:setWorldPositionY(e_i)
	party:setWorldPositionY(e_i)
	force_field_1:setWorldPositionY(e_i-0.5)
	elvwall_1:setWorldPositionY(e_i)
	elvwall_2:setWorldPositionY(e_i)
	elvcorner_1:setWorldPositionY(e_i)
	elvcorner_2:setWorldPositionY(e_i)
	elvcorner_3:setWorldPositionY(e_i)
	elvcorner_4:setWorldPositionY(e_i)
	elvbuttonwall_1:setWorldPositionY(e_i)
	elvbuttonwall_2:setWorldPositionY(e_i)
	elv_roof:setWorldPositionY(e_i+3)
	elv_door:setWorldPositionY(e_i)
	lever_1:setWorldPositionY(e_i-0.18)
	lever_2:setWorldPositionY(e_i-0.18)
	lever_3:setWorldPositionY(e_i-0.18)
	wall_button_1:setWorldPositionY(e_i+0.4)
end

-- Elevator Movement --

function goUp()
	if getFloor() < e_i and not moving then
		goDown()
		return
	end
	if getFloor() ~= 0 then
		wall_button_1.clickable:setSize(vec(0,0,0))
		lever_1.clickable:setSize(vec(0,0,0))
		lever_2.clickable:setSize(vec(0,0,0))
		lever_3.clickable:setSize(vec(0,0,0))
		if e_i < getFloor() then
			force_field_1.controller:activate()
			if not moving then
				sound_1.sound:play("pushable_block_hover")
				sound_1.sound:fadeIn(1)
				sound_1.sound:setVolume(2.5)
				sound_1.sound:setPitch(0.8)
				--[[ Optional Output
				hudPrint("Going Up...")
				--]]
				playSound("gate_close")
				moving = true
			end
		    closeDoor()
			if elv_door:getWorldPositionY() <= elevator:getWorldPositionY() then
				if not doorclosed then
					playSound("gate_lock")
					doorclosed = true
				end
				mvamt = 0.02
				e_i = e_i + 0.02
				moveEverything()
				party.party:shakeCamera(0.02,0.05)
			end
			delayedCall(self.go.id,0.05,"goUp")
			return
		else
			if moving then
				playSound("wall_sliding_lock")	
				--[[ Optional Output
				hudPrint("You've arrived at floor "..(getFloor()/3))
				--]]
			end
			elevator:setWorldPositionY(getFloor())
			party:setWorldPositionY(getFloor())
			playSound("gate_open")
			force_field_1.controller:deactivate()
			moving = false
			doorclosed = false
			openDoor()
			wall_button_1.clickable:setSize(vec(.25,.25,.25,0))
			lever_1.clickable:setSize(vec(.4,.6,.4,0))
			lever_2.clickable:setSize(vec(.4,.6,.4,0))
			lever_3.clickable:setSize(vec(.4,.6,.4,0))
			sound_1.sound:fadeOut(1)
		end
	end	
end


function goDown()
	wall_button_1.clickable:setSize(vec(0,0,0))
	lever_1.clickable:setSize(vec(0,0,0))
	lever_2.clickable:setSize(vec(0,0,0))
	lever_3.clickable:setSize(vec(0,0,0))
	if e_i > getFloor() then
		force_field_1.controller:activate()
		if not moving then
			sound_1.sound:play("pushable_block_hover")
			sound_1.sound:fadeIn(1)
			sound_1.sound:setVolume(2.5)
			sound_1.sound:setPitch(0.8)
			--[[ Optional Output
			hudPrint("Going Down...")
			--]]
			playSound("gate_close")
			moving = true
		end
	    closeDoor()
		if elv_door:getWorldPositionY() <= elevator:getWorldPositionY() then
			if not dooropen then
				playSound("gate_lock")
				dooropen = true
			end
			mvamt = -0.02
			moveEverything()
			party.party:shakeCamera(0.02,0.05)
			e_i = e_i - 0.02
		end
		delayedCall(self.go.id,0.05,"goDown")
		return
	else
		if moving then
			playSound("wall_sliding_lock")	
			--[[ Optional Output
			if getFloor() / 3 ~= 0 then 
				hudPrint("You've arrived at floor "..(getFloor()/3))
			else
				hudPrint("You've arrived at ground floor.")
			--]]
		end
		elevator:setWorldPositionY(getFloor())
		party:setWorldPositionY(getFloor())
		playSound("gate_open")
		force_field_1.controller:deactivate()
		moving = false
		dooropen = false
		openDoor()
		wall_button_1.clickable:setSize(vec(.25,.25,.25,0))
		lever_1.clickable:setSize(vec(.4,.6,.4,0))
		lever_2.clickable:setSize(vec(.4,.6,.4,0))
		lever_3.clickable:setSize(vec(.4,.6,.4,0))
		sound_1.sound:fadeOut(1)
	end
end	
Like I said, those modifications are untested and might throw errors if you just copy/paste them in. If that happens and you can't figure out the error, just give me a holler!
coolAlias
Posts: 11
Joined: Sun Oct 19, 2014 5:06 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by coolAlias »

Neat! If you switched to binary, you could get 8 floors out of the same 3 levers: 000, 001, 010, 011, 100, 101, 110, 111
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by Leki »

Ninja, we really need bigger images... please, next time try 4K :roll:
I'm the Gate I'm the Key.
Dawn of Lore
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by ninjanerdbgm »

Leki wrote:Ninja, we really need bigger images... please, next time try 4K :roll:
What? I can't read your 240p text. ;)
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [SCRIPT] Automatic Elevator with Working LEDs

Post by MrChoke »

This is very cool. Thanks for sharing it.

I do see one problem though. As the elevator is moving, you can walk through the door even though its closed. Of course this results in you getting squashed by the floor platforms that you hit. Don't know what the deal is but that is what I am seeing.
Post Reply