If you haven't already read Tutorial #3 we recommend that you check it out first. Or, start at the beginning, if you're new to the series!
Displaying Stats
By using the Stat() proc you can quickly and easily display information to players.
Step 1.1 First lets add some new stats to display, add these in the "Vars.dm" file.
mob/var
Level=1
Exp=0
Nexp=100
//New code below
HP=100
MaxHP=100
Str=10
Def=5
These should be pretty self explanatory.
It creates your health, strength and defense, and gives them their initial values.
Step 1.2 Now lets make a new Code File named "StatPanel.dm" and add the following code to it:
mob/Stat()
statpanel("[src]'s Stats")
stat("Level:","[src.Level]")
stat("EXP:","[src.Exp]/[src.Nexp]")
stat("Health:","[src.HP]/[src.MaxHP]")
stat("Strength:","[src.Str]")
stat("Defense:","[src.Def]")
Stat() is a built-in proc that can be used to display information in an info control tab.
Stat() is automatically called every 8 ticks, or 8/10ths of a second, so that is when this information will update.
statpanel() and stat() are also built-in, and are used to manage what data you want to display and where.
Step 1.3 You can display multiple tabs if you want by setting another statpanel().
mob/Stat()
statpanel("[src]'s Stats")
stat("Level:","[src.Level]")
stat("EXP:","[src.Exp]/[src.Nexp]")
stat("Health:","[src.HP]/[src.MaxHP]")
stat("Strength:","[src.Str]")
stat("Defense:","[src.Def]")
//New code below
statpanel("Another Tab")
stat("???")
Not much to explain here, it works exactly the same as above.
Implementing New Additions
We added some variables for health, strength, and defense; now lets make them increase when you level up.
Step 2.1 The following code should exist in "Procs.dm"
mob/proc
LevelCheck()
if(src.Exp>=src.Nexp)
src.Exp=0
src.Nexp+=10
src.Level+=1
//new code below
src.MaxHP+=rand(1,5)
src.Str+=1
src.Def+=1
//end new code
src<<"You are now Level [src.Level]"
There are three new lines added, one for each stat.
MaxHP is increased by a random integer between 1 and 5 (1, 2, 3, 4, or 5).
Str and Def are increased by 1 each.
If you wanted to, you could restore the player's health when they level up; using something like:
"src.HP=src.MaxHP"; after you've added to their MaxHP.
Continue to Tutorial #5: Saving/Loading