Now draw a smiley, stick figure, person, whatever you want. Make it a male. Once your done, click the "Back" button, located at the bottom right of the screen, click again, and draw a female. Now, right-click on the male, and click Edit State. Click on the box, and type in male, all lowercase. Do the same with the female, execpt type female. Now click the paint again, and flood the icon with green, for grass. Name that icon, grass. Also make water. Don't forget to name it! Now the fun part, CODING!
Step 2: Coding the Basics.
Double click on 'tutorial.dm' in the file tree. Now we are ready to code! First, you need to define the mob. To do so, type:
mob
Easy, right? Now, you need to define what icon you have. To do that, type this:
mob
icon = 'person.dmi'
Ok, so far, so good. Now you need some HP, strength, and defense. HP and others are stored in a variable. So you need to define a var in your mob. So type this:
mob
icon = 'person.dmi'
var
hp = 10
str = 5
def = 2
Now we have hp (10), strength (5), and defense (2). Now, we need something to walk on. Now that grass comes in handy. Lets go ahead and define a grass turf:
turf
grass
icon = 'person.dmi'
icon_state = "grass"
Notice on this one, I used icon_state. An icon state is an icon in a dmi file. Now, lets define the water one.
turf
water
icon = 'person.dmi'
icon_state = "water"
density = 1
There's something new on here, too. Density. It can be set to 0 or 1. 0 means players and mobs can walk over it. 1 means they cannot. Ok. Now you are almost ready to walk around in your first game! Keep in mind you can't do anything.. YET. Now lets set some world variables.
world
name = "My First Game."
turf = /turf/grass
Name, sets the name of the world (what you see on the hub, and pager). Now, we need a map. Go to File, New.., and for the type, select Map File (.dmp). Name it world. Click ok. Now, look at the file tree, and click the + on turf. You should see water, and grass. Click on water, and place some on the grass by clicking. Once you have it down, click on the tab that says 'File' in the top left corner of the screen.You can also add view = 5 to make the camera focus on you, instead of the map. Now we need it where you can choose male or female. You need to make a Login() proc. To do that, you just do this:
mob
Login()
Simple? We aren't done yet. Now to make the choices.:
mob
Login()
usr.icon_state = input("What gender?") in list ("male","female")
usr.Move(locate(1,1,1))
Make sure male and female are all lowercase. usr, is the user as you might have guessed. src is the source of the code. So if you used src in login, src would be whoever logged in. As for the Move, it moves you to a certain x,y,z coordinates. Change the 1,1,1 to the starting point you want. Now you are ready to walk around in your world! Just go to Build, Compile (or CTRL K), and then go to Build, Run (or CTRL R).
Step 3: Basic Communication (world,usr,view,oview).
Now you are going to learn how to use <<,usr,world,oview, and view, along with some other things. << is input, while >> is output. So if you wanted to make the user see text, you would need input. So you would have to do
usr << "This message is to you, [usr]"
Notice i have [usr] in there. Things in brackets like that, are displayed as vars. So if you wanted to show the users strength to them, you would do
usr << "Your strength is [usr.str]."
View is something else you can send something to. Its everyone in the screen of usr, or whatever you use. (src, usr, etc). So to send something to someone in view you would do:
view() << "To everyone in the view of [usr]"
You can also assign how far the message goes. If you only want people right next to you to hear it, you can do this:
view(1) << "To everyone next to [usr]"
There is also oview. Its basicly the same thing as view, but its to everyone BUT usr, or whatever you use.
oview() << "To everyone in the screen, but [usr]"
You can also assign how far with oview too. Now if you want to send a message to EVERYONE, you would use world. World is as you know, the world :).
world << "Hi, everyone! I am [usr]!"
Step 4: Verbs and Procs
Verbs are commands. Things to carry out messages, attacks, or anything! Procs do events for you instead of having to repeat code and etc. Lets learn about verbs first. To make a verb you would have to do:
mob
verb
My_Verb()
//what ever you want the verb to do
an underscore ( _ ) acts like a space in verbs, and procs. In game, My_Verb() will turn out My Verb. // acts as commenting. Commenting something makes the game skip that line of code. Now, from what I've taught you, I want you to make a few verbs. One sending a message saying "hi" to the usr, one to view, oview, and world, and also a verb to increase the users strength by 1. If you can't, just scroll down.
Well, if you cant get it, that's ok. Ill provide some examples, And if you did, way to go! (especially because i havn't taught you how to add to things yet!) Here are some examples:
mob
verb
Hi_to_user()
usr << "Hi!"
Hi_to_view()
view() << "Hi!"
Hi_to_oview()
oview() << "Hi!"
Hi_to_world()
world << "Hi!"
Add_1_to_Strength()
usr.str += 1
Adding things is simple! all you have to do is use+=,-=, and *= for mathmatic things. Now that you know how, i want you to make a verb, that messages the number 5 to the user, by starting out with the number 30. Heres an example how to do that stuff:
mob
verb
Say_60()
usr << (100 - 50 - 20) * 2
That would show the number 60 to you.. Now do it with 30 to 5. Now lets learn procs. Heres an example of a proc:
mob
proc
Myproc()
if(src.str > 4)
src << "Your strength is greater than 4"
else
src << "Your strength is less than 4
Now when you call the Myproc() proc, it will do all that code for you, so you dont have to keep typing it over and over. To call it just do something like this:
mob
verb
Myproc_call_verb()
usr << "Checking strength.."
sleep(10) // wait for 1 second.
usr:Myproc()
Pretty easy. Now lets make an "attack" verb.
First lets make the base for it.
mob
verb
Attack(mob/M as mob in oview(1))
Ok. Thats the base. You see something new in this. mob/M as mob. mob/M as mob in oview(1) defines M as any mob beside you. You should know that by now. Now, we need to define some damage.
mob
verb
Attack(mob/M as mob in oview(1))
var/damage = usr.str - M.def
Thats pretty easy to understand. The damage you do, is your strength, minus thier defense. Now lets do some more things
mob
verb
Attack(mob/M as mob in oview(1))
var/damage = usr.str - M.def
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.hp -= damage
view() << "[usr] attacks [M] for [damage] HP!"
M:deathcheck()
That right there, makes it to where if the damage is 0 or less than 0, then tell you, and whoever you attacked, that they dodged. If not, than take away the damage, show who ever is in view, and run a deathcheck proc (which we are making now.) Now we need to make the deathcheck() proc.
mob
proc
deathcheck()
if(src.hp <= 0)
view() << "[src] dies!"
src.hp = 10
src.Move(locate(1,1,1))
usr.str += 1
usr.def += 1
That proc checks to see if the usr's hp is 0 or below. If it is, move them to 1,1,1, reset thier hp, and give the killer more stats. Now your game is playable. You might want to add some mobs to the map to fight though.Now lets make some weapons! First we need some vars to tell if we are wearing something.
mob
var
armor_equipped = 0
weapon_equipped = 0
Now that we have that, lets make the weapon and armor. First make the icon for it in the person dmi, and name it weapon and the other one armor. Now lets make the objects.
obj
sword
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up \a [src]"
Drop()
new/obj/sword(usr.loc)
view() << "[usr] drops \a [src]"
del(src)
armor
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up [src]"
Drop()
new/obj/armor(usr.loc)
view() << "[usr] drops [src]"
del(src)
Ok, you see a few new things here. set src in oview(1). That makes it where you get that verb, when you are in range of oview(1). usr.contents is like a ubilt in inventory. \a is a macro. If src is apple, then it will say drops an apple. its its rock, it will say drops a rock. Now for the equip and unequip verbs.
obj
sword
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up \a [src]"
Drop()
new/obj/sword(usr.loc)
view() << "[usr] drops \a [src]"
del(src)
Equip()
if(usr.weapon_equipped == 0)
usr.str += 2
usr.weapon_equippped = 1
view() << "[usr] equips a sword."
else
usr << "You are already wielding something."
Unequip()
if(usr.weapon_equipped == 1)
usr.str -= 2
view() << "[usr] unequips a sword."
else
usr << "You aren't wielding this."
armor
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up [src]"
Drop()
new/obj/armor(usr.loc)
view() << "[usr] drops [src]"
del(src)
Equip()
if(usr.armor_equipped == 0)
usr.def += 2
usr.armor_equippped = 1
view() << "[usr] wears some armor."
else
usr << "You are already wearing something."
Unequip()
if(usr.armor_equipped == 1)
usr.def -= 2
view() << "[usr] takes off some armor."
else
usr << "You aren't wearing this."
Not too hard, eh? Nothing new here, really. Now for SPECIAL weapons! Lets say you want a weapon to give you the 'super slash' attack, that does more damage than usual. You would have to make a super slash verb, but not under mob. Lets put it under mob/attacks, like so:
mob
attacks
verbs
Super_Slash(mob/M as mob in oview(2)) // can attack someone TWO spaces away
var/damage = usr.str - M.def + 5
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.hp -= damage
view() << "[usr] super slashes [M] for [damage] HP!"
M:deathcheck()
Then, under the equip verb for the 'super sword' just put
usr.verbs += /mob/attacks/verbs/Super_Slash
Well thats about it. That should get you on your way to your great game! Hope you enjoyed the tutorial!
----
Tell me what you think :)
and Please comment or something wrong here :)</<>
ID:159122
![]() May 7 2009, 6:09 pm
|
|
Just for future reference, kindly stop linking that tutorial and recommend ZBT's tutorials.
It's just that it has many, many errors and 'abusive' code :< |
Mysame wrote:
Just for future reference, kindly stop linking that tutorial and recommend ZBT's tutorials. I wasnt linking to it for learning.. just to show that Narutofoxy was taking credit for something that wasnt even made by him/her. And yes, ZBT's tut is good. |
Jan90ster9 wrote:
um... people don't like it when you take credit for something that you haven't even made... I know your right about the Credit on it, but people don't know how to find that adress Just you know, i just take credit to make more interesting. And, i post it here. |
http://www.angelfire.com/games4/byond/
exact same tut