Blockland

Blockland

49 ratings
Simple Event Script guides
By Attack Badger
A collection of simple scripts (And maybe some not-so-simple ones) for use in Blocklands.
   
Award
Favorite
Favorited
Unfavorite
A Simple Key Locked Door / Auto-closing Door Tut
So let's say you wanted to make a locked door, and you only wanted that door to open using a key. This is pretty simple, really.

First, build your door. Also, paint your door the same color as the key you want to use with it (Green for a green key, red for a red key, etc)


And then give it a name. You name things by using your wrench on them, and typing a name in the NAME field.



(Naming things that you/other people will interact with will save you a lot of time later, because you will be able to easily find it in the <Named Block> listing). Something like "Locked Door".

Now, click on the Events button on the bottom of the item properties window. It will bring up a window with a listing of all the actions assigned to that door.

For more information on the functions of these events, see CommunistSquared's Basic Guide to Eventing For Dummies, also in the guide section.

Now, we don't want the door to just open up anytime somebody comes up and taps on it, because that would defeat the whole purpose of locking it. So what we have to do is remove the "onActivate" toggle, so that the door doesn't do anything at all. For the moment.

So what you will do, is select the "-" from the InputEvents list, which will cancel that action on the door. Now, we just have to assign the door a key check function.


So, we pick the event "onKeyMatch" which means when the correct color key is used on the door (Keys are used like your wrench or a gun, from the q menu), the door will complete this line of events. Now, we pick a target that we want to execute the action on. In this case we can use "Self" since we're using the key directly on the door.


Following that, we pick what kind of action we want taken. Since we want the door to open, we pick "door" from the OutputEvents list.


And finally we pick what we what that door to do, from the list of actions that doors can take.



But what do you do if somebody uses the wrong color key on the door? Well for that, we use function onKeyMismatch.

Start a new line of events, and select onKeyMismatch as your input event.



Then, pick an action. In this case, we're going to execute a function on the player, instead of the door.


Select an appropriate action. Here, we're going to make the player be instakilled if they use the wrong key.


But what if they don't have a key at all, and come up and tap the door? Well, why don't we make it play an alarm then. Start a new event line, and pick onActivate, just like the door had before we even messed with it.

Now, instead of executing the function on the door, or on the player, we'll execute one on the client. This way, only the player who actually tries to use the door will get the alarm sound; anyone nearby won't hear anything at all.
And assign it a playSound function, which will play whatever sound we select next on the client's game.


Finally, pick a sound that you want played. This one is a warning alarm type of sound.



Now, spawn yourself another block, give it a name (in this case, Green Key Spawner), and in the item menu, select Green Key. This will spawn a green key you can pick up.



Try using the key on the door now, and you'll see it should pop right open for you. Since we used Toggle in the output event, if you repeatedly use your key you can make the door open and close as much as you want.


Spawn yourself another block, only this time make the item a Yellow Key.


Try using your new, yellow key on the door, and POW.


Auto-closing door
"But Badger" you might say, "Now I have a spiffy locked door, but if I open it it just stands there, letting whoever walks by come right in! How do we fix this?"

Quite simple, really, using that little function on the Events list called Delay. Delay functions as a timer, making the object wait a specified ammount of time (up to 30 seconds) before executing that line of events. This time is listed in milliseconds, or 1/1000th of a second. So if you wanted the block to wait 5 seconds before doing the action, you would put 5000 in the Delay box.

So, to make our door close behind us, we can use Delay coupled with a specific door check to close it. Go back to your door events list, start a new line at the very bottom, and enter 1500 in the delay box. Then pick onDoorOpen which means this event line will only happen if the door is standing open, self since we're making this door the target, then the Door and Close options to force the door to close itself.


Now once you use the right key on the door, the door will stand open for 1.5 seconds (plenty of time to get through) and then promptly close behind you, keeping others out.
A Simple Two-Position Lightswitch
Now that we've got a little experience with events under our belt, let's try making a remote switch. In this case, we're going to make a lightswitch to turn on a lamp.

Build yourself a light, and a remote switch.


Name the brick you want to light up something, like Light.


And name your switch something else, like Light Switch.


