Scripting Punishable Failures

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
VannisMaule
Posts: 3
Joined: Sat Mar 23, 2013 5:29 am

Scripting Punishable Failures

Post by VannisMaule »

I want to create a combination lock for a door, using wall buttons, and if/when the player gets the combo wrong, a demon head will shoot a fire ball down a hallway at the player. I'm new the the LUA scripting language, and have had nothing but trouble with it.
If I could just get a demon head to even cast a spell that would help.
I would also like to know what variables I used to use things other than levers to interact with the script interface, like Pressure plates, buttons, and torches. I would also like help with linking scripts to object other than doors, such as timers, teleporters, and demon heads that cast spells.

I'm a huge novice at this scripting language, the only languages I ever learned were binary and HTML 4, neither of which can save my sorry novice hide, and there is no how to script LUA for dummies.

I know it's a lot to ask, so if I could just get short, to the point answers it would help a lot! Thanks!
Alcator
Posts: 37
Joined: Fri Apr 13, 2012 9:59 am

Re: Scripting Punishable Failures

Post by Alcator »

So, you don't get demon head to shoot fire, actually.
What you get is an invisible object called SPAWNER (find it in the "Logic" section of objects), to which you'll write "fireball" or "fireball_greater" as the projectile.
Then, all you do is [spawner]:activate() to make it shoot 1 fireball.

Then the trick is to "evaluate" the levers/buttons. Depending on how complex the solution is, this can be done completely without scripting, or some scripting may be required.

For instance, if you had 4 levers next to one another and the solution was "Up"-"Down"-"Down"-"Up",
you could do this:

1. Place a COUNTER object and set its initial value to 4* (read below on this value).
2. Each lever will have 2 connectors to this COUNTER object: First connector will be "activate", the other will be "deactivate" (i.e., the first happens when the lever goes DOWN, the other when it goes UP). The 1st and 4th lever would have the ACTION of the first connector "INCREMENT" and of the second "DECREMENT", while the 2nd and 3rd would be the opposite.

Regarding the initial value of the counter: This must be set in such a way that if the levers are moved to their correct positions, then the associated actions ("decrement") will reduce it to 0 -- and that's where you'd connect the Opening of doors.
In our scenario, this depends on starting positions. If their starting positions were UP-UP-UP-UP, then we see that 2 levers are already in correct position, so we must lower the Counter initial value to 2. For "DOWN-UP-UP-UP", we have only 1 lever in correct position --> initial value would be 3.

I strongly recommend you get this done first, then we can proceed with "programming".
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Scripting Punishable Failures

Post by Neikun »

Hi! Welcome to the forums.
We're usually pretty good at helping out around here. I'm doing some digging in some old threads for read through of some common problems people new to modding Grimrock face.
viewtopic.php?f=14&t=3771
viewtopic.php?f=14&t=4564
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: Scripting Punishable Failures

Post by SpiderFighter »

VannisMaule wrote:I want to create a combination lock for a door, using wall buttons, and if/when the player gets the combo wrong, a demon head will shoot a fire ball down a hallway at the player. I'm new the the LUA scripting language, and have had nothing but trouble with it.
If I could just get a demon head to even cast a spell that would help.
I would also like to know what variables I used to use things other than levers to interact with the script interface, like Pressure plates, buttons, and torches. I would also like help with linking scripts to object other than doors, such as timers, teleporters, and demon heads that cast spells.

I'm a huge novice at this scripting language, the only languages I ever learned were binary and HTML 4, neither of which can save my sorry novice hide, and there is no how to script LUA for dummies.

I know it's a lot to ask, so if I could just get short, to the point answers it would help a lot! Thanks!
First, welcome!!
The things you're asking are not too complex, but you're asking to run before you can even crawl. I'd strongly suggest you look at Komag's excellent video tutorials and then my own tutorials. In this way, you'll see how everything works together (and, in Komag's, you can actually build a level along with him).

Answering a question about scripting before you can hook up a spawner is a bit like asking a question about a quadratic equation before you can do basic math. :)
VannisMaule
Posts: 3
Joined: Sat Mar 23, 2013 5:29 am

Re: Scripting Punishable Failures

Post by VannisMaule »

Levers is not the problem. Here's the situation:

Here is the hallway. You are teleported to the first space (represented by "T") and can walk down a hallway which has four buttons ( represented by "+") and a closed door (represented by "X"). You are seperated from the demon head and spawner to cast the fireball (represented by "D") by a pit (represented by "P")

________________________
X____+__+__+__+___T__P__ D


I can script a basic combination lock using levers, but contextually I would like to use wall buttons instead.

I tried to do this:

