[EA] MiniMap

The following is iHero’s MiniMap system for EO converted to work with EA.

(If you already used the old tutorial I made for this, remove it all and start with the new one)

In modGraphics find```
For I = 1 To Action_HighIndex

Call DrawActionMsg(I)

Next I
in Render Graphics and under it add
’ Render the minimap

DrawMiniMap


At the bottom of modTypes add```
' Mini Map Data

Public MiniMapPlayer(1 To MAX_PLAYERS) As MiniMapPlayerRec

Public MiniMapNPC(1 To MAX_MAP_NPCS) As MiniMapNPCRec

Public Type MiniMapPlayerRec

x As Long

y As Long

End Type

Public Type MiniMapNPCRec

x As Long

y As Long

End Type

FindSub SetPlayerX(ByVal Index As Long, ByVal x As Long)and underPlayer(Index).x = xadd```
MiniMapPlayer(Index).x = x * 4


Find```
Sub SetPlayerY(ByVal Index As Long, ByVal x As Long)
```and under```
Player(Index).y = y
```add```
MiniMapPlayer(Index).y = y * 4

FindPrivate Sub HandleNpcMove(ByVal Index As Long, ByRef data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)and under```
With MapNpc(MapNpcNum)

.x = x

.y = y
add
MiniMapNPC(MapNpcNum).x = x * 4

MiniMapNPC(MapNpcNum).y = y * 4


Find```
Private Sub HandleMapNpcData(ByVal Index As Long, ByRef data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
```and under```
.y = buffer.ReadLong
```add```
MiniMapNPC(I).x = MapNpc(I).x * 4

MiniMapNPC(I).y = MapNpc(I).y * 4

Now at the bottom of modGraphics add


Public Sub DrawMiniMap()

Dim i As Long, Z As Long

Dim X As Integer, Y As Integer

Dim direction As Byte

Dim CameraX As Long, CameraY As Long, playerNum As Long

Dim MapX As Long, MapY As Long

Dim CameraXSize As Long, CameraYSize As Long

CameraXSize = MAX_MAPX * 32 + 1

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo ErrorHandler

MapX = Map.MaxX

MapY = Map.MaxY

' Draw Outline

For X = 0 To MapX

For Y = 0 To MapY

CameraX = CameraXSize - (MapX * 4) + (X * 4)

CameraY = 55 + (Y * 4)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 255, 255, 150)

Next Y

Next X

' Draw Tile Attribute

For X = 0 To MapX

For Y = 0 To MapY

CameraX = CameraXSize - (MapX * 4) + (X * 4)

CameraY = 55 + (Y * 4)

Select Case Map.Tile(X, Y).Type

Case TILE_TYPE_BLOCKED

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 0, 0, 200)

Case TILE_TYPE_WARP

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(75, 0, 155, 200)

Case TILE_TYPE_ITEM

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(0, 155, 0, 200)

Case TILE_TYPE_SHOP

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 125, 0, 200)

End Select

Next Y

Next X

' Draw Player dot

For i = 1 To Player_HighIndex

If IsPlaying(i) Then

If GetPlayerMap(i) = GetPlayerMap(MyIndex) And (Not i = MyIndex) Then

Select Case Player(i).PK

Case 0

CameraX = CameraXSize - (MapX * 4) + (MiniMapPlayer(i).X)

