BYOND TUTORIALS

BY ADAM R. TURNER


 

Mob Creation and Map Basics
-Tutorials for non-know-hows from the in-the-know.

It is recommend you read the first Hello World! tutorial before reading this one.

Since we have already defined the world datum in the first example, it is quite easy to build off of this example and connect to our first mob.

If we recall from the previous example we defined the world datum like so:

Example:
world //The world datum
     name = "Hello World" //The name of our world.
     hub = "Rockinawsome.Hello World" //This is so it will show up in your hub when you register the game.

For this example we will build off the first example but change the name of the world and hub address. We will also drop the New() proc as it isn't necessary to redefine when creating a world unless you need to do something when the world is first created.

Example:
world //The world datum
     name = "My First World" //The name of our world.
     hub = "Rockinawsome.My First World" //This is so it will show up in your hub when you register the game.

Mobs are short for mobile, and represent player characters (referred to as PCs) and non-player characters (referred to as NPCs). Generally, if it moves, it's a mob. Mobs are also datums, but unlike the world datum, the mob datum only looks after things that pertain to the player's avatar, rather than the entire world.

Let's add an additional line to this that will tell the world what the default mob is; that is, the mob in which the player will play when he/she logs into the game:

Example:
world //The world datum
     name = "My First World" //The name of our world.
     hub = "Rockinawsome.My First World" //This is so it will show up in your hub when you register the game.
     mob = /mob/PC  //The path of our mob

This will set the default mob to mob/PC which we need to define, so after the code you already have, insert this:

Example:

mob
    PC

PC is a new type of mob, it branches off from it and in this way is declared as a new type. As a shortcut:

Example:
mob/PC

The above 2 examples accomplish the same thing, the first one is good for keeping code tidy and neat while the second provides an easy shortcut.

Notice not every line of code needs to be commented, but it's still a good idea.

Now for a bit of fun: go to the 'File' tab, select 'New', next to the Type option select the drop-down menu and press icon, after this give the icon a name, avoid special characters, but anything else will do. For mine I called it 'mob', press 'OK'. Presently a big empty white box should be displayed, above this a pallete icon and a camera are available, press the pallete icon. From this your garden variety of buttons are available much like Microsoft paint. Paint a picture of what you feel players should look like but use a color other than black for the moment, and for the purpose of this tutorial, it's best to keep it simple. When you are done select 'File' then 'Close', you will be prompted to save your picture,  make sure you do.

Now to add the icon to your mob we add the icon variable to the mob like so:

Example:
mob
    PC
        icon = 'mob.dmi' //set the icon variable to the icon file

Files are surrounded in single quotes, so to link the icon variable to the file, place the name of the icon file you just created beside the extension .dmi, and surround the two in single quotes as seen above.

Return to 'File' -> 'New', and select Map File. Give it a name. A prompt will appear asking for a size, since this is not a full blown game, I recommend either the default sizes, or something not much larger. The 'Z' option will increase the number of maps of the same proportion.

Now select 'Compile' from the 'Build' tab. To see what our world looks like return to the 'Build' tab and select 'Run'. This will allow us to see the player in motion. Already, BYOND's built in features allow us to move around at random with the arrow keys. If you can't see your player, it's because he's a color too close to black.

Background

You're probably thinking, "this all looks fine and dandy, except for the black background". And for you I have the answer: turfs. Turfs allow us to control the background of the game. So to create one we code it much the same way as we coded a mob:

Example:
turf
    grass
        icon = 'grass.dmi'  

Provided we created another icon the same way we created the icon for the mob, we now have a background that isn't black and boring. This means we can use black in our mob icons and they'll be visible, however - we still need to add it to the map file. So double-click the map you created (if you don't remember what you called it, it's extension is .dmp). Once you've double-clicked the map, the map editor will open before you.

On the left of your map editor two things are defined next to little plus signs. Select turf, now click grass (if you named it something else click that instead). By default 'Add' is selected, click the black dotted area to the right, notice the turf is added one at a time. To change this behavior click 'Fill', now it's possible to add to as much of the map as you want. Once the whole background is full, select 'Build' -> 'Compile', then 'Run' the program. Now your world is incredibly spiffy.

Icon direction and Movement

For the last part of this tutorial, select the icon  file you created for your mob by double clicking it. Once it has loaded, right click the icon you made for the mob and select 'Edit as Movie...', you'll now be able to several options at the bottom of the white rectangle, and inside the rectangle your icon. Find the #Dirs option, press the down arrow and select '4'. You will see 4 directions to the left of 3 gray squares and your icon, select any one of these squares by double clicking. Paint the direction your mob should look when facing that direction. Once all four directions are filled in, increase the number of frames of the icons by finding the #Frames option and pressing the up arrow. For this tutorial you can select 2 or 3 frames, but for most games that I make, I tend to use 4 frames for each player mob. Fill in each of the frames with what each part of the animation should look like. You can check what the overall animation looks like by pressing the back button. Once every icon frame has been filled in, press the back button until you reach the Palette and Camera pictures, or reload the icon by closing it, saving, and double-clicking the icon once more. At this point right-click the icon and select 'Copy', then paste it to the right of your first icon. There should now be 2 icons. Right click one of them, select 'Edit State' - leave the name blank but check the box next to 'Movement state' and press 'OK'. This will allow the icon with the M next to it to be loaded into the mob whenever the mob moves (walks). For the other double click it and reduce its frames until there is only one left. Save the icon file and close it. Now 'Build' -> 'Compile'.

You should see your mob moving and changing direction when you press the arrow keys.

The complete code in this project should look like this:

Example:
world //The world datum
     name = "My First World" //The name of our world.
     hub = "Rockinawsome.My First World" //This is so it will show up in your hub when you register the game.
     mob = /mob/PC  //The path of our mob

mob
    PC
        icon = 'mob.dmi' //set the icon variable to the icon file

turf
    grass
        icon = 'grass.dmi'  

Hello World << ||

More questions? Consult the BYOND forums or your reference by pressing F1.

Email me at adam.empyreal@gmail.com if you have any comments or suggestions.