ID:292503
 
This tutorial will cover a simple way to display players' stats to them in a stat panel.
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
Make a save system guide
Thanks for the tutorials Falacy , your effort is much appreciated ,you got my spirit to learn DM back , can't wait for the other tutorials and hope you have sucess doing them ;3
Make the Tutorial 5 already lazy noob!
In response to Aakash14 (#3)
Find your own tutorial lazy newb!`
In response to Drehdog7 (#4)
I love these tutorials, there a big help.
In response to Drehdog7 (#4)
Shut up , you low class saiyans Dont deserve to talk to me. *walks away*
In response to Aakash14 (#6)
This isnt roleplay newb >.>
make a tutorial plz i need one
In response to Zelda123 (#8)
Zelda123 wrote:
make a tutorial plz i need one
when i hit i go lvl up the whole the time its not to stop
are you make a 5 Tutorial or not Falacy
Fal you can give me link that charachars
um... can you make one that shows how to make doors?
Being picky but, you should explain why it's important to call ..(), any then include it yourself :p
In response to El Wookie (#13)
Uh, you shouldn't need to be calling the parent proc anywhere there, and rarely at all in general.
In response to Falacy (#14)
I often overwrite my Bump() procs for specific atoms, but with conditions that pertain the Bump() proc to call the default, and it's always handy to call the default in case of a fatal error.
Good stuff. I already have a fair knowledge of DM and have read the guide + parts of reference, but I felt like skimming through it.
I would like to add on something. ;)
Falacy wrote:
Displaying Stats
By using the Stat() proc you can quickly and easily display information to players.
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.

So Stat() is called too frequently.And making a Game is not just making things work,but making them faster,better and the best!

its a lil improvement. ;)(but if you are a newbie then you shouldn't care much) but it makes a lot of difference.
mob/Stat()
if(statpanel("[src]'s Stats")) //checks if your current tab is the [src]'s Stats,if it is then update info else don't
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
if(statpanel("Another Tab"))//checks if your current tab is "Another Tab", if yes then update else don't
stat("???")

Why should we do that?
See, Stat() gets called frequently, and what if the Stat() is very laggy? Then the whole Game would have to suffer just because you want to show something to your Player!Thats too dumb! So what we should do is 'not to update anything you don't need to'.

What Falacy posted above, he did so because he did this tutorial for the newbies.
But this is what Falacy's Stat() would do--> [Update all Tabs] and what mine would do--[Update the current Tab only]!

While Falacy teaches you DM, I'll try to explain 'Basic Concepts and Logics of Programming'.Something too basic, but don't worry He'll give you a good picture of this in his examples.

Control Statements
What are they?- They are statements that control!
They control the flow of code.
<small>1. The 'if' Family
Members:if,else and else if
if you recollect the LevelCheck() in Tutorial 3, we find something like
if(src.Exp>=src.Nexp)
src.Level+=1
src.Exp=0
src.Nexp+=10 // blah blah

English Translation of the Code:
if src's Exp is greater than or equal to src's Nexp then Add 1 to src's Level, make src's Exp 0 and add 10 to src's Nexp.

Format:

if(condition)
statementyes
else
staementno

or

if(condition1) //if cond_1 true then exec statem1
statement1
else if(condition2) //if cond_2 true then exec statem2
statement2
else if(conditionn) //if condition_n true excecute statementn
statementn
else
statement // if none of the conditions are true then this

For 'if' 0,"" and null are false everything else is true.

2.The 'for loop'
Consider
for(var/i=1,i<=10,i++)
world<<"[i]"

Outputs

1
2
3
4
5
6
7
8
9
10

English Translation of Code:
Hey Compiler get ready for a Merry-Go-Round!
Start doing 'the thing' by introducing a variable named i with value 1, and keep on doing it till i is less than or equal to 10, and after each time your done doing 'the thing' increase i's value by 1!And 'the thing' is 'outputting the world - "[i]" //the value of i

Format:

for(pre-action,condition,post-action)
body

What it does?
1.Do Pre-Action
2.Check Condition if true continue to step 3 else stop everything
3.Execute Body
4.Do Post-Action
5.Check condition if true continue to step 3 else stop everything

There is another for loop in DM, its called the 'for loop list' since lists aren't taught I ll wait till Fal makes it clear to you.

3.The 'while loop'
Consider this
var/i=1
while(i<=10)
world<<"[i]"
i++

Outputs

1
2
3
4
5
6
7
8
9
10

English Translation of Code:
Hey Compiler get ready for another Merry-Go-Arround
Keep doing 'the thing' as long as the value of i is less than or equal to 10.
Here 'the thing' is outputting to the world the value of i and increasing the value of i by 1.


Guess thats Enough for this post.Remaining I ll try to get it clear to you guys.

Mommy who is the src?
This is a bit of DM, but Ill explain it.
consider this:
proc/Proc_1() // tell the compiler there is a proc called Proc_1
world<<"Proc_1 says-My src is [src]" // Proc_1 tells the world who his src is
/* text embedding:
var/Age=14 //just define a var
1."My Age is Age" outputs >> My Age is Age
2."My Age is [Age]" outputs >> My Age is 10
3."My Age is \[Age\]"outputs >> My Age is [Age]
Compiler out puts a string as it is.So in 1 we expect the same string.
Compiler exempts [variable] and replaces the value of the variable instead of outing [variable]
If you want to output a string containing '[' and ']' then
we have escape sequence characters.
\n newline
\t leave a tab space
\" output "
\' output '
Several others in the references (Press F1 while on DM and type macros)
\[ and \] are escape characters which is a workaround for outputting [ and ], bcz the compiler can't make out when and what we want*/

mob/proc/Proc_2()
world<<"Proc_2 says-My src is [src]" // Proc_2 tells the world who his src is

English Translation of Code:
Hey Compiler there is a procedure named Proc_1 which outputs to the world "Proc_1 says-My src is [src]".
And Compiler there is a procedure named Proc_2 of every mob in the game and the procedure ourputs to the world "Proc_2 says-My src is [src]".
Question whats the Output?
1.Proc_1 would out put "Proc_1 says-My src is "
because [src] is replaced with the value of src.
Here the src value is null not "null" but "".
[Some Axiom= null~""~0].
The Axiom means null is almost same as "" and 0.But they are not equal.If null is used in text it becomes "" and when used in Boolean(don't worry) Values it is 0/False.
Best way to get over this is experience!
2.Proc_2 would output "Proc_2 says-My src is [src.name]"
If the name of the mob were Falacy then it would output
"Proc_2 says-My src is Falacy". So what do we understand?
Every mob has its own Proc_2 which outputs the same line except the mob's name.

Didn't understand? Don't worry Falacy will make you, probably he did in his LevelCheck() procedure.I just went too in depth about this.

Whats the Best Help?
Press F1 while in DM and search for things!

Anyway Keep up the Good work Fal*








In response to Soul Sign (#17)
Soul Sign wrote:
if(statpanel("[src]'s Stats")) //checks if your current tab is the [src]'s Stats,if it is then update info else don't

I didn't even know you could do that o.O
In response to Falacy (#18)
Neither did I till a month ago o.O |;)|
Now you can reduce the lag on HU2 keeping stable the alpha system.

Falacy, I was thinking about your Alpha Rendering System.
And I could think of something similar producing the same effect.

Consider a man, who has no shoes walking on a rugged terrain full of stones and thorns.Would it be easier to put a carpet on the whole terrain or would it be easier to give him a pair of shoes?

If I am right it is easier to give him a pair of shoes, rather than wasting time & money to cover the whole terrain!

In the same manner instead of adding Alpha Content to the turfs which are millions in number try adding an overlay of the mob's icon which has alpha content and change the overlay's layer to more than the layer of high things.

So the overlay will be same as the mob's icon and when the mob comes under a roof its overlay will be visible since it's layer is higher than the layer of the building.

I made a similar effect, using this method, it works, its good, less lag, but you need to update the guy's alpha_overlay every time you change the mob's icon in anyway(eg.changing the icon value/adding an overlay.. etc..)

I suggested this bcz sometimes I see the map getting loaded like tile by tile.But its so crappy that we need to change something we worked on for a long time.But whatever this is just a suggestion.

One more point that I observed a couple months ago is that only objects that have a whole image(in the.png format) have the alpha content layer not the others, so you can overcome that problem also
I ll show you a screen shot of how it is.(looks the same anyway =P)


Alpha Rendering Example
Page: 1 2