Mirage Engine
HP Bars Under NPCs - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: HP Bars Under NPCs (/showthread.php?tid=81)



HP Bars Under NPCs - Tutorial Bot - 02-06-2006

Author: GodSentDeath
Difficulty: 1/5

:: SERVER SIDE ::
In modHandleData add the following anywhere:
Code:
' :::::::::::::::::::::::::::
    ' :: Npc hp request packet ::
    ' :::::::::::::::::::::::::::
    Dim Pack As String
    If LCase(Parse(0)) = "getnpchp" Then

    Pack = "npchp" & SEP_CHAR
        For i = 1 To MAX_MAP_NPCS
            n = MapNpc(GetPlayerMap(index), i).Num
            Pack = Pack & MapNpc(GetPlayerMap(index), i).HP & SEP_CHAR & GetNpcMaxHP(n) & SEP_CHAR
        Next i
    Pack = Pack & END_CHAR

        Call SendDataTo(index, Pack)
        Exit Sub
    End If

:: CLIENT SIDE ::
In modHandleData add the following anywhere:
Code:
' :::::::::::::::::::
    ' :: Npc hp packet ::
    ' :::::::::::::::::::
    If LCase(Parse(0)) = "npchp" Then
        n = 1

        For i = 1 To MAX_MAP_NPCS
            MapNpc(i).HP = Val(Parse(n))
            MapNpc(i).MaxHP = Val(Parse(n + 1))

            n = n + 2
        Next i

        Exit Sub
    End If


In modTypes find "Type MapNpcRec under HP As Long" add:
Code:
MaxHP As Long
Now in modGameLogic, under:
Code:
' Blit out the npcs
For i = 1 To MAX_MAP_NPCS
Call BltNpc(i)
Next i
Add:
Code:
' Blit out NPC hp bars
        Dim GSD2 As Long
        If GetTickCount > GSD2 + 500 Then
            Call SendData("getnpchp" & SEP_CHAR & END_CHAR)
            GSD2 = GetTickCount
        End If
      
        For i = 1 To MAX_MAP_NPCS
            If MapNpc(i).Num > 0 Then
                Call BltNpcBars(i)
            End If
        Next i
Finally, at the very bottom of modGameLogic add:
Code:
Sub BltNpcBars(ByVal Index As Long)
Dim x As Long, y As Long
x = MapNpc(Index).x * PIC_X + MapNpc(Index).XOffset
y = MapNpc(Index).y * PIC_Y + MapNpc(Index).YOffset - 4
If MapNpc(Index).HP = 0 Then Exit Sub
Call DD_BackBuffer.SetFillColor(RGB(255, 0, 0))
Call DD_BackBuffer.DrawBox(x, y + 32, x + 32, y + 36)
Call DD_BackBuffer.SetFillColor(RGB(0, 255, 0))
Call DD_BackBuffer.DrawBox(x, y + 32, x + ((MapNpc(Index).HP / 100) / (MapNpc(Index).MaxHP / 100) * 32), y + 36)
End Sub
That's all!