Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

HPBar problem.


zenmen
 Share

Recommended Posts

```
Private Sub HandlePlayerHp(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
Dim Buffer As clsBuffer

    ' If debug mode, handle error then exit out
    If Options.Debug = 1 Then On Error GoTo errorhandler

    Set Buffer = New clsBuffer
    Buffer.WriteBytes Data()
    Player(MyIndex).MaxVital(Vitals.HP) = Buffer.ReadLong
    Call SetPlayerVital(MyIndex, Vitals.HP, Buffer.ReadLong)

    If GetPlayerMaxVital(MyIndex, Vitals.HP) > 0 Then
        'frmMain.lblHP.Caption = Int(GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * 100) & "%"
        frmMain.lblHP.Caption = GetPlayerVital(MyIndex, Vitals.HP) & "/" & GetPlayerMaxVital(MyIndex, Vitals.HP)
        ' hp bar
        frmMain.ImgHPBar.height = ((GetPlayerVital(MyIndex, Vitals.HP) / HPBar_Height) / (GetPlayerMaxVital(MyIndex, Vitals.HP) / HPBar_Height)) * HPBar_Height
    End If

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "HandlePlayerHP", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
End Sub
```
Link to comment
Share on other sites

This is a bit of a guess, but try
```
    If GetPlayerMaxVital(MyIndex, Vitals.HP) > 0 Then
        'frmMain.lblHP.Caption = Int(GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * 100) & "%"
        frmMain.lblHP.Caption = GetPlayerVital(MyIndex, Vitals.HP) & "/" & GetPlayerMaxVital(MyIndex, Vitals.HP)
        ' hp bar
        frmMain.ImgHPBar.top = ((GetPlayerVital(MyIndex, Vitals.HP) /  frmMain.ImgHPBar.top) / (GetPlayerMaxVital(MyIndex, Vitals.HP) /  frmMain.ImgHPBar.top)) *  frmMain.ImgHPBar.top
    End If

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "HandlePlayerHP", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
```It's definatly the .Top attribute you need to adjust instead of the .Height variable that's used now. Im just not sure if the math works out like this.
Link to comment
Share on other sites

```
    If GetPlayerMaxVital(MyIndex, Vitals.HP) > 0 Then
        'frmMain.lblHP.Caption = Int(GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * 100) & "%"
        frmMain.lblHP.Caption = GetPlayerVital(MyIndex, Vitals.HP) & "/" & GetPlayerMaxVital(MyIndex, Vitals.HP)
        ' hp bar
        frmMain.ImgHPBar.top = ((GetPlayerVital(MyIndex, Vitals.HP) /  frmMain.ImgHPBar.top) / (GetPlayerMaxVital(MyIndex, Vitals.HP) /  frmMain.ImgHPBar.top)) *  frmMain.ImgHPBar.top + *insert ur thing*
    End If

    ' Error handler
    Exit Sub
errorhandler:
    HandleError "HandlePlayerHP", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext
    Err.Clear
    Exit Sub
```Can you try again with this code, and fill in *insert ur thing* with the .Top of your frmMain.ImgHPBar.
Link to comment
Share on other sites

I dont understand:

> and fill in *insert ur thing* with the .Top of your frmMain.ImgHPBar.

How it must look? You mean "frmMain.ImgHPBar.top + HPBar_Height" ?

But if i do that with this code its nothing change, still the same what is on the screen.
Link to comment
Share on other sites

Now i dont see my bitmap of ImgHPBar.

> If GetPlayerMaxVital(MyIndex, Vitals.HP) > 0 Then
>         'frmMain.lblHP.Caption = Int(GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * 100) & "%"
>         frmMain.lblHP.Caption = GetPlayerVital(MyIndex, Vitals.HP) & "/" & GetPlayerMaxVital(MyIndex, Vitals.HP)
>         ' hp bar
>         frmMain.ImgHPBar.top = ((GetPlayerVital(MyIndex, Vitals.HP) / frmMain.ImgHPBar.top) / (GetPlayerMaxVital(MyIndex, Vitals.HP) / frmMain.ImgHPBar.top)) * frmMain.ImgHPBar.top + 589
>     End If
>
>     ' Error handler
>     Exit Sub
> errorhandler:
>     HandleError "HandlePlayerHP", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext
>     Err.Clear
>     Exit Sub
>     End Sub
Link to comment
Share on other sites

I think both Top + height need to be adjusted properly to set it up properly and to be honest I am way too stoned to do smart mathz. The top needs to move down so the image moves down, while the height needs to shrink with an equal amount to make sure the image doesnt just go down but stays on the same spot.
Link to comment
Share on other sites

