05-07-2007, 02:26 PM
Since this isn't up, I'll repost this aswell
Directional Blocking (My way)
Difficulty 3/5
Ok, this tutorial will allow each tile to have its own Blocking rules so there’s no need for TILE_TYPE_BLOCK (Although it will still be there if you want it). On Map Editor, a new option will be added to allow viewing tile Block pattern and will blt on each tile, the directions your able to walk in (If your unable to walk in a certain direction, a circle will be placed instead of an arrow) and in the center of every tile is a toggle circle that will Enable/Disable the ability to walk over the tile.
Btw, I’m not sure, but I assume that this will muck up any maps you already have so you either have to redo the maps, or make a small app to convert all old maps to this new format
Ok, lets Begin, first off lets change the way Tiles are read and saved, so find TileRec on both Client and Server and add to the bottom of the type:
This will be used to record which directions are walkable, if a directions walkable, it will be set to true
Now, lets just add the controls we’ll be using in Map Editor, Add a Checkbox called chkDirectionView and two command buttons called cmdFillDirections and cmdClearDirections
![[Image: directionblockmapeditor9aw.th.png]](http://img25.imageshack.us/img25/3708/directionblockmapeditor9aw.th.png)
Ok, now we’ve added the controls, we need the server to send us the new Tile Records to the client so find the sub SendMap, find:
and replace it with:
Now find SendMap in the Client and replace the same thing
Now, we need the client to interpret this new data when its received so find:
And after SaveMap.Tile(x, y).Data3 add:
And change:To: So we can keep track on what we’ve received
Now we’ve done all that, we need to make the server aware of all this malarkey that the clients sending so find:
And add:
And again, change the n = n +8 to n = n + 12
Now the server can quite happily send and retrieve the new data, we need to allow the Client to edit this data, so let’s first make the Client Blt the arrows onto each tile by adding a new surface containing the arrows. First, save this image to your Client Gfx Folder and call it ‘Direction’ and the extension you use. http://img363.imageshack.us/img363/4606 ... ion6rn.png
We want to do this neatly and as fully as possible so find
And replace it with:
Now, we need to create the DirectDraw surface, so find and underneath it add:
Also find: and add underneath
Now we need to add the code that actually inits the surface, so find
And add under it
Lets go though this line by line, the .lFlags is telling Dx what properties to look at, so if we added, ddsd_Height, it will check the height property, in this case its checking the caps property. The .lCaps is describing how to load the surface, in this case its placed into the video memory. (Not 100% sure what the OffScreenPlain does, but you use it for any surface that’s in the background)
The next line tells it to load a picture from file onto the surface using the properties we’ve just set, and the line after that just tells it what colours to make invisible.
We also have to unload the surface from memory when we exit so find and add
Now we need to display the directions on the map when we choose to so, find:
And replace it withAll this does is disable viewing tile attribs when viewing Tile Directions
Now to main part that displays the arrows, we need this to be displayed above everything including all text, so we need to place this just after the backbuffer is released when blting text, so find:
And add this
and then add the end of modGameLogic add this sub
All this sub does is, go though each tile, checks its walkable properties and blts the correct image, once it’s done that it blts 2 lines which will eventually create a grid. The only other thing to explain about this sub is that it blts the center shape by checking if the tile is totally blocked, and if it is, it will blt a cross, if not, it blts a circle.
We still need to make use of them buttons we added earlier, so double click on cmdFillDirections and add:
All this does is scan each tile and make each direction walkable
Now double click cmdClearDirections and add:
This also scans each tile, but this time, it cuts off all directions.
Direction Blocking Part 2
Finally gotten round to starting the second half
I better explain first what I’m going to do next for detecting which tile and where on the tile you’ve clicked, so far, i've split the tile into sections like this...
![[Image: tilesection6rk.png]](http://img69.imageshack.us/img69/8615/tilesection6rk.png)
Each section is a different clickable area, for example, the green area is for Blocking/Unblocking walking up and if the user clicks in this area then it will toggle it, the only problem now, is the corners at each side of the green section. The easiest way to solve this is to divide the whole tile into nine sections, like this…
![[Image: tilesectionblock4aq.png]](http://img29.imageshack.us/img29/6905/tilesectionblock4aq.png)
What we need the client to do now when the mouse is clicked, is to scan which section was clicked. So, open up your client, find the sub EditorMouseDown.
Now at the top with the variables declaration, add these variables:
Now, to make it look neat, indent this
All this section does is scan for which of the nine parts of the tile we clicked, and changes the settings respectively. If it’s a corner, it will compare x and y to tell which side of the square its on, for, if X = Y, it will create a line from one corner to the other, if X > Y, it will make a point on one side of the line, if Y > X, it will create a point on the other side of the line.
Ok, right now, we have to actually restrict player movement if the tile their standing on needs to so, in the client, find sub CanMove, find:
And after it, add:
Now, find this, which is a bit below it (This ones the walking down version)
and add below it
And now for the left movement, find
And add:
Now the right side, find
Then add:
Now, this alone would work, but if a player is using a hacked client, or has hacked the map somehow, this could be bypassed easily, so we need to change the Player movement in the server, so find in the server, sub PlayerMove, and we basically have to do something similar here so locate:
And Change it to:
Now do the same with:And change to:
Now do the same with:And change to:
Now do the same with:And change to:
That should be everything, find any problems with this let me know. Btw, I wont be surprised if you dont understand it, I found it a kinda hard to explain some of the things..
Directional Blocking (My way)
Difficulty 3/5
Ok, this tutorial will allow each tile to have its own Blocking rules so there’s no need for TILE_TYPE_BLOCK (Although it will still be there if you want it). On Map Editor, a new option will be added to allow viewing tile Block pattern and will blt on each tile, the directions your able to walk in (If your unable to walk in a certain direction, a circle will be placed instead of an arrow) and in the center of every tile is a toggle circle that will Enable/Disable the ability to walk over the tile.
Btw, I’m not sure, but I assume that this will muck up any maps you already have so you either have to redo the maps, or make a small app to convert all old maps to this new format
Ok, lets Begin, first off lets change the way Tiles are read and saved, so find TileRec on both Client and Server and add to the bottom of the type:
Code:
WalkUp As Boolean
WalkDown As Boolean
WalkLeft As Boolean
WalkRight As Boolean
This will be used to record which directions are walkable, if a directions walkable, it will be set to true
Now, lets just add the controls we’ll be using in Map Editor, Add a Checkbox called chkDirectionView and two command buttons called cmdFillDirections and cmdClearDirections
![[Image: directionblockmapeditor9aw.th.png]](http://img25.imageshack.us/img25/3708/directionblockmapeditor9aw.th.png)
Ok, now we’ve added the controls, we need the server to send us the new Tile Records to the client so find the sub SendMap, find:
Code:
Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR
and replace it with:
Code:
Packet = Packet & .Ground & SEP_CHAR & .Mask & SEP_CHAR & .Anim & SEP_CHAR & .Fringe & SEP_CHAR & .Type & SEP_CHAR & .Data1 & SEP_CHAR & .Data2 & SEP_CHAR & .Data3 & SEP_CHAR & .WalkUp & SEP_CHAR & .WalkDown & SEP_CHAR & .WalkLeft & SEP_CHAR & .WalkRight & SEP_CHAR
Now find SendMap in the Client and replace the same thing
Now, we need the client to interpret this new data when its received so find:
Code:
SaveMap.Tile(x, y).Ground = Val(Parse(n))
SaveMap.Tile(x, y).Mask = Val(Parse(n + 1))
SaveMap.Tile(x, y).Anim = Val(Parse(n + 2))
SaveMap.Tile(x, y).Fringe = Val(Parse(n + 3))
SaveMap.Tile(x, y).Type = Val(Parse(n + 4))
SaveMap.Tile(x, y).Data1 = Val(Parse(n + 5))
SaveMap.Tile(x, y).Data2 = Val(Parse(n + 6))
SaveMap.Tile(x, y).Data3 = Val(Parse(n + 7))
n = n + 8
And after SaveMap.Tile(x, y).Data3 add:
Code:
SaveMap.Tile(x, y).WalkUp = Parse(n + 8)
SaveMap.Tile(x, y).WalkDown = Parse(n + 9)
SaveMap.Tile(x, y).WalkLeft = Parse(n + 10)
SaveMap.Tile(x, y).WalkRight = Parse(n + 11)
And change:
Code:
n = n + 8
Code:
n = n + 12
Now we’ve done all that, we need to make the server aware of all this malarkey that the clients sending so find:
Code:
Map(MapNum).Tile(x, y).Ground = Val(Parse(n))
Map(MapNum).Tile(x, y).Mask = Val(Parse(n + 1))
Map(MapNum).Tile(x, y).Anim = Val(Parse(n + 2))
Map(MapNum).Tile(x, y).Fringe = Val(Parse(n + 3))
Map(MapNum).Tile(x, y).Type = Val(Parse(n + 4))
Map(MapNum).Tile(x, y).Data1 = Val(Parse(n + 5))
Map(MapNum).Tile(x, y).Data2 = Val(Parse(n + 6))
Map(MapNum).Tile(x, y).Data3 = Val(Parse(n + 7))
And add:
Code:
Map(MapNum).Tile(x, y).WalkUp = Parse(n + 8)
Map(MapNum).Tile(x, y).WalkDown = Parse(n + 9)
Map(MapNum).Tile(x, y).WalkLeft = Parse(n + 10)
Map(MapNum).Tile(x, y).WalkRight = Parse(n + 11)
And again, change the n = n +8 to n = n + 12
Now the server can quite happily send and retrieve the new data, we need to allow the Client to edit this data, so let’s first make the Client Blt the arrows onto each tile by adding a new surface containing the arrows. First, save this image to your Client Gfx Folder and call it ‘Direction’ and the extension you use. http://img363.imageshack.us/img363/4606 ... ion6rn.png
We want to do this neatly and as fully as possible so find
Code:
If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Then
Code:
If FileExist(FileName & "sprites" & GFX_EXT, True) = False Or FileExist(FileName & "tiles" & GFX_EXT, True) = False Or FileExist(FileName & "items" & GFX_EXT, True) = False Or FileExist(FileName & "Direction" & GFX_EXT, True) = False Then
Now, we need to create the DirectDraw surface, so find
Code:
Public DDSD_Item As DDSURFACEDESC2
Code:
Public DDSD_Direction As DDSURFACEDESC2
Also find:
Code:
Public DD_ItemSurf As DirectDrawSurface7
Code:
Public DD_DirectionSurf As DirectDrawSurface7
Now we need to add the code that actually inits the surface, so find
Code:
' Init items ddsd type and load the bitmap
With DDSD_Item
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY
End With
Set DD_ItemSurf = DD.CreateSurfaceFromFile(FileName & "items" & GFX_EXT, DDSD_Item)
DD_ItemSurf.SetColorKey DDCKEY_SRCBLT, Key
And add under it
Code:
' Init Direction ddsd type and load the bitmap
With DDSD_Direction
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY
End With
Set DD_DirectionSurf = DD.CreateSurfaceFromFile(FileName & "Direction" & GFX_EXT, DDSD_Direction)
DD_DirectionSurf.SetColorKey DDCKEY_SRCBLT, Key
Lets go though this line by line, the .lFlags is telling Dx what properties to look at, so if we added, ddsd_Height, it will check the height property, in this case its checking the caps property. The .lCaps is describing how to load the surface, in this case its placed into the video memory. (Not 100% sure what the OffScreenPlain does, but you use it for any surface that’s in the background)
The next line tells it to load a picture from file onto the surface using the properties we’ve just set, and the line after that just tells it what colours to make invisible.
We also have to unload the surface from memory when we exit so find
Code:
Set DD_ItemSurf = Nothing
Code:
Set DD_DirectionSurf = Nothing
Now we need to display the directions on the map when we choose to so, find:
Code:
' Blit out attribs if in editor
If InEditor Then
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
With Map.Tile(x, y)
If .Type = TILE_TYPE_BLOCKED Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "B", QBColor(BrightRed))
If .Type = TILE_TYPE_WARP Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "W", QBColor(BrightBlue))
If .Type = TILE_TYPE_ITEM Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "I", QBColor(White))
If .Type = TILE_TYPE_NPCAVOID Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "N", QBColor(White))
If .Type = TILE_TYPE_KEY Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "K", QBColor(White))
If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))
If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
End With
Next x
Next y
End If
And replace it with
Code:
' Blit out attribs if in editor
If InEditor Then
If frmMirage.chkDirectionView.Value = 0 Then
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
With Map.Tile(x, y)
If .Type = TILE_TYPE_BLOCKED Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "B", QBColor(BrightRed))
If .Type = TILE_TYPE_WARP Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "W", QBColor(BrightBlue))
If .Type = TILE_TYPE_ITEM Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "I", QBColor(White))
If .Type = TILE_TYPE_NPCAVOID Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "N", QBColor(White))
If .Type = TILE_TYPE_KEY Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "K", QBColor(White))
If .Type = TILE_TYPE_KEYOPEN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "O", QBColor(White))
If .Type = TILE_TYPE_NPCSPAWN Then Call DrawText(TexthDC, x * PIC_X + 8, y * PIC_Y + 8, "NS", QBColor(Yellow))
End With
Next x
Next y
End If
End If
Now to main part that displays the arrows, we need this to be displayed above everything including all text, so we need to place this just after the backbuffer is released when blting text, so find:
Code:
Call DD_BackBuffer.ReleaseDC(TexthDC)
And add this
Code:
If InEditor Then
If frmMirage.chkDirectionView.Value = 1 Then
Call BltDirectionArrows
End If
End If
and then add the end of modGameLogic add this sub
Code:
Public Sub BltDirectionArrows()
Dim x As Long, y As Long
Dim Walkable As Boolean ' If tile has at least one dir, change center to circle
For y = 0 To MAX_MAPY
For x = 0 To MAX_MAPX
With Map.Tile(x, y)
Walkable = False ' Reset for a new tile
' Lets check what to Blt for the Up arrow
If .WalkUp Then
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = PIC_Y * 3
.Right = .Left + PIC_Y
End With
Walkable = True
Else
With rec
.top = PIC_X
.Bottom = .top + PIC_X
.Left = PIC_Y * 3
.Right = .Left + PIC_Y
End With
End If
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_DirectionSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
' Now lets check For Down Arrow
If .WalkDown Then
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = PIC_Y * 2
.Right = .Left + PIC_Y
End With
Walkable = True
Else
With rec
.top = PIC_X
.Bottom = .top + PIC_X
.Left = PIC_Y * 2
.Right = .Left + PIC_Y
End With
End If
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_DirectionSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
' Now lets check For Left Arrow
If .WalkLeft Then
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = PIC_Y * 0
.Right = .Left + PIC_Y
End With
Walkable = True
Else
With rec
.top = PIC_X
.Bottom = .top + PIC_X
.Left = PIC_Y * 0
.Right = .Left + PIC_Y
End With
End If
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_DirectionSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
' Now lets check For Right Arrow
If .WalkRight Then
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = PIC_Y * 1
.Right = .Left + PIC_Y
End With
Walkable = True
Else
With rec
.top = PIC_X
.Bottom = .top + PIC_X
.Left = PIC_Y * 1
.Right = .Left + PIC_Y
End With
End If
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_DirectionSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
' If tile is totally blocked, place cross in center
If Walkable Then
With rec
.top = 0
.Bottom = .top + PIC_X
.Left = PIC_Y * 4
.Right = .Left + PIC_Y
End With
Else
With rec
.top = PIC_X
.Bottom = .top + PIC_X
.Left = PIC_Y * 4
.Right = .Left + PIC_Y
End With
End If
Call DD_BackBuffer.BltFast(x * PIC_X, y * PIC_Y, DD_DirectionSurf, rec, DDBLTFAST_WAIT Or DDBLTFAST_SRCCOLORKEY)
' We need to draw a grid so we can tell which tiles which (First set pen width to 1)
DD_BackBuffer.DrawLine x * PIC_X, y * PIC_Y, x * PIC_X, y * PIC_Y + (PIC_Y * MAX_MAPY) + 1
DD_BackBuffer.DrawLine x * PIC_X, y * PIC_Y, x * PIC_X + (PIC_X * MAX_MAPX) + 1, y * PIC_Y
End With
Next x
Next y
End Sub
All this sub does is, go though each tile, checks its walkable properties and blts the correct image, once it’s done that it blts 2 lines which will eventually create a grid. The only other thing to explain about this sub is that it blts the center shape by checking if the tile is totally blocked, and if it is, it will blt a cross, if not, it blts a circle.
We still need to make use of them buttons we added earlier, so double click on cmdFillDirections and add:
Code:
Dim X As Long, Y As Long
' Go through each tile and set each direction to walkable
For X = 0 To MAX_MAPX
For Y = 0 To MAX_MAPY
With Map.Tile(X, Y)
.WalkUp = True
.WalkDown = True
.WalkLeft = True
.WalkRight = True
End With
Next Y
Next X
All this does is scan each tile and make each direction walkable
Now double click cmdClearDirections and add:
Code:
Dim X As Long, Y As Long
' Go through each tile and set each direction to walkable
For X = 0 To MAX_MAPX
For Y = 0 To MAX_MAPY
With Map.Tile(X, Y)
.WalkUp = False
.WalkDown = False
.WalkLeft = False
.WalkRight = False
End With
Next Y
Next X
This also scans each tile, but this time, it cuts off all directions.
Direction Blocking Part 2
Finally gotten round to starting the second half

