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

Blitting Other Players' Health Bars


balliztik1
 Share

Recommended Posts

In Eclipse Stable (and maybe older versions), the code is already there to blit out other players' health bars. However, the player's health is never sent to others' clients. This is easily fixed by a slight modification to the SendHP function. Find both instances of SendHP and change them to this:

```
Sub SendHP(ByVal Index As Long)
    Call SendDataToMap(GetPlayerMap(index), "PLAYERHP" & SEP_CHAR & Index & SEP_CHAR & GetPlayerMaxHP(Index) & SEP_CHAR & GetPlayerHP(Index) & END_CHAR)
End Sub
```
This makes sure all players on your map get the HP update.

Now, you'll need to make sure when a player enters the game, their HP is sent out, and all players' HP is sent to them. The easiest way to do this is to place it in the need map packet, because that packet already sends the data for every characters' equipment on said map. In Sub Packet_NeedMap, alter the For loop like so:

```
    For I = 1 To MAX_PLAYERS
        If IsPlaying(I) Then
            Call SendHP(I)
            Call SendIndexWornEquipment(I)
            Call SendWornEquipment(I)
        End If
    Next I
```
Now, everyone on the map gets your updated HP.

Finally, you just need to alter the client's packet handling for the SendHP sub. Find the "playerhp" packet handle in the HandleData sub of the Client and change it to this:

```
    If LCase$(Casestring) = "playerhp" Then
        Player(Parse(1)).MaxHp = Val(Parse(2))
        Call SetPlayerHP(Parse(1), Val(Parse(3)))
        If Parse(1) = MyIndex And GetPlayerMaxHP(MyIndex) > 0 Then
            ' frmMirage.shpHP.FillColor = RGB(208, 11, 0)
            frmMirage.shpHP.Width = ((GetPlayerHP(MyIndex)) / (GetPlayerMaxHP(MyIndex))) * 150
            frmMirage.lblHP.Caption = GetPlayerHP(MyIndex) & " / " & GetPlayerMaxHP(MyIndex)
        End If
        Exit Sub
    End If
```
And that will do it.
Link to comment
Share on other sites

Client Error
"index out of range exception"

in code:

```
    If LCase$(Casestring) = "playerhp" Then
        Player(Parse(1)).MaxHp = Val(Parse(2))
        Call SetPlayerHP(Parse(1), Val(Parse(3)))
        If Parse(1) = MyIndex And GetPlayerMaxHP(MyIndex) > 0 Then
            ' frmMirage.shpHP.FillColor = RGB(208, 11, 0)
          frmMirage.shpHP.Width = ((GetPlayerHP(MyIndex)) / (GetPlayerMaxHP(MyIndex))) * 150
          frmMirage.lblHP.Caption = GetPlayerHP(MyIndex) & " / " & GetPlayerMaxHP(MyIndex)
        End If
        Exit Sub
    End If
```
Thats the Error-line
Call SetPlayerHP(Parse(1), Val(Parse(3)))
Link to comment
Share on other sites

@Kirby4tw:

> Client Error
> "index out of range exception"
>
> in code:
>
> ```
>     If LCase$(Casestring) = "playerhp" Then
>         Player(Parse(1)).MaxHp = Val(Parse(2))
>         Call SetPlayerHP(Parse(1), Val(Parse(3)))
>         If Parse(1) = MyIndex And GetPlayerMaxHP(MyIndex) > 0 Then
>             ' frmMirage.shpHP.FillColor = RGB(208, 11, 0)
>           frmMirage.shpHP.Width = ((GetPlayerHP(MyIndex)) / (GetPlayerMaxHP(MyIndex))) * 150
>           frmMirage.lblHP.Caption = GetPlayerHP(MyIndex) & " / " & GetPlayerMaxHP(MyIndex)
>         End If
>         Exit Sub
>     End If
> ```
> Thats the Error-line
> Call SetPlayerHP(Parse(1), Val(Parse(3)))

Did you change the SendHP sub in both places? It sounds like you've still got the old version of SendHP with the new version of the packet handle.
Link to comment
Share on other sites

  • 1 month later...
@Kirby4tw:

> With this code the Sadcript commands like "SetPlayerHP(index,GetPlayerMaxHP(index))"
> will not work longer if you have worn equip. Please fix this Balliztik1 ^^
>
> For Questions: [email protected] (MSN)

Well, I made no changes to the SetPlayerHP sub, so I don't see how that could be an issue with this code. I know there's a post around here about GetPlayerMaxHP not returning the right value. Check that out.

At a glance (because I'm leaving in a moment), try reversing the SendHP and the equipment sends. Maybe sending the HP after the equipment is a better idea. Still, I don't think the issue lies here.
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...