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

[Any Event Version] Basic Instanced Maps


JohnPony
 Share

Recommended Posts

**Server Side:**

in modDatabase replace loadmaps with

```

Public Sub LoadMaps()

Dim filename As String

Dim i As Long

Dim F As Long

Dim x As Long

Dim y As Long, z As Long, p As Long, w As Long

Dim newtileset As Long, newtiley As Long

Call CheckMaps

[size]For i = 1 To 99

filename = App.path & "\data\maps\map" & i & ".dat"

F = FreeFile

Open filename For Binary As #F

Get #F, , Map(i).Name

Get #F, , Map(i).Music

Get #F, , Map(i).BGS

Get #F, , Map(i).Revision

Get #F, , Map(i).Moral

Get #F, , Map(i).Up

Get #F, , Map(i).Down

Get #F, , Map(i).Left

Get #F, , Map(i).Right

Get #F, , Map(i).BootMap

Get #F, , Map(i).BootX

Get #F, , Map(i).BootY

Get #F, , Map(i).Weather

Get #F, , Map(i).WeatherIntensity

Get #F, , Map(i).Fog

Get #F, , Map(i).FogSpeed

Get #F, , Map(i).FogOpacity

Get #F, , Map(i).Red

Get #F, , Map(i).Green

Get #F, , Map(i).Blue

Get #F, , Map(i).Alpha

Get #F, , Map(i).MaxX

Get #F, , Map(i).MaxY

' have to set the tile()

ReDim Map(i).Tile(0 To Map(i).MaxX, 0 To Map(i).MaxY)[/size]

[size] For x = 0 To Map(i).MaxX

For y = 0 To Map(i).MaxY

Get #F, , Map(i).Tile(x, y)

Next

Next[/size]

[size] For x = 1 To MAX_MAP_NPCS

Get #F, , Map(i).Npc(x)

Get #F, , Map(i).NpcSpawnType(x)

MapNpc(i).Npc(x).Num = Map(i).Npc(x)

Next[/size]

[size] Close #F

ClearTempTile i

CacheResources i

DoEvents

CacheMapBlocks i

Next

End Sub

[/size]

[size]And replace check maps with:[/size]

[size][code]

Sub CheckMaps()

Dim i As Long

[size] For i = 1 To 99

If Not FileExist("\Data\maps\map" & i & ".dat") Then

Call SaveMap(i)

End If

Next[/size]

[size]End Sub

[/size]

[size]And add this at the bottom of the module:[/size]

[size][code]

Sub LoadMap(ByVal MapNum As Long, ByVal Max As Long)

Dim filename As String

Dim Filename2 As String

Dim i As Long

Dim F As Long

Dim x As Long

Dim y As Long, z As Long, p As Long, w As Long

Dim newtileset As Long, newtiley As Long

[size] i = MapNum

filename = App.path & "\data\maps\map" & i & ".dat"

F = FreeFile

Open filename For Binary As #F

Get #F, , Map(i).Name

Get #F, , Map(i).Music

Get #F, , Map(i).BGS

Get #F, , Map(i).Revision

Get #F, , Map(i).Moral

Get #F, , Map(i).Up

Get #F, , Map(i).Down

Get #F, , Map(i).Left

Get #F, , Map(i).Right

Get #F, , Map(i).BootMap

Get #F, , Map(i).BootX

Get #F, , Map(i).BootY

Get #F, , Map(i).Weather

Get #F, , Map(i).WeatherIntensity

Get #F, , Map(i).Fog

Get #F, , Map(i).FogSpeed

Get #F, , Map(i).FogOpacity

Get #F, , Map(i).Red

Get #F, , Map(i).Green

Get #F, , Map(i).Blue

Get #F, , Map(i).Alpha

Get #F, , Map(i).MaxX

Get #F, , Map(i).MaxY

' have to set the tile()

ReDim Map(i).Tile(0 To Map(i).MaxX, 0 To Map(i).MaxY)[/size]

[size] For x = 0 To Map(i).MaxX

For y = 0 To Map(i).MaxY

Get #F, , Map(i).Tile(x, y)

Next

Next[/size]

[size] For x = 1 To MAX_MAP_NPCS

Get #F, , Map(i).Npc(x)

Get #F, , Map(i).NpcSpawnType(x)

MapNpc(i).Npc(x).Num = Map(i).Npc(x)

Next[/size]

[size] Close #F

ClearTempTile i

CacheResources i

DoEvents

CacheMapBlocks i

End Sub[/size]

[size][/size]

[size]Next download the attachment below and add it to the server[/size]

[size]in modGeneral in InitServer add:[/size]

[size][code]

Call SetStatus("Clearing Unused Maps...")

Call ClearInstance

[/code][/size]

[size]In modTypes in the playerrec at the bottom add:[/size]

[size][code]

PrevMap As Long

PrevX As Long

PrevY As Long

[/code][/size]

Next in modServerTcp in SubSendLeaveMap at the bottom add:

[code]

If GetTotalMapPlayers(MapNum) = 0 Then

If MapNum > 100 Then

Call ClearInstancedMap(MapNum)

End If

End If

[/code]

and at the bottom of the module add:

[code]

Sub SendInstance(ByVal Index As Long, ByVal OldMapNum As Long, ByVal NewMapNum As Long)

Dim buffer As clsBuffer

Set buffer = New clsBuffer

buffer.WriteLong SInstance

buffer.WriteLong OldMapNum

buffer.WriteLong NewMapNum

SendDataTo Index, buffer.ToArray

Set buffer = Nothing

End Sub

[/code]

Next in modEnumerations with the server packets add:

[code]

SInstance

[/code]

and in modPlayer in the JoinGame sub add:

[code]

If Player(Index).PrevMap > 0 Then

Call PlayerWarp(Index, Player(Index).PrevMap, Player(Index).PrevX, Player(Index).PrevY)

Player(Index).PrevMap = 0

Player(Index).PrevX = 0

Player(Index).PrevY = 0

Call PlayerMsg(Index, "You Have Left The Instance!", Red)

End If

[/code]

and at the bottom of modPlayer add:

[code]

Sub PartyWarp(ByVal Index As Long, ByVal MapNum As Long, ByVal x As Long, ByVal y As Long, Optional Instance As Boolean = False)

Dim i As Long

If TempPlayer(Index).inParty Then

For i = 1 To Party(TempPlayer(Index).inParty).MemberCount

If Instance Then

Player(Party(TempPlayer(Index).inParty).Member(i)).PrevMap = GetPlayerMap(Party(TempPlayer(Index).inParty).Member(i))

Player(Party(TempPlayer(Index).inParty).Member(i)).PrevX = GetPlayerX(Party(TempPlayer(Index).inParty).Member(i))

Player(Party(TempPlayer(Index).inParty).Member(i)).PrevY = GetPlayerY(Party(TempPlayer(Index).inParty).Member(i))

End If

Call PlayerWarp(Party(TempPlayer(Index).inParty).Member(i), MapNum, x, y)

Next

End If

End Sub

[/code]

And at the bottom of Sub PlayerWarp add:

[code]

If GetTotalMapPlayers(OldMap) <= 0 Then

If OldMap >= 100 Then

Call ClearInstancedMap(OldMap)

End If

End If

[/code]

And in the PlayerMove sub below the tile_type_slide procedure add:

[code]

If .Type = TILE_TYPE_INSTANCE Then

' Check if already on instanced map

If GetPlayerMap(Index) >= 100 Then

Moved = NO

Else

' New Instance

For i = 100 To MAX_MAPS

If GetTotalMapPlayers(i) > 0 Then

CanWarp = False

Else

CanWarp = True

End If

If CanWarp Then

' Save Previous Coords

Player(Index).PrevMap = GetPlayerMap(Index)

Player(Index).PrevX = GetPlayerX(Index)

Player(Index).PrevY = GetPlayerY(Index)

' Instance New Map

Call InstanceMap(.Data1, i, Index)

' Warp Player(s)

If TempPlayer(Index).inParty Then

Call PartyWarp(Index, i, .Data2, .Data3, True)

Else

Call PlayerWarp(Index, i, .Data2, .Data3)

End If

Exit For

End If

Next i

End If

Moved = YES

End If

[/code]

And in modConstants with the Tile types add:

[code]

Public Const TILE_TYPE_INSTANCE As Byte = 16

[/code]

[b][size]Client Side:[/size][/b]

in modText in Public Function DrawMapAttributes() add:

[code]

Case TILE_TYPE_INSTANCE

RenderText Font_Default, "MI", tx, ty, Red

[/code]

Next in modGameLogic in CheckMovement find:

[code]

If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_WARP

[/code]
And replace it with

[code]

If Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_WARP Or Map.Tile(GetPlayerX(MyIndex), GetPlayerY(MyIndex)).Type = TILE_TYPE_INSTANCE

[/code]

Next in modConstants with the tile types add:

[code]

Public Const TILE_TYPE_INSTANCE As Byte = 16

[/code]

Now add the files from the attachment download to the client, you should know which ones ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)

in modGameEditors in MapEditorMouseDown add:

[code]

' instance

If frmEditor_Map.optInstance.value Then

.Type = TILE_TYPE_INSTANCE

.Data1 = EditorWarpMap

.Data2 = EditorWarpX

.Data3 = EditorWarpY

End If

[/code]

In modEnumerations with the server packets add:

[code]

SInstance

[/code]

in modHandleData with the messages add:

[code]

HandleDataSub(SInstance) = GetAddress(AddressOf HandleInstanced)

[/code]

And at the bottom of the module add:

[code]

Private Sub HandleInstanced(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)

Dim Buffer As clsBuffer

Dim OldMapNum As Long

Dim NewMapNum As Long

Dim filename As String

Dim Filename2 As String

Set Buffer = New clsBuffer

With Buffer

.WriteBytes Data()

OldMapNum = .ReadLong

NewMapNum = .ReadLong

End With

filename = App.Path & MAP_PATH & "map" & NewMapNum & ".Map"

Filename2 = App.Path & MAP_PATH & "map" & OldMapNum & ".Map"

If Not Dir(filename) = vbNullString Then

Kill filename

End If

If Dir(filename) = vbNullString Then

FileCopy Filename2, filename

End If

[/code]

[b]Attachment: [url]http://www.mmorpgcre....com/Attach.rar[/url][/b]

If You find any bugs please notify me, if i have forgotten anything i will fix the tutorial. This was working 100% for me and i have tested it for awhile, so i don't think there are any bugs.

Bug Fix:

Remove: (Server Side, modInstance)

[code] Call InstanceEvent(mapOriginalNum, mapCopyNum)[/code]

Bug Fix #2:

in modGlobals add:

[code]

Public CurrentMaxMaps As Long

[/code]

and in modServerInit before [code]

ServerLoop

[/code]

Add:

[code]

CurrentMaxMaps = 99

[/code]

And replace your modInstance with this:

[code]

Option Explicit

Public Sub InstanceMap(mapOriginalNum As Long, mapCopyNum As Long, Index As Long)

Dim filename As String

Dim Filename2 As String

' Save new copy

filename = App.path & "\data\maps\map" & mapCopyNum & ".dat"

Filename2 = App.path & "\data\maps\map" & mapOriginalNum & ".dat"

If Not Dir(filename) = vbNullString Then

Call ClearInstancedMap(mapCopyNum)

Call Clear(mapCopyNum)

End If

'F = FreeFile

FileCopy Filename2, filename

Call LoadMap(mapCopyNum, mapCopyNum)

Call SendInstance(Index, mapOriginalNum, mapCopyNum)

CurrentMaxMaps = CurrentMaxMaps + 1

End Sub

Public Sub ClearInstance()

Dim i As Long

Dim filename As String

Dim Filename2 As String

For i = 100 To MAX_MAPS

filename = App.path & "\data\maps\map" & i & ".dat"

Filename2 = App.path & "\data\maps\map" & i & "_eventdata.dat"

If Not Dir(filename) = vbNullString Then

Kill filename

Call SetStatus("Destroying Map # " & i)

End If

If Not Dir(Filename2) = vbNullString Then

Kill Filename2

Call SetStatus("Destroying Event Map # " & i)

End If

Next i

End Sub

Public Sub ClearInstancedMap(ByVal MapNum As Long)

Dim filename As String

Dim Filename2 As String

filename = App.path & "\data\maps\map" & MapNum & ".dat"

Filename2 = App.path & "\data\maps\map" & MapNum & "_eventdata.dat"

If Not Dir(filename) = vbNullString Then

Kill filename

Call SetStatus("Destroying Map # " & MapNum)

End If

If Not Dir(Filename2) = vbNullString Then

Kill Filename2

Call SetStatus("Destroying Event Map # " & MapNum)

End If

CurrentMaxMaps = CurrentMaxMaps - 1

End Sub

Public Sub Clear(ByVal MapNum As Long)

Call ClearMap(MapNum)

End Sub

[/code]

And finally in UpdateMapLogic replace [code]

For MapNum = 1 To MAX_MAPS

[/code]

with [code]

For MapNum = 1 To CurrentMaxMaps

[/code]

Regards,

General Pony[/code][/size][/code][/size]
```
Link to comment
Share on other sites