I better explain first what I’m going to do next for detecting which tile and where on the tile you’ve clicked, so far, i've split the tile into sections like this...
![[Image: tilesection6rk.png]](http://img69.imageshack.us/img69/8615/tilesection6rk.png)
Each section is a different clickable area, for example, the green area is for Blocking/Unblocking walking up and if the user clicks in this area then it will toggle it, the only problem now, is the corners at each side of the green section. The easiest way to solve this is to divide the whole tile into nine sections, like this…
![[Image: tilesectionblock4aq.png]](http://img29.imageshack.us/img29/6905/tilesectionblock4aq.png)
What we need the client to do now when the mouse is clicked, is to scan which section was clicked. So, open up your client, find the sub EditorMouseDown.
Now at the top with the variables declaration, add these variables:
Code:
Dim x2 As Long, y2 As Long ' Used to record where on the tile was clicked
Dim CenterTolerence As RECT ' Controls how easy it is to press center
Now, to make it look neat, indent this
Code:
If (Button = 1) And (x1 >= 0) And (x1 = 0) And (y1 = 0) And (x1 = 0) And (y1 .Right Then ' Right side
If y2 > .Bottom Then ' Right Bottom
' Now check which side of that small section was clicked
If x2 > y2 Then
Map.Tile(x1, y1).WalkRight = True
Else
Map.Tile(x1, y1).WalkDown = True
End If
ElseIf y2 > .Left Then ' Right Middle
Map.Tile(x1, y1).WalkRight = True
Else ' Right Top
' Check which side was clicked, remember, minus from x because
' its not starting from 0
If x2 - .Right > y2 Then
Map.Tile(x1, y1).WalkUp = True
Else
Map.Tile(x1, y1).WalkRight = True
End If
End If
ElseIf x2 > .Left Then ' Middle side
If y2 > .Bottom Then 'Bottom
Map.Tile(x1, y1).WalkDown = True
ElseIf y2 > .Left Then ' Middle
Map.Tile(x1, y1).WalkUp = True
Map.Tile(x1, y1).WalkDown = True
Map.Tile(x1, y1).WalkLeft = True
Map.Tile(x1, y1).WalkRight = True
Else ' Top
Map.Tile(x1, y1).WalkUp = True
End If
Else
If y2 > .Bottom Then 'Left Bottom
If x2 > y2 - .Bottom Then
Map.Tile(x1, y1).WalkDown = True
Else
Map.Tile(x1, y1).WalkLeft = True
End If
ElseIf y2 > .Left Then ' Left Middle
Map.Tile(x1, y1).WalkLeft = True
Else ' Left Top
If x2 > y2 Then
Map.Tile(x1, y1).WalkUp = True
Else
Map.Tile(x1, y1).WalkLeft = True
End If
End If
End If
ElseIf Button = 2 And (x1 >= 0) And (x1 = 0) And (y1 .Bottom Then ' Right Bottom
' Now check which side of that small section was clicked
If x2 > y2 Then
Map.Tile(x1, y1).WalkRight = False
Else
Map.Tile(x1, y1).WalkDown = False
End If
ElseIf y2 > .Left Then ' Right Middle
Map.Tile(x1, y1).WalkRight = False
Else ' Right Top
' Check which side was clicked, remember, minus from x because
' its not starting from 0
If x2 - .Right > y2 Then
Map.Tile(x1, y1).WalkUp = False
Else
Map.Tile(x1, y1).WalkRight = False
End If
End If
ElseIf x2 > .Left Then ' Middle side
If y2 > .Bottom Then 'Bottom
Map.Tile(x1, y1).WalkDown = False
ElseIf y2 > .Left Then ' Middle
Map.Tile(x1, y1).WalkUp = False
Map.Tile(x1, y1).WalkDown = False
Map.Tile(x1, y1).WalkLeft = False
Map.Tile(x1, y1).WalkRight = False
Else ' Top
Map.Tile(x1, y1).WalkUp = False
End If
Else
If y2 > .Bottom Then 'Left Bottom
If x2 > y2 - .Bottom Then
Map.Tile(x1, y1).WalkDown = False
Else
Map.Tile(x1, y1).WalkLeft = False
End If
ElseIf y2 > .Left Then ' Left Middle
Map.Tile(x1, y1).WalkLeft = False
Else ' Left Top
If x2 > y2 Then
Map.Tile(x1, y1).WalkUp = False
Else
Map.Tile(x1, y1).WalkLeft = False
End If
End If
End If
End With
Else
All this section does is scan for which of the nine parts of the tile we clicked, and changes the settings respectively. If it’s a corner, it will compare x and y to tell which side of the square its on, for, if X = Y, it will create a line from one corner to the other, if X > Y, it will make a point on one side of the line, if Y > X, it will create a point on the other side of the line.
Ok, right now, we have to actually restrict player movement if the tile their standing on needs to so, in the client, find sub CanMove, find:
Code:
' Check to see if a npc is already on that tile
For i = 1 To MAX_MAP_NPCS
If MapNpc(i).Num > 0 Then
If (MapNpc(i).x = GetPlayerX(MyIndex)) And (MapNpc(i).y = GetPlayerY(MyIndex) - 1) Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_UP Then
Call SendPlayerDir
End If
Exit Function
End If
End If
Next i
Code:
' Check if the tile will let us walk onto it
If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).WalkUp = False Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_UP Then
Call SendPlayerDir
End If
Exit Function
End If
Now, find this, which is a bit below it (This ones the walking down version)
Code:
' Check to see if a npc is already on that tile
For i = 1 To MAX_MAP_NPCS
If MapNpc(i).Num > 0 Then
If (MapNpc(i).x = GetPlayerX(MyIndex)) And (MapNpc(i).y = GetPlayerY(MyIndex) + 1) Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_DOWN Then
Call SendPlayerDir
End If
Exit Function
End If
End If
Next i
and add below it
Code:
' Check if the tile will let us walk onto it
If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).WalkDown = False Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_DOWN Then
Call SendPlayerDir
End If
Exit Function
End If
And now for the left movement, find
Code:
' Check to see if a npc is already on that tile
For i = 1 To MAX_MAP_NPCS
If MapNpc(i).Num > 0 Then
If (MapNpc(i).x = GetPlayerX(MyIndex) - 1) And (MapNpc(i).y = GetPlayerY(MyIndex)) Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_LEFT Then
Call SendPlayerDir
End If
Exit Function
End If
End If
Next I
And add:
Code:
' Check if the tile will let us walk onto it
If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).WalkLeft = False Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_LEFT Then
Call SendPlayerDir
End If
Exit Function
End If
Now the right side, find
Code:
' Check to see if a npc is already on that tile
For i = 1 To MAX_MAP_NPCS
If MapNpc(i).Num > 0 Then
If (MapNpc(i).x = GetPlayerX(MyIndex) + 1) And (MapNpc(i).y = GetPlayerY(MyIndex)) Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_RIGHT Then
Call SendPlayerDir
End If
Exit Function
End If
End If
Next I
Then add:
Code:
' Check if the tile will let us walk onto it
If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).WalkRight = False Then
CanMove = False
' Set the new direction if they weren't facing that direction
If d DIR_RIGHT Then
Call SendPlayerDir
End If
Exit Function
End If
Now, this alone would work, but if a player is using a hacked client, or has hacked the map somehow, this could be bypassed easily, so we need to change the Player movement in the server, so find in the server, sub PlayerMove, and we basically have to do something similar here so locate:
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED Then
And Change it to:
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) - 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkUp Then
Now do the same with:
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkDown Then
Now do the same with:
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) ).Type TILE_TYPE_BLOCKED Then
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)-1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkLeft Then
Now do the same with:
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED Then
Code:
If Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index)+1, GetPlayerY(Index) + 1).Type TILE_TYPE_BLOCKED And Map(GetPlayerMap(Index)).Tile(GetPlayerX(Index), GetPlayerY(Index)).WalkRight Then
That should be everything, find any problems with this let me know. Btw, I wont be surprised if you dont understand it, I found it a kinda hard to explain some of the things..