Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
picHPbar
#1
OK. This tutorial is to teach you all how to make an HP bar in frmMirage. When the player looses hp, the picture will resize, and another picture underneath will be a different (I used a grayed-out) color. Also, I have added a label that tells you how much HP you have (12 / 62).

Difficulty (1/5) C & P


This is all Client side

First place two picture bars of the same size, but differing colors in frmMirage and label them picFull and picOut. Choose whatever HP bar pictures you want now (make sure they are the same size).
Inside each of those picture boxes add a label (lblFull and lblOut respectively). Set the captions of both to " 0 / 0"

Now

In modHandleData find:
Code:
' ::::::::::::::::::::::
    ' :: Player hp packet ::
    ' ::::::::::::::::::::::

replace that packet with:
Code:
' ::::::::::::::::::::::
    ' :: Player hp packet ::
    ' ::::::::::::::::::::::
    If LCase(Parse(0)) = "playerhp" Then
        Dim hpbWidth As Integer
        hpbWidth = 154
        Player(MyIndex).MaxHP = Val(Parse(1))
        Call SetPlayerHP(MyIndex, Val(Parse(2)))
        If GetPlayerMaxHP(MyIndex) > 0 Then
           'frmMirage.lblHP.Caption = Int(GetPlayerHP(MyIndex) / GetPlayerMaxHP(MyIndex) * 100) & "%"
            frmMirage.picFull.Width = Int(GetPlayerHP(MyIndex) / GetPlayerMaxHP(MyIndex) * hpbWidth)
            frmMirage.lblFull.Caption = GetPlayerHP(MyIndex) & " / " & GetPlayerMaxHP(MyIndex)
            frmMirage.lblOut.Caption = GetPlayerHP(MyIndex) & " / " & GetPlayerMaxHP(MyIndex)
        End If
        Exit Sub
(I made it so that the default HP label doesn't show anymore)
make sure that you change hpbwidth to the width of you HP bar (in pixels, not twips)

Analysis:
To resize the full HP bar we must get the current percentage of the players HP. such as .1, .92, or 1; then we multiply it by the width of the maxed out bar in order to make sure that the bar is resized properly.
Next, we update both labels because once your full HP bar goes past a certain point, you wont see it anymore, so we added the bottom one in order to keep it visible (make sure that they are in the same place on both HP bars).

Your Challenge:
Add an MP, SP, and/or EXP bar(s).
Reply
#2
Meh, I had trouble adding HP bars when I first used them a long time ago, I'm glad someone finally did a tut on it, although I've already sorted out my own style for them.

It's good seeing new tuts too, heh.
Reply
#3
I don't know if you mentioned twip, the noob killer Tongue
Reply
#4
Here is my version of the HP/MP/SP bars in action.
(Although in my source I load the images onto the picture box when the game starts)
(Shouldn't make a difference as the code above is the same as my code that updates the pictures)

This is just to show people what the code does:

[spoiler]Stage 1: I set all my stats to the bare minimum (w/o dieing)
[Image: savend8.png]

Stage 2:Slight regeneration in stats
[Image: save2sq5.png]

Stage 3: Slightly more restoration
[Image: save3tz4.png]

(Don't steal those, as they are property of me)[/spoiler]
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)