> Why are you done? School? As much as it disappoints me that I'm programming with a bum candy language for a game, the fact that it's fun keeps me here. You should get in on that bum candy, it's cool

I'm trying to move towards general programming design and theory rather then playing with a engine in a older language, not saying it wasn't enjoyable i just think that it's time for me to move on.
Link to comment
Share on other sites

> Ok, got some problems. You forgot to put prevx, prevy, and prevmap in player rec, also, when I create a new account and login it errors on
>
> ```
>
> And temptile(MapNum).DoorOpen(x1, y1) = YES Then
>
> ```
>
> for closing doors. Also, CanWarp is undefined. And that's as far as I got xD

```
Dim CanWarp As Boolean
```at the top of the player move sub, and i'm pretty sure the rest is JC's fault. His event system doesn't like my instanced maps which is why i the version i used i cut out the events.

I'm removing the event system portion from this tutorial, it's just too unstable and slow ATM.
Link to comment
Share on other sites

> Sub not defined on```
>
> Call SendLoad(Index)
>
> ```in mod instance.

Just remove that, wasn't supposed to be in there.

Should be working fine now, sorry for all these unexpected problems guy; as i stated in the other topic i can't seem to get the new forum post to work right with code, so half the time i have to go back and redo the tutorial code while in the post editor, which is where i forget stuff/leave stuff out. I apologize again for the inconvenience
Link to comment
Share on other sites

Fix:

Under

```
Call SendInstance(Index, mapOriginalNum, mapCopyNum)
```

Add

```
Call SpawnMapNpcs(mapCopyNum)
```

There is alot more bugs of course, but i am too lazy to post them ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png)
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...