Welcome to the Creatures Wiki! Log in and join the community.

Difference between revisions of "Simple door script"

From Creatures Wiki
Jump to navigation Jump to search
(Initial submission)
 
m
Line 80: Line 80:
 
   mvft va02 va03
 
   mvft va02 va03
 
   [[DOIF|endi]]
 
   [[DOIF|endi]]
 
 
  [[DOIF|endi]]
 
  [[DOIF|endi]]
 +
* When you've found the partnering door, stop the script at the end of this block.
 +
stop
 
  [[DOIF|endi]]
 
  [[DOIF|endi]]
 
  [[ENUM|next]]
 
  [[ENUM|next]]

Revision as of 15:46, 31 May 2017

Summary

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.

Script contents

We will create four doors: two on the upper level of the norn meso, and their partnering doors in the workshop and agent injector. 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, kill them and remove the script from the scriptorium.

Install Script

  • Make the script run instantly
inst
  • 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.
attr 4
  • Now give the door the correct behaviour: creatures can activate 1 (push) it, which makes for a total behaviour value of 1.
bhvr 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 8914
  • Get the room id of the xcoord ycoord of the door, then set it in a temporary variable va00
setv va00 grap posx posy
  • 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 9468
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 8927
setv va01 grap posx posy
new: simp 2 2 20855 "ds portals" 1 11 550
attr 4
bhvr 1
setv ov00 1
mvto 6305 9197
setv va01 grap posx posy
link va00 va01 100
  • You now made 4 doors. Congratulations! Now we have to write their activation script.

Event Scripts

  • 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
  • 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 variables, 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 both the door group (stored in ov00), and a variable that refers to the original door.
setv va00 ov00
seta va01 targ
enum 2 2 20855
  • 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 ov01
  • 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 xcoord
setv va03 ycoord
  • 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, the camera should be moved to the door, together with all creatures that were touching it.
doif from eq pntr
 cmra xcoord ycoord 1
 targ ownr
 etch 4 0 0
 doif tmvf va02 va03 eq 1
  mvft va02 va03
 endi
  • 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.
elif crea from eq 1
 targ from
 doif tmvf va02 va03 eq 1
  doif trck eq from
   cmrp va02 va03
  endi
  mvft va02 va03
 endi
endi
  • When you've found the partnering door, stop the script at the end of this block.
stop
endi
next
endm

Removal script

  • The removal script identification tag
rscr
  • Enumerate over all the doors and kill them
enum 2 2 20855
kill targ
next
  • Remove the push script from the scriptorium
rscr 2 2 20855 1

Credits

Pilla