CameraY = 55 + (MiniMapPlayer(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(0, 255, 0, 200)

Case 1

CameraX = CameraXSize - (MapX * 4) + (MiniMapPlayer(i).X)

CameraY = 55 + (MiniMapPlayer(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(100, 0, 0, 200)

End Select

End If

End If

Next i

' Draw NPC dot

For i = 1 To MAX_MAP_NPCS

If MapNpc(i).num > 0 Then

Select Case NPC(i).Behaviour

Case NPC_BEHAVIOUR_ATTACKONSIGHT

CameraX = CameraXSize - (MapX * 4) + (MiniMapNPC(i).X)

CameraY = 55 + (MiniMapNPC(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(0, 0, 0, 200)

Case NPC_BEHAVIOUR_ATTACKWHENATTACKED

CameraX = CameraXSize - (MapX * 4) + (MiniMapNPC(i).X)

CameraY = 55 + (MiniMapNPC(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(100, 0, 100, 200)

Case NPC_BEHAVIOUR_SHOPKEEPER

CameraX = CameraXSize - (MapX * 4) + (MiniMapNPC(i).X)

CameraY = 55 + (MiniMapNPC(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 125, 0, 200)

Case NPC_BEHAVIOUR_FRIENDLY

CameraX = CameraXSize - (MapX * 4) + (MiniMapNPC(i).X)

CameraY = 55 + (MiniMapNPC(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 0, 255, 200)

Case NPC_BEHAVIOUR_GUARD

CameraX = CameraXSize - (MapX * 4) + (MiniMapNPC(i).X)

CameraY = 55 + (MiniMapNPC(i).Y)

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(0, 255, 255, 200)

End Select

End If

Next i

' Draw Tile Attribute

For X = 0 To MapX

For Y = 0 To MapY

For i = 1 To Map.CurrentEvents

If Map.MapEvents(i).Visible = 1 Then

If Map.MapEvents(i).X = X Then

If Map.MapEvents(i).Y = Y Then

CameraX = CameraXSize - (MapX * 4) + (X * 4)

CameraY = 55 + (Y * 4)

Select Case Map.MapEvents(i).ShowName

Case 0 ' Tile

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(0, 0, 155, 200)

Case 1 ' Sprite

RenderTexture Tex_White, CameraX, CameraY, 0, 0, 4, 4, 4, 4, D3DColorRGBA(255, 255, 0, 200)

End Select

End If

End If

End If

Next i

Next Y

Next X

' Error handler

Exit Sub

ErrorHandler:

HandleError "DrawMiniMap", "modDirectDraw7", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Color Info

! Event With Name = Yellow
! Event Without Name = Dark Blue
! Default tile = White
! Block Tile = Red
! Warp Tile = Purple
! Item Tile = Green
! PK Player = Dark Red
! Non-PK = Light Green
! NPC Attack On Sight = Black
! NPC ATtack When Attacked = Dark Purple
! NPC SHopkeeper = Orange
! NPC Friendly = Pink
! NPC Guard = Light Blue

To change any of the colors, simple edit the value used inD3DColorRGBA()at the end of theRenderTexture Tex_Whiteline in```
Public Sub DrawMiniMap()


Example Ingame

>! ![](http://www.freemmorpgmaker.com/files/imagehost/pics/cf2831ecd53f42a5b77bf30028c174ed.png)

Will this work with any DX8 version? Like dragon eclipse?

Now you should do what Robin advised in the original tutorial, cache the data into memory rather then setting it every draw loop.

So, I know features like these keep getting put out for EA, but this would in theory work all the same with 3.0 no?

Should work in any of the DX8 versions. Might have to make some changes depending on what engine you use though.

You need to get visible events to show on the minimap too… heads up.

Cleaned up the code a little and also fixed a small bug I had in the ’ Draw Player dot.

And ya Jcsinder, I’ll work on adding it so the visible events show up also. I tried before but ducked it up so I have to retry that part later when I have time.

I thought there is a Problem on Eclipse 3.0 , on unrecovable Dx8 error ? is that already fixed?

Will this work with any DX8 version? Like dragon eclipse?

I don’t remember Dragon Eclipse being DirectX8 related, but maybe I should double check…although I have used it.

Ertzel you are making nices tutorials but it would be great if you don’t forget the others engine users ^^ hehe i’m also talking about dragon eclipse :P keep it up !

I don’t remember Dragon Eclipse being DirectX8 related, but maybe I should double check…although I have used it.

It is. The old buggy version isn’t.

Updated the original post with a new DrawMiniMap sub and a new image. With the new code and image it now displays events on the map also.

Like i said before, cache the equations instead of calculating them every loop.

What exactly do you mean by that? Can you give some kind of example.

The CameraX and CameraY is a great example, why should that be calculated every loop, rather then updating it when the player successfully moves.

I’m not sure still what exactly you mean or how it would be done…

I’m not sure still what exactly you mean or how it would be done…

Why do you do so many checks? Cache the positions and re-set them when packets arrive. Don’t just re-calculate everything each loop.

Caching is your friend.

Again, saying the same thing over and over isn’t going to help me get it done. I don’t know how I would do that which is why I asked for an example of how its done…

I’ll look into it right now, just let me go to the bathroom.

Do you mean something like this for NPC movement


        ' Draw NPC dot

        For I = 1 To Npc_HighIndex

                If MapNpc(I).num > 0 Then

                        Select Case Npc(I).Behaviour

                                Case NPC_BEHAVIOUR_ATTACKONSIGHT Or NPC_BEHAVIOUR_ATTACKWHENATTACKED

                                        CameraX = 780 - (MapX * 4) + (MiniMapNPC(I).x * 4)

                                        CameraY = 55 + (MiniMapNPC(I).y * 4)

                                        RenderTexture Tex_MiniMap, CameraX, CameraY, NpcAttackerRect.Left, NpcAttackerRect.Top, NpcAttackerRect.Right - NpcAttackerRect.Left, NpcAttackerRect.Bottom - NpcAttackerRect.Top, NpcAttackerRect.Right - NpcAttackerRect.Left, NpcAttackerRect.Bottom - NpcAttackerRect.Top, D3DColorRGBA(255, 255, 255, 200)

                                Case NPC_BEHAVIOUR_SHOPKEEPER

                                        CameraX = 780 - (MapX * 4) + (MiniMapNPC(I).x * 4)

                                        CameraY = 55 + (MiniMapNPC(I).y * 4)

                                        RenderTexture Tex_MiniMap, CameraX, CameraY, NpcShopRect.Left, NpcShopRect.Top, NpcShopRect.Right - NpcShopRect.Left, NpcShopRect.Bottom - NpcShopRect.Top, NpcShopRect.Right - NpcShopRect.Left, NpcShopRect.Bottom - NpcShopRect.Top, D3DColorRGBA(255, 255, 255, 200)

                                Case Else

                                        CameraX = 780 - (MapX * 4) + (MiniMapNPC(I).x * 4)

                                        CameraY = 55 + (MiniMapNPC(I).y * 4)

                                        RenderTexture Tex_MiniMap, CameraX, CameraY, NpcOtherRect.Left, NpcOtherRect.Top, NpcOtherRect.Right - NpcOtherRect.Left, NpcOtherRect.Bottom - NpcOtherRect.Top, NpcOtherRect.Right - NpcOtherRect.Left, NpcOtherRect.Bottom - NpcOtherRect.Top, D3DColorRGBA(255, 255, 255, 200)

                        End Select

                End If

        Next I

then having```

Public MiniMapNPC(1 To MAX_MAP_NPCS) As MiniMapNpcRec

Public Type MiniMapNpcRec

x As Long

y As Long

End Type

in modTypes and in HandleNpcMove having something like this
MiniMapNPC(MapNpcNum).x = x

MiniMapNPC(MapNpcNum).y = y

Or did I get the wrong meaning of what you where saying?
Log in to reply