COB Tutorial Lesson 5: Cheese vendor NOTE: I've replaced cven.spr with a ZIPped version of the file. The old one did not always download correctly. So far we've covered food, removers, objects with external scripts, and weeds. Let's move on to another very important type of object: vendors. Many of us are familiar with the carrot vendor. But the carrot vendor appears in a remote part of Albia, largely inaccessable to Norns who might need it elsewhere. Fortunately, there are carrots in the garden. But what about cheese and other foods? Cheese is the most nutritious food in Albia, and most of us don't want to be bothered injecting it every time a Norn is really hungry. So why not make a way for Norns to get cheese whenever they want it? Step 1: The sprite file What's different about this COB is that it has a sprite file to go with it: The cven.spr file is needed to display the cheese vendor. (We could use the carrot vendor's sprites, but that displays- surprise!- carrots.) Currently the easiest way to make SPR files is to create a bitmap (.BMP) file with an image editor, then change it to an SPR file with Alexander Laemmle's COE. (If you use version 1.4 of COE, you'll need to make sure all the colors in your image use only the colors in the Creatures palette.) This sprite file is 64 pixels wide, 100 high. This information will be important later. To use this COB, you must copy cven.spr to the \Images directory. If you make a COB with its own sprites or sounds, be sure to make a text file with instructions on how to do this; otherwise, people will make the Newbie Mistake and forget. Step 2: The object classes This step is important, but brief. It's important to put the vendor object in family 2, genus 8; those are the vendor objects. I'm going to choose species 65, which I've used for a lot of objects in the tutorials; hopefully no one else has made an object of class 2 8 65. The cheese objects are all class 2 6 1. Scripts for eating cheese are already installed in the scriptorium (they'd better be!), since there's cheese in the world when the world is created. There's no need to install new scripts for cheese, just to create the cheest object itself. It will know what scripts to use, since we'll tell it it's in the same class as all the other cheese in the world. Step 3: The installation script Start CobCom and click the list box marked "Installation Scripts" ("Imports" in CobCom 1.02 or earlier). In the edit box, type in the following: inst new: simp cven 1 0 500 0 setv clas 34095360 setv attr 70 bhvr 1 1 edit Now, let's look through the new lines for this script. new: simp cven 1 0 500 0 Well, we're making a new object that uses the cven.spr sprite file. That's nothing new. You may notice, though, that I wrote in 500 for the image plane (how far forward or back the object is) instead of the usual 3500. Most objects use 3500, but we want this to appear behind the creatures who use it; I experimented and found out that 500 will do, though 1000 will not. setv clas 34095360 This object is in family 2, genus 8, species 65. setv attr 70 "70?" you say. Yes, 70. I got this value by adding up 2 (hand can pick up object), 4 (hand can activate object), and 64 (wallbound; a typical attribute for most objects). If I'd wanted creatures to be able to pick it up, I'd have added another 1 to get 71. The values for the attr flag are available in the macro.rtf or macro.html files on the Reference page. bhvr 1 1 This says that either the hand or a creature can activate the object. The first 1 says what the hand can do; the second says what the creature can do (in this case, it can use activation function #1). These values are also available in macro.rtf and macro.html. edit That's it; we're ready to place the vendor in the world. All the necessary setup has been done. Step 4: The activation script Click on the list box labeled "Scripts", then type this into the edit box: scrp 2 8 65 1 snde vend wait 8 inst setv var0 posl setv var1 post addv var0 20 addv var1 76 new: simp food 3 3 3500 0 setv clas 33947904 setv attr 67 bhvr 0 1 setv obv0 1 pose 2 mvto var0 var1 targ ownr setv actv 0 endm Well, let's get to it. scrp 2 8 65 1 The script for family 2, genus 8, species 65, activation function #1. snde vend Makes the sound that the carrot vendor makes. It sounds like the machine is moving around and getting ready to spit something out. wait 8 Normally, a vendor would use the following two commands: anim [12345670] over However, this vending machine has no animation. So we'll just wait 8 ticks as if there was something to animate. inst Where have we seen this before? That's right, it's in all the installation scripts. All it means is that the next stuff happens in a single timer tick. That's necessary whenever you install a new object, as we're about to do. setv var0 posl setv var1 post addv var0 20 addv var1 76 This set of commands takes the machine's current position and stores it in two variables, adding 20 to the X position and 76 to the Y position. Why 20 and 76? Because the machine is 64 pixels wide and 100 high, and the cheese is 24 by 24. To center the cheese, you have to add (64-24)÷2 to the X position to center it, and (100-24) to the Y position to place it 24 pixels off the ground. When we create the cheese object, we'll move it to these coordinates. new: simp food 3 3 3500 0 setv clas 33947904 setv attr 67 bhvr 0 1 setv obv0 1 pose 2 This stuff makes the cheese object. The first command says to use the food.spr file which is already in the game. Cheese has 3 poses (the first "3" in the list of numbers), and starts at the 4th sprite in the file (index #3; hence the second "3" in the list). Then, the class is set to 2 6 1. Attributes are set to 67, which means the hand and creatures can pick it up, and it stays within the room (67=1+2+64). The behavior is set to 0 for the hand (which can't eat it), and 1 for creatures (they can use activation #1). Cheese uses the obv0 variable for some reason; I don't know why, so I'll just set it to 1. Then, we'll give it pose 2, since pose 2 is the piece of cheese resting on the ground. mvto var0 var1 See? I told you we'd move it later. This moves the new piece of cheese to a spot in front of the vending machine, on the ground. targ ownr We've finished placing the cheese, so change back to the vending machine (ownr is the object that owns the current script) so we can do something. setv actv 0 This is required to be able to activate the vending machine again. If it's not reset to 0, the machine will just sit there and do nothing. endm We're finally done. The script is over. Step 5: Using the object and moving forward Remember, above all else, you must copy cven.spr to the \Images directory; if you make such an object and distribute it, be sure to include both the SPR file and a text file that explains what to do with it. If you want, you can use CobCom to import a picture from the cven.spr file and put it in the object file. This is just for appearances, though, and it's completely optional. To use the object, just inject it. Then you can click on it to make cheese appear. You don't have to click on the red button, though; it's just there to make it look good. Show the vending machine to your creatures so they can learn to use it. If you want to make the object even better, make a sequence of new sprites and animate them using the commands above. The carrot machine does this to show the carrot being delivered.