Cob Tutorial 8
Well you have come a long way since the first cheese tutorial now! (If you started with that one anyway) I had to look hard through my cob files to find anything new to put in this tutorial. :) In this tutorial you will create the blueberry vendor available for download on my website. The most important new stuff in this tutorial is the concept of targets (which was touched on in the last tutorial) and timer scripts.
inst new: simp hblv 29 0 3500 0 setv attr 199 setv cls2 2 8 31505 bhvr 1 1 slim edit endm
Nothing new here.
scrp 2 8 31505 1 setv va04 targ setv actv 0 setv va00 posx addv va00 53 setv va01 posy addv va01 22 snde vend base 0 anim over base 10 anim over rndv va03 1 2 doif va03 eq 1 inst new: simp hblu 7 0 3500 0 setv cls2 2 7 31502 setv attr 195 bhvr 0 64 slim mvto va00 va01 setv grav 1 slow else doif va03 eq 2 inst new: simp hblu 7 0 3500 0 setv cls2 2 7 31502 setv attr 195 bhvr 0 64 slim mvto va00 va01 setv grav 1 slow endi endi targ va04 anim over base 20 anim over base 0 pose 0 endm
scrp 2 8 31505 1 setv va04 targ
Here we are storing the current target of the script in a variable called va04 for later use. The concept of a target is a very important one in caos scriptinh. The target is the object that the script is focusing on. When you play a game like Diablo and aim your weapon at one of the monsters, the monster you are focusing on is your target. This is exactly the same in caos scripting. If the script is focusing on the norn that is currently selected and telling it how it should behave or finding out its properties (ie. telling it to drop the object it is holding) then the norn is the target. If the script is focusing on the hand and tell it how to behave or find out its properties (ie. finding the top left coordinate of the hand in Albia) the hand is the target. If the script is telling the object itself what to do or finding out its properties (ie. finding out the attributes set for the object) the object is the target. By default the target of a script is the object itself. For the target to be anything else it must be manually changed (as seen later in the script). In this line of script we are setting (setv) the variable (va04) to the current target (targ) so we can set the target later on in the script back to what it was originally.
setv actv 0 setv va00 posx addv va00 53 setv va01 posy addv va01 22 snde vend base 0 anim over base 10 anim over rndv va03 1 2 doif va03 eq 1 inst new: simp hblu 7 0 3500 0
The target is now changed from being the blueberry vendor to the blueberry juice that has just been created by the new: simp command.
setv cls2 2 7 31502 setv attr 195 bhvr 0 64 slim mvto va00 va01 setv grav 1 slow
This is sort of the opposite of the inst command. The inst command makes the script following it occur without interuption (so creatures doesn’t autosave halfway though injecting a cob or something). The slow makes the rest of the script execute at a normal pace.
else doif va03 eq 2 inst new: simp hblu 7 0 3500 0 setv cls2 2 7 31502 setv attr 195 bhvr 0 64 slim mvto va00 va01 setv grav 1 slow endi endi targ va04
We have now set the target back to what it was at the beginning of the script. At the beginning of the script the target was the blueberry vendor. Then the target changed to the cup of blueberry juice when the cup of blueberry juice wall installed. Now the target is the blueberry vendor again so we can finish the animation. If we didn’t set the target to the blueberry vendor creatures would try to animate the cup instead. And the vendor would be stuck where it was when the cup was injected.
anim over base 20 anim over base 0 pose 0 endm
scrp 2 8 31505 6 snde drop endm
Blueberry juice eat script
scrp 2 7 31502 12 snde drnk anim tick 60
Tells Creatures to activate the timer script (script number nine) in 60 ticks. The command layout is tick
stim writ from 0 255 0 0 37 150 50 150 73 150 70 150 endm
Blueberry juice Timer script
scrp 2 7 31502 9
Script nine is the timer script which is activated by the tick
kill targ endm
Blueberry juice drop script
scrp 2 7 31502 6 snde drop endm
The concept of a target is really important in Creatures as it enables the commands in the script not to effect just the object itself, but also interact with other creatures and objects near it. :) You’ve really got a good grip on cobbing now if you understand everything you’ve learnt in the tutorials so far. I think there is only a few more simple objects I can do a tutorial on now and then we can move on to stuff like rooms and movers. :)
The vendor sprite used in this cob was created by NORNgod (http://www.norngod.com)