-- Door to Kayart Lock
function pullLever()
if wall_button_8:getLeverState() == "activated" and
wall_button_9:getLeverState() == "deactivated" and
wall_button_10:getLeverState() == "deactivated" and
wall_button_11:getLeverState() == "activated" then
temple_ornate_door_7:open()
else
combinationDoor:close() and
**Demon Spitfire**
end
end

I knew from the start I would need help on this, but I figured I would give a try first. There has to be something to use that isn't getLeverState, the function must be different, and there has to be a code for the Spawner to activate upon inacurate combination rather than just running on a timer. I'd like to do a lock in which I could ask the party to press the buttons in a certain order, but I thought making a combination would be more simple since I already knew how to do it from the Wiki supplied on this site.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting Punishable Failures

Post by Ryeath_Greystalk »

One thing that jumps out to me is this

wall_button_9:getLeverState() == "deactivated" and

a wall button is only a toggle, it does not have a state. The getLeverState() only works with levers, not buttons (as far as I know).

One way you may be able to do it is to connect each button to a counter. Set up the button to increment the counter and start each counter at 0. Then have a script that each button push calls that checks the value of each counter. So maybe something like this (assume correct order is button 3,2,4,1)

Code: Select all

edited out non functional code. :x 


This has not been tested but I think it ought to work.
Last edited by Ryeath_Greystalk on Fri Mar 29, 2013 12:40 am, edited 1 time in total.
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: Scripting Punishable Failures

Post by SpiderFighter »

Ryeath_Greystalk is right; buttons are "toggle" only, which means you wouldn't be able to do a combination lock per se. However, as a workaround, you can always leave one of those buttons unconnected. A couple of other options are to have some or all of your fireballs already running (trigger them via a hidden plate just before the player walks into view, or else you're wasting CPU cycles), or connect your buttons to separate counters (B and C to decrement a counter (set to "2) attached to the pit/spawner and also a counter set to 4 that resets the first counter (possibly along with a hudPrint message to let the player know the puzzle has reset) and buttons A and D set only to decrement the second counter).

[EDIT] The problem with buttons is that they can only increment or decrement; they can't do both (the way a lever can alternate). What this means for your puzzle is that the player can simply press button B or C twice and the pit will close. A workaround to that is to have each button "Activate Once" and then, when your counter resets the puzzle, have it destroy all 4 buttons and spawn new ones.

But...yeah...levers are the way to go here.

[EDIT AGAIN:] If you want buttons pressed in a certain order (instead of only a couple activated), this script might help.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting Punishable Failures

Post by Ryeath_Greystalk »

- sequentially work your way through counters in sequential order

redundant statement is redundant :lol:

I should not have tried to figure it out when I should have been sleeping. The code I posted is not going to work. I will try and get it fixed but probably not til tomorrow.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting Punishable Failures

Post by Ryeath_Greystalk »

Ok, try this, or something like it.

First thing I fixed was I made it unnecessarily complicated by using numbers for counter names and letters for the script. Change that to counter_a, counter_b, counter_c, counter_d.

Second thing I did to make it more complicated was trying to match the variables to the order of the button presses and match that to the counters. All I really needed to do was put the buttons and variables in the same order first to last and you can make your puzzle by putting in different order on the wall.

In summary just have button_a increment counter_a and call the script, button_b increment counter_b and call the script, button_c increment counter_c and call the script and finally button_d increment counter_d and call the script. Have each counter initial setting to 0. You do not need to connect the counters to anything they are just place holders. Put the buttons on the wall in any order you want, but the door will only open if the are pressed in order a, b, c, d. If they are pressed out of order the spawner will lite em up.

This code has not been tested but it should work. I may find a place to use it in my dungeon.

Code: Select all

-- combination lock

function comboLock()

-- set local variables
	
	local a = counter_a:getValue()
	local b = counter_b:getValue()
	local c = counter_c:getValue()
	local d = counter_d:getValue()

-- check for proper press sequence
-- start with first button in sequence and work to last

	if a == 1 then
		if b == 1 then
			if c == 1 then
				if d == 1 then
					hallwayExitDoor:open()
				end
			elseif d ~= 0 or c > 1 then
				spawner_1:activate()
				counter_a:reset()
				counter_b:reset()
				counter_c:reset()
				counter_d:reset()
			end
		elseif c ~= 0 or d ~= 0 or b > 1 then
			spawner_1:activate()
			counter_a:reset()
			counter_b:reset()
			counter_c:reset()
			counter_d:reset()
		end
	elseif b ~= 0 or c ~= 0 or d ~= 0 or a > 1 then
		spawner_1:activate()
		counter_a:reset()
		counter_b:reset()
		counter_c:reset()
		counter_d:reset()
	end
end		
				


I took the time to flow chart this one out so I feel pretty good about it.

Hope this helps.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting Punishable Failures

Post by Ryeath_Greystalk »

Ok tested out and it worked beautifully.
Post Reply

Return to “Modding”