Really bad and new to scripting.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Chaze007
Posts: 1
Joined: Thu Apr 17, 2014 10:31 pm

Really bad and new to scripting.

Post by Chaze007 »

So I'm completely new to this and can't really wrap my head around. I'm sure this is fairly basic but I have no idea how to do it.

I'd like to make a function when you pick up a key_1 it closes door_1 and opens door_2. :/ Any help would be great
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Really bad and new to scripting.

Post by Isaac »

Chaze007 wrote:I'd like to make a function when you pick up a key_1 it closes door_1 and opens door_2. :/ Any help would be great
Do you mean when the player picks up the key (like off of the ground), that it causes one door to close, and another to open?
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Really bad and new to scripting.

Post by msyblade »

Doing this off the top of my head (and I SUCK at scripting), but I think this one is easy :) Let us know if it doesn't work off the bat.

NOTE: You will need to replace some of this with your actual door names.

Create a "script entity" near the puzzle. First, you will need the key to be on a "trigger". An alcove or Altar will work great for this. On the right side of the editor, with the altar selected, choose "add connector" there will be a box that lets you choose "Activate", "deactivate", or "any". This is to select whether you want the connection to trigger when something is placed ON the altar (activate), taken OFF of the altar (deactivate, the one you want), or any change (put on OR taken off). Normally, deactivate will only work when the last item is removed, you can select the "always activate" box to make it react when ANYTHING is removed, regardless of how many objects are left. I would suggest not to do this, as the player could place a rock on the altar, then remove it to trigger the script. Now, connect the altar to the script entity, set to "deactivate", and paste this code into the SE (after changing the objects to your objects names, exact syntax is imperative):

Code: Select all

function takekey()
mydoor_1: close()
mydoor_2: open()
end
I hope that looks simple enough to you, it really is that straightforward. It will not be foolproof, resourceful modders will be able to find cracks in this and possibly cheat it (replacing the object in the correct order, etc.). And a better scripter could write a more complex script to counter that problem. But if you just want one door to open, and another to close, it should work fine.

This is a more secure code (but less likely to work right away, because,as I said, I'm not very good at this.)

Code: Select all

function takekey2()
for i in myaltar_1:containedItems() do
if i.name == "the_key" then
door_1:open()
door_2:close()

else

door_1:close()
door_2:open()		
break
		
        end
	
   end
end
If this gives you trouble, remove an "end" and try it again. Otherwise, the first code may work for your purpose.

Hope this helps!
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Post Reply