That is, You will try to help me (read - do it for me ^ ^)? Unfortunately I do not know much about programming, so or I find a ready-made solution, or the GUI to be thrown away : P

Anyway, now I thank you for the above help! :)
Link to comment
Share on other sites

In ModGlobal add

```
Public HPTop As Long
Public HPHeight As Long
Public HPOffset As Long
```
In```
Private Sub Form_Load()
```on frmMain add
```
HpTop = ImgHPBar.Top
HpHeight = ImpHpBar.Height
HpOffSet = HpHeight - HpTop
```
Replace
```
        frmMain.ImgHPBar.top = ((GetPlayerVital(MyIndex, Vitals.HP) / frmMain.ImgHPBar.top) / (GetPlayerMaxVital(MyIndex, Vitals.HP) / frmMain.ImgHPBar.top)) * frmMain.ImgHPBar.top + 589
```with
```

Percentage = (GetPlayerVital(MyIndex, Vitals.HP / GetPlayerMaxVital(MyIndex, Vitals.HP)
ImgHpBar.Top = HpTop + (HpOffSet * Percentage)
ImgHpBar.Height = HpHeight - (HPOffset * Percentage)

```
Add Dim Percentage As Long at the top of that sub.
Link to comment
Share on other sites

This was my proof of concept to make sure my math was ok. Make a new project, add a Picture1 and a Hscroll1 and you can test the math. So if there are any mistakes in the above code, it is probably something small and stupid.

```
Public A As Long
Public B As Long
Public C As Long
Public Percentage As Long

Private Sub Change()

    Picture1.Top = A - (C * Percentage / 100)
    Picture1.Height = B + (C * Percentage / 100)

End Sub

Private Sub Form_Load()
    A = Picture1.Top
    B = Picture1.Height
    C = (A - B)
End Sub

Private Sub HScroll1_Change()
Percentage = HScroll1.Value
Call Change

End Sub

```
Link to comment
Share on other sites

Thank you! But.. (yeah thats only me..) i have got some error (ofcoure i add all Publics etc in modGlobals and frmMain):

Link: ![](http://s6.ifotos.pl/img/errorPNG_renxwnq.PNG)

And there is some bugs:

> HpTop = ImgHPBar.Top
> HpHeight = Im**p**HpBar.Height
> HpOffSet = HpHeight - HpTop

and parentheses but I do not know how they should be:

> Percentage = (GetPlayerVital(MyIndex, Vitals.HP / GetPlayerMaxVital(MyIndex, Vitals.HP)**))**
> ImgHpBar.Top = HpTop + (HpOffSet * Percentage)
> ImgHpBar.Height = HpHeight - (HPOffset * Percentage)

or:

> Percentage = (GetPlayerVital(MyIndex, Vitals.HP**)** / GetPlayerMaxVital(MyIndex, Vitals.HP)**)**
> ImgHpBar.Top = HpTop + (HpOffSet * Percentage)
> ImgHpBar.Height = HpHeight - (HPOffset * Percentage)

I really thank you for your help!  :embarrassed:
Link to comment
Share on other sites

```
Percentage = (GetPlayerVital(MyIndex, Vitals.HP / GetPlayerMaxVital(MyIndex, Vitals.HP)
frmMain.ImgHpBar.Top = HpTop + (HpOffSet * Percentage)
frmMain.ImgHpBar.Height = HpHeight - (HPOffset * Percentage)
```
That should fix that problem.

```
HpHeight = ImpHpBar.Height
```That was just a typo, but I assume you fixed that already

```
Percentage = GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP)
ImgHpBar.Top = HpTop + (HpOffSet * Percentage)
ImgHpBar.Height = HpHeight - (HPOffset * Percentage)
```That one is correct.
Link to comment
Share on other sites

Joost, what about this code?

```
    With Health_Bar

            If Player.Stats.Total_Health <> 0 Then HP = (Player.Stats.Current_Health / Player.Stats.Total_Health) * .Frame_Size.Bottom

Vertex_List(0) = Create_TLVertex(.X + .Frame_Size.Left, .Y + .Frame_Size.Top, 0, 1,  D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)

Vertex_List(1) = Create_TLVertex(.X + .Frame_Size.Left, .Y + HR, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)

    End With
```
Its something change?
Link to comment
Share on other sites

Try this:

* * *

Find:
```
Public HPBar_Width As Long

```
and under add:
```
Public HPBar_Height As Long

```
Next find:
```
' store the bar widths for calculations

```
and under add:
```
    HPBar_Height = frmMain.imgHPBar.height

```
Then use this code for the calculations in HandlePlayerHP:
```
frmMain.imgHPBar.height = GetPlayerVital(MyIndex, Vitals.HP) / GetPlayerMaxVital(MyIndex, Vitals.HP) * HPBar_Height

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...