Simple door script
This is a very basic door which can be pushed by a creature to transfer to the linked door, or by the hand to teleport the camera and the creatures that are currently touching the door.
We will create four doors: two on the upper level of the norn meso, and their partnering doors in the workshop and comms room. These doors will be CA linked, and both creatures and the hand will be able to push the door to be transferred to the partnering door. When the door is clicked, it will enumerate over all the doors with the classifier you use and search for the partnering door. If they found their partnering door, the creature(s) and/or the hand will be moved to that door. There will also be a removal script that enumerates over all doors, kills them and remove the script from the scriptorium.
- Make the script run instantly
- Make the first door! This one is going to be the leftmost door in the top left part of the norn meso. This door will link to the agent injector.
- Create a simple object that classifies as a door. For convenience's sake, we will use the image of the existing DS teleporters, which are called "ds portals.c16" in the image folder. I will just be using 1 sprite, the 11th, since that one looks cute. You could totally use your own sprite or even add animations in the push script, just be sure to ajdust the image_count and first_image in the new: simp script. We want the door's plane to be behind the creature, so we'll set it to 550.
new: simp 2 2 20855 "ds portals" 1 11 550
- Give the door the correct attribute flags, we'll make them clickable by the pointer, which means a total attribute value of 4.
- Now give the door the correct behaviour: creatures can activate 1 (push) it, which makes for a total behaviour value of 1.
setv ov00 0
- Move the door to the correct place: this one goes in the upper left part of the norn meso. You can pick your own spot by clicking ctrl-alt-x ingame, then the pointer will show the coordinates it's currently at.
mvto 810 8814
- Get the room id of the xcoord ycoord of the door, then set it in a temporary variable va00
- We made our first door! On to the second one, which is the partnering door of the first one. The second one can be found at the workshop, at the bottom left.
new: simp 2 2 20855 "ds portals" 1 11 550 attr 4 bhvr 1 setv ov00 0 mvto 4478 9368 setv va01 grap posx posy
- Now, to allow Cellular Automata to travel freely, we'll link these two doors, using the temporary variables va00 and va01.
link va00 va01 100
- The first two doors are done now. Let's now make the next two doors (which belong to another door group, so their OV00s are different from the first group.) The third door is in the norn meso, a bit to the right of the first door, and the fourth door is in the agent injector. Then we'll link the third and fourth door.
new: simp 2 2 20855 "ds portals" 1 11 550 attr 4 bhvr 1 setv ov00 1 mvto 910 8827 setv va00 grap posx posy
new: simp 2 2 20855 "ds portals" 1 11 550 attr 4 bhvr 1 setv ov00 1 mvto 6305 9097 setv va01 grap posx posy
link va00 va01 100
- You now made 4 doors. Congratulations! Now we have to write their activation script.
- Create an event script for the doors that activates when you send a Push message to it. Don't forget to close your script block with endm at the end.
scrp 2 2 20855 1
- We want this script to be locked, so it can't be interrupted by other norns when someone activated it.
- Hmm, so we got a push message. Let's enumerate over all doors to find your partnering door. Don't forget to close your enumeration block with next at the end of the enumeration script. Before we can enumerate, we'll have to save the object variable of the door that received the click into a temporary variable, since when you enumerate over agents, they get TARGeted and you won't be able to reach any of the object variables of the original door. We will save the door group (stored in ov00).
- You're now inside of the enumeration loop. Make sure that the door you're currently targeting isn't the door being activated.
doif targ ne va01
- Check if this door belongs to the same group as the original door
doif ov00 eq va00
- If yes, WOO, you've found your partnering door! Let's save the coordinates in temporary variables first.
setv va02 posx setv va03 posy
- Now, let's check who actually called the script: was it the pointer and do we need to teleport all touching creatures AND the camera, or was it a creature and do we only have to teleport that creature, and eventually the camera if it's locked to that creature?
- Let's assume it's the pointer first. If it is the pointer
- Move the center of the camera to the xcoord ycoords of the partnering door
cmrp va02 va03 1
- Target the original door
- For each creature touching the door:
etch 4 0 0
- Check if the creature can move to the xcoord ycoords of the partnering door. If they can, move them.
doif tmvf va02 va03 eq 1 mvft va02 va03 endi
- End the creatures enumeration loop and "pointerclick" script.
- Now let's assume it's not the pointer but a creature. Then just that creature should be moved, but if the camera is locked on that creature, then the camera view should move too. Check if it's a creature:
- If it's a creature, target it and check if it can be moved to the xcoord ycoord of the partnering door.
targ from doif tmvf va02 va03 eq 1
- If the camera is currently tracking this creature, move the camera.
doif trck eq from cmrp va02 va03 1 endi
- Move the creature
mvft va02 va03
- End the block where it checks whether the creature can move, and the creatureclick script.
- When you've found the partnering door, stop the script at the end of this block, so it won't run any inneccessary enumeration loops
- End the 'if found partnering door' block, the 'if not me' block and the 'enumerate over all doors' loop.
- Unlock and end the script
- The removal script identification tag
- Enumerate over all the doors and kill them
enum 2 2 20855 kill targ next
- Remove the push script from the scriptorium
scrx 2 2 20855 1