Now, looking at the switch block's event list, we're going to pick onActivate, so that the player has to tap it to make it work.


But since we want to make the bulb light up and not the switch, instead of picking self like we did for the door, we're going to specify a particular block, using <Named Block>.



Now we're going to tell the switch what action we want the bulb to do when we hit it, so we pick setLight.


And then pick whichever light you want, here we'll use Yellow Light.

Now we're going to make the second function, which is what will happen if the player hits the switch a second time.

First, uncheck the enable box, which means that this function won't automatically happen.

Again select onActivate since we want the player to tap the switch to make this work.

Use the <NamedBlock> function again to specify that we want the light bulb to be effected.


And specify the right name in the field.


Now we're going to use another setLight command.

Except this time we're going to set the light to None, which will turn the light off.


Now we add the toggle function, which will switch between the two lines of events when we tap the switch block.

onActivate on the Switch.


Select Self (the switch block) this time, since that's what we will hit to make the toggle.


From the Output Events menu, scroll all the way to the bottom and hit toggleEventsEnabled.


And finally, in the text field, enter 0 1. This tells the switch what event lines to swap.


Now, send your events, exit the item properties window, and use the light switch block. The light should come on.


And using it again should shut it off.
Making a hidden door / false walls
So in this tutorial we're going to play with a few new Events, and some of the more advanced block functions.

First, we need a wall and some trigger plates. Here the plates are colored for easy viewing, normally you would make these the same color as your floor so they blend in.

Now, name all the bricks in the wall that you want to pass through. Make sure they all have the EXACT same name[/b]


Now, go to your first switch plate, and use the onPlayerTouch function, which means the player has to walk over or run into the switch, rather than physically using it.


From the <NamedBrick> menu, select the name of the wall bricks you want to walk through.


Now, from the output events menu, select setColliding, and make sure the box is unchecked.



Add a second event line, with a 1500ms delay, to toggle the collision back on (so that other players can't pass through behind you) like so.


Now, when you run over the trigger plate, you have 1.5 seconds to pass through the wall, before it turns solid behind you. However, the wall will not appear to be one you could walk through.

If you want to make it so that once a player passes through the wall that the first switch is disabled (Essentially, making it so the first player through is the only one getting through) simply add a second trigger plate on the opposite side of the wall, and use <NamedBrick> to select your first switch, and then toggleEventEnabled to turn off the functions on the first plate.
14 Comments
DeedalaDee 3 Oct, 2021 @ 1:08pm 
fuck this i cant do that
BuoYancY_dabl 18 Mar, 2020 @ 12:19pm 
P.S. if door makes "toggle" sound when player without key tries to open the closed door the do this:

0 enabled onKeyMatch Self door Open
1 disabled onActivate Self door Close
2 disabled onActivate Self setEventDisabled 1 2
3 enabled onKeyMatch Self setEventEnabled 1 2
BuoYancY_dabl 18 Mar, 2020 @ 12:14pm 
About the door: you can make it semi-key. For example use this:
onKeyMatch Self door Open
onActivate Self door Close

So that you doesnt need the key to close the door.
krazy maestro 20 Oct, 2018 @ 1:26am 
good eventing guides but the light switch does not wor for me:steamsad:
DebraDi 16 Apr, 2017 @ 3:12pm 
only one worked i need help it was A simple key locked door
scramandius 16 Dec, 2016 @ 1:26pm 
Im trying to make shades for my house is there a way to toggle there visibility?
Shorp 26 Nov, 2016 @ 6:02am 
or do onkeymismatch setcolor (key color) while the door well stay the same color
perro pepsi 24 Sep, 2016 @ 6:33pm 
@Steee
OnActivate>Self>FireRelay
OnRelay>Self>SpawnExplosion/Projectile>any
OnRelay>Self>FireRelay
ayy kekkooooooo
Steee 7 Jul, 2016 @ 10:41am 
you should add an autofiring baseplate for trolling section :p
spacebar 21 May, 2016 @ 2:12am 
Wow, I may be a 100k, but I never could get doors to close by themselves or make lights toggle in one brick. Thank you! (I'm 1%Spacebar)