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

[EO] Advanced doors, keys, and switches (v 3.0)


RyokuHasu
 Share

Recommended Posts

Ok last time I tried making a tutorial for doors I did it 1/2 arsed and there where complaints coming out the wazu. I eventually went over the entire case Dir line by line and rewote the entire thing using the original as a reference.

What it dose it give your game an advanced doors system an option on how to unlock them.

I also found a few other bugs that i ironed out in EXTENSIVE testing and debugging.

Again this has to be cut in parts because of the posting limit on content.

~~**PLEASE DO NOT POST A REPLY UNTIL ALL PARTS ARE POSTED.**~~

Now its all been posted, enjoy.

****WARNING DO NOT PLACE "EMPTY" DOORS ON MAP****

**This is NOT recommended if you are just starting with EO, or if you haven't done a few easier tutorials first.

**BOTH SERVER AND CLIENT**

Most of the constants for the doors and tile type are already there!

In mod constants

under ' General constants add
```
Public Const MAX_DOORS As Byte = 255

```
under ' Game editor constants add
```
Public Const EDITOR_DOORS As Byte = 7 'or the next number you dont have

```

In modTypes

at the top add
```
Public Doors(1 To MAX_DOORS) As DoorRec

```

Find "Private Type PlayerRec" and add above it
```
Public Type DoorRec
    Name As String * NAME_LENGTH
    DoorType As Long

    WarpMap As Long
    WarpX As Long
    WarpY As Long

    UnlockType As Long
    key As Long
    Switch As Long

    state As Long
End Type

```
In Private Type PlayerRec at the bottom add
```
PlayerDoors(1 To MAX_DOORS) As DoorRec

```

In modEnumerations

add to the bottom of the "c" list
```
    CSaveDoor
    CRequestDoors
    CRequestEditDoors

```
add to the "s" list
```
    SDoorsEditor
    SUpdateDoors

```

**SERVER**

in modHandleData

At the top in InitMessages() add
```
    HandleDataSub(CSaveDoor) = GetAddress(AddressOf HandleSaveDoor)
    HandleDataSub(CRequestDoors) = GetAddress(AddressOf HandleRequestDoors)
    HandleDataSub(CRequestEditDoors) = GetAddress(AddressOf HandleEditDoors)

```
find "Sub  HandleAttack" and add to the bottom
```
CheckDoor index, x, y

```
at the bottom of modHandleData add
```
'  //////////////////////////////////
' //Request/Save edit Door packets//
'//////////////////////////////////
Sub HandleEditDoors(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    Dim Buffer As clsBuffer

    ' Prevent hacking
    If GetPlayerAccess(index) < ADMIN_DEVELOPER Then
        Exit Sub
    End If

    Set Buffer = New clsBuffer
    Buffer.WriteLong SDoorsEditor
    SendDataTo index, Buffer.ToArray()
    Set Buffer = Nothing
End Sub

Sub HandleRequestDoors(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    SendDoors index
End Sub

Private Sub HandleSaveDoor(ByVal index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    Dim DoorNum As Long
    Dim Buffer As clsBuffer
    Dim DoorSize As Long
    Dim DoorData() As Byte

    ' Prevent hacking
    If GetPlayerAccess(index) < ADMIN_DEVELOPER Then
        Exit Sub
    End If

    Set Buffer = New clsBuffer
    Buffer.WriteBytes Data()
    DoorNum = Buffer.ReadLong

    ' Prevent hacking
    If DoorNum < 0 Or DoorNum > MAX_DOORS Then
        Exit Sub
    End If

    DoorSize = LenB(Doors(DoorNum))
    ReDim DoorData(DoorSize - 1)
    DoorData = Buffer.ReadBytes(DoorSize)
    CopyMemory ByVal VarPtr(Doors(DoorNum)), ByVal VarPtr(DoorData(0)), DoorSize
    ' Save it
    Call SendUpdateDoorToAll(DoorNum)
    Call SaveDoor(DoorNum)
    Call AddLog(GetPlayerName(index) & " saved Door #" & DoorNum & ".", ADMIN_LOG)
End Sub

```

In modDatabase add at the bottom
```
' ***********
' ** Doors **
' ***********

Sub SaveDoors()
    Dim i As Long

    For i = 1 To MAX_DOORS
        Call SaveDoor(i)
    Next

End Sub

Sub SaveDoor(ByVal DoorNum As Long)
    Dim filename As String
    Dim F As Long
    filename = App.Path & "\data\doors\door" & DoorNum & ".dat"
    F = FreeFile
    Open filename For Binary As #F
        Put #F, , Doors(DoorNum)
    Close #F
End Sub

Sub LoadDoors()
    Dim filename As String
    Dim i As Long
    Dim F As Long
    Dim sLen As Long

    Call CheckDoors

    For i = 1 To MAX_DOORS
        filename = App.Path & "\data\doors\door" & i & ".dat"
        F = FreeFile
        Open filename For Binary As #F
            Get #F, , Doors(i)
        Close #F
    Next

End Sub

Sub CheckDoors()
    Dim i As Long

    For i = 1 To MAX_DOORS
        If Not FileExist("\Data\doors\door" & i & ".dat") Then
            Call SaveDoor(i)
        End If
    Next

End Sub

Sub ClearDoor(ByVal index As Long)
    Call ZeroMemory(ByVal VarPtr(Doors(index)), LenB(Doors(index)))
    Doors(index).Name = vbNullString
    ReDim door(index)
End Sub

Sub ClearDoors()
    Dim i As Long

    For i = 1 To MAX_DOORS
        Call ClearDoor(i)
    Next

End Sub

```

In modServerTCP add at the bottom
```
Sub SendDoors(ByVal index As Long)
    Dim i As Long

    For i = 1 To MAX_DOORS

        If LenB(Trim$(Doors(i).Name)) > 0 Then
            Call SendUpdateDoorsTo(index, i)
        End If

    Next

End Sub

Sub SendUpdateDoorToAll(ByVal DoorNum As Long)
    Dim packet As String
    Dim Buffer As clsBuffer
    Dim DoorSize As Long
    Dim DoorData() As Byte
    SetStatus ("sending doors")
    Set Buffer = New clsBuffer

    DoorSize = LenB(Doors(DoorNum))
    ReDim DoorData(DoorSize - 1)
    CopyMemory DoorData(0), ByVal VarPtr(Doors(DoorNum)), DoorSize

    Buffer.WriteLong SUpdateDoors
    Buffer.WriteLong DoorNum
    Buffer.WriteBytes DoorData

    SendDataToAll Buffer.ToArray()
    Set Buffer = Nothing
End Sub

Sub SendUpdateDoorsTo(ByVal index As Long, ByVal DoorNum As Long)
    Dim packet As String
    Dim Buffer As clsBuffer
    Dim DoorSize As Long
    Dim DoorData() As Byte
    SetStatus ("sending doors")
    Set Buffer = New clsBuffer

    DoorSize = LenB(Doors(DoorNum))
    ReDim DoorData(DoorSize - 1)
    CopyMemory DoorData(0), ByVal VarPtr(Doors(DoorNum)), DoorSize

    Buffer.WriteLong SUpdateDoors
    Buffer.WriteLong DoorNum
    Buffer.WriteBytes DoorData

    SendDataTo index, Buffer.ToArray()
    Set Buffer = Nothing
End Sub

```

in modGeneral

find ' Check if the directory is there, if its not make it and add
```
ChkDir App.Path & "\Data\", "doors"

```
find "Public Sub ClearGameData()" and add
```
    Call SetStatus("Clearing Doors...")
    Call ClearDoors

```
find "Private Sub LoadGameData()" and add
```
    Call SetStatus("Loading Doors...")
    Call LoadDoors

```

In modPlayer

Find Sub JoinGame

add under ' Send some more little goodies, no need to explain these
```
Call SendDoors(index)

```
Link to comment
Share on other sites

  • Replies 83
  • Created
  • Last Reply

Top Posters In This Topic

Still in modPlayer

find "Sub PlayerMove"

at the top add
```
Dim DoorNum As Long

```
Find "Select Case Dir" and replace the entire thing with (IT'S LARGE)
```
Select Case Dir
        Case DIR_UP

            ' Check to make sure not outside of boundries
            If GetPlayerY(index) > 0 Then

                ' Check to make sure that the tile is walkable
                If Not isDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_UP + 1) Then
                    If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type <> TILE_TYPE_BLOCKED Then
                        If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type <> TILE_TYPE_RESOURCE Then
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type = TILE_TYPE_DOOR Then
                                    If Player(index).PlayerDoors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).state = 0 Then

                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).DoorType = 0 Then
                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).UnlockType = 0 Then
                                                    PlayerMsg index, "You need the right kind of key to open this door. (" & Trim$(Item(Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).key).Name) & ")", BrightRed
                                                ElseIf Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).UnlockType = 1 Then
                                                    PlayerMsg index, "You need to activate a switch to open this door. ", BrightRed
                                                Else
                                                    mapNum = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).WarpMap
                                                    x = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).WarpX
                                                    y = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).WarpY
                                                    Call PlayerWarp(index, mapNum, x, y)
                                                    Moved = YES
                                                End If
                                                End If

                                            PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                            Exit Sub
                                    Else
                                            If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Data1).DoorType = 1 Then
                                                PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                                Exit Sub
                                            End If
                                    End If
                                End If

                                ' Check to see if the tile is a key and if it is check if its opened
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type <> TILE_TYPE_KEY Or (Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) - 1).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(index)).DoorOpen(GetPlayerX(index), GetPlayerY(index) - 1) = YES) Then
                                    Call SetPlayerY(index, GetPlayerY(index) - 1)
                                    SendPlayerMove index, movement, sendToSelf
                                    Moved = YES
                                End If

                        End If
                    End If
                End If

            Else

                ' Check to see if we can move them to the another map
                If Map(GetPlayerMap(index)).Up > 0 Then
                    NewMapY = Map(Map(GetPlayerMap(index)).Up).MaxY
                    Call PlayerWarp(index, Map(GetPlayerMap(index)).Up, GetPlayerX(index), NewMapY)
                    Moved = YES
                    ' clear their target
                    TempPlayer(index).target = 0
                    TempPlayer(index).targetType = TARGET_TYPE_NONE
                    SendTarget index
                End If
            End If

        Case DIR_DOWN

            ' Check to make sure not outside of boundries
            If GetPlayerY(index) < Map(mapNum).MaxY Then

                ' Check to make sure that the tile is walkable
                If Not isDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_DOWN + 1) Then
                    If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type <> TILE_TYPE_BLOCKED Then
                        If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type <> TILE_TYPE_RESOURCE Then
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type = TILE_TYPE_DOOR Then
                                    If Player(index).PlayerDoors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).state = 0 Then

                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).DoorType = 0 Then
                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).UnlockType = 0 Then
                                                    PlayerMsg index, "You need the right kind of key to open this door. (" & Trim$(Item(Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).key).Name) & ")", BrightRed
                                                ElseIf Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).UnlockType = 1 Then
                                                    PlayerMsg index, "You need to activate a switch to open this door. ", BrightRed
                                                Else
                                                    mapNum = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).WarpMap
                                                    x = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).WarpX
                                                    y = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).WarpY
                                                    Call PlayerWarp(index, mapNum, x, y)
                                                    Moved = YES
                                                End If
                                                End If

                                            PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                            Exit Sub
                                    Else
                                            If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Data1).DoorType = 1 Then
                                                PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                                Exit Sub
                                            End If
                                    End If
                                End If

                                ' Check to see if the tile is a key and if it is check if its opened
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type <> TILE_TYPE_KEY Or (Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index) + 1).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(index)).DoorOpen(GetPlayerX(index), GetPlayerY(index) + 1) = YES) Then
                                    Call SetPlayerY(index, GetPlayerY(index) + 1)
                                    SendPlayerMove index, movement, sendToSelf
                                    Moved = YES
                                End If

                        End If
                    End If
                End If

            Else

                ' Check to see if we can move them to the another map
                If Map(GetPlayerMap(index)).Down > 0 Then
                    NewMapY = Map(Map(GetPlayerMap(index)).Down).MaxY
                    Call PlayerWarp(index, Map(GetPlayerMap(index)).Down, GetPlayerX(index), 0)
                    Moved = YES
                    ' clear their target
                    TempPlayer(index).target = 0
                    TempPlayer(index).targetType = TARGET_TYPE_NONE
                    SendTarget index
                End If
            End If

        Case DIR_LEFT

            ' Check to make sure not outside of boundries
            If GetPlayerX(index) > 0 Then

                ' Check to make sure that the tile is walkable
                If Not isDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_LEFT + 1) Then
                    If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type <> TILE_TYPE_BLOCKED Then
                        If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type <> TILE_TYPE_RESOURCE Then
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type = TILE_TYPE_DOOR Then
                                    If Player(index).PlayerDoors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).state = 0 Then

                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).DoorType = 0 Then
                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).UnlockType = 0 Then
                                                    PlayerMsg index, "You need the right kind of key to open this door. (" & Trim$(Item(Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).key).Name) & ")", BrightRed
                                                ElseIf Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).UnlockType = 1 Then
                                                    PlayerMsg index, "You need to activate a switch to open this door. ", BrightRed
                                                Else
                                                    mapNum = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).WarpMap
                                                    x = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).WarpX
                                                    y = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).WarpY
                                                    Call PlayerWarp(index, mapNum, x, y)
                                                    Moved = YES
                                                End If
                                                End If

                                            PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                            Exit Sub
                                    Else
                                            If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Data1).DoorType = 1 Then
                                                PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                                Exit Sub
                                            End If
                                    End If
                                End If

                                ' Check to see if the tile is a key and if it is check if its opened
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type <> TILE_TYPE_KEY Or (Map(GetPlayerMap(index)).Tile(GetPlayerX(index) - 1, GetPlayerY(index)).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(index)).DoorOpen(GetPlayerX(index) - 1, GetPlayerY(index)) = YES) Then
                                    Call SetPlayerX(index, GetPlayerX(index) - 1)
                                    SendPlayerMove index, movement, sendToSelf
                                    Moved = YES
                                End If

                        End If
                    End If
                End If

            Else

                ' Check to see if we can move them to the another map
                If Map(GetPlayerMap(index)).Left > 0 Then
                    NewMapX = Map(Map(GetPlayerMap(index)).Left).MaxX
                    Call PlayerWarp(index, Map(GetPlayerMap(index)).Left, NewMapX, GetPlayerY(index))
                    Moved = YES
                    ' clear their target
                    TempPlayer(index).target = 0
                    TempPlayer(index).targetType = TARGET_TYPE_NONE
                    SendTarget index
                End If
            End If

        Case DIR_RIGHT

            ' Check to make sure not outside of boundries
            If GetPlayerX(index) < Map(mapNum).MaxX Then

                ' Check to make sure that the tile is walkable
                If Not isDirBlocked(Map(GetPlayerMap(index)).Tile(GetPlayerX(index), GetPlayerY(index)).DirBlock, DIR_RIGHT + 1) Then
                    If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type <> TILE_TYPE_BLOCKED Then
                        If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type <> TILE_TYPE_RESOURCE Then
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type = TILE_TYPE_DOOR Then
                                    If Player(index).PlayerDoors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).state = 0 Then

                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).DoorType = 0 Then
                                                If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).UnlockType = 0 Then
                                                    PlayerMsg index, "You need the right kind of key to open this door. (" & Trim$(Item(Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).key).Name) & ")", BrightRed
                                                ElseIf Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).UnlockType = 1 Then
                                                    PlayerMsg index, "You need to activate a switch to open this door. ", BrightRed
                                                Else
                                                    mapNum = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).WarpMap
                                                    x = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).WarpX
                                                    y = Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).WarpY
                                                    Call PlayerWarp(index, mapNum, x, y)
                                                    Moved = YES
                                                End If
                                                End If

                                            PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                            Exit Sub
                                    Else
                                            If Doors(Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Data1).DoorType = 1 Then
                                                PlayerWarp index, GetPlayerMap(index), GetPlayerX(index), GetPlayerY(index)
                                                Exit Sub
                                            End If
                                    End If
                                End If

                                ' Check to see if the tile is a key and if it is check if its opened
                                If Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type <> TILE_TYPE_KEY Or (Map(GetPlayerMap(index)).Tile(GetPlayerX(index) + 1, GetPlayerY(index)).Type = TILE_TYPE_KEY And TempTile(GetPlayerMap(index)).DoorOpen(GetPlayerX(index) + 1, GetPlayerY(index)) = YES) Then
                                    Call SetPlayerX(index, GetPlayerX(index) + 1)
                                    SendPlayerMove index, movement, sendToSelf
                                    Moved = YES
                                End If

                        End If
                    End If
                End If

            Else

                ' Check to see if we can move them to the another map
                If Map(GetPlayerMap(index)).Right > 0 Then
                    NewMapX = Map(Map(GetPlayerMap(index)).Right).MaxX
                    Call PlayerWarp(index, Map(GetPlayerMap(index)).Right, 0, GetPlayerY(index))
                    Moved = YES
                    ' clear their target
                    TempPlayer(index).target = 0
                    TempPlayer(index).targetType = TARGET_TYPE_NONE
                    SendTarget index
                End If
            End If

    End Select

```
and also in Sub PlayerMove Find "If .Type = TILE_TYPE_DOOR Then" and replace It with

```
' Check to see if the tile is a door tile
        If .Type = TILE_TYPE_DOOR Then
            DoorNum = .Data1

            If Player(index).PlayerDoors(DoorNum).state = 1 Then
                mapNum = Doors(DoorNum).WarpMap
                x = Doors(DoorNum).WarpX
                y = Doors(DoorNum).WarpY
                Call PlayerWarp(index, mapNum, x, y)
                Moved = YES
            End If

        End If

```

At the bottom of modPlayer add
```
Sub CheckDoor(ByVal index As Long, ByVal x As Long, ByVal y As Long)
    Dim Door_num As Long
    Dim i As Long
    Dim n As Long
    Dim key As Long
    Dim tmpIndex As Long

    If Map(GetPlayerMap(index)).Tile(x, y).Type = TILE_TYPE_DOOR Then
        Door_num = Map(GetPlayerMap(index)).Tile(x, y).Data1

        If Door_num > 0 Then
            If Doors(Door_num).DoorType = 0 Then
                If Player(index).PlayerDoors(Door_num).state = 0 Then
                    If Doors(Door_num).UnlockType = 0 Then
                        For i = 1 To MAX_INV
                            key = GetPlayerInvItemNum(index, i)
                            If Doors(Door_num).key = key Then
                                TakeInvItem index, key, 1
                                If TempPlayer(index).inParty > 0 Then
                                    For n = 1 To MAX_PARTY_MEMBERS
                                        tmpIndex = Party(TempPlayer(index).inParty).Member(n)
                                        If tmpIndex > 0 Then
                                            Player(tmpIndex).PlayerDoors(Door_num).state = 1
                                            SendPlayerData (tmpIndex)
                                            If index <> tmpIndex Then
                                                PlayerMsg tmpIndex, "A member of your party unlocked a door.", BrightBlue
                                            Else
                                                PlayerMsg tmpIndex, "You used a key to unlock the door.", BrightBlue
                                            End If
                                        End If
                                    Next

                                Else
                                    Player(index).PlayerDoors(Door_num).state = 1
                                    PlayerMsg index, "You used a key to unlock the door.", BrightBlue
                                    SendPlayerData (index)
                                End If
                                Exit Sub
                            End If
                        Next
                        PlayerMsg index, "You do not have the right key to unlock the door.", BrightBlue
                    ElseIf Doors(Door_num).UnlockType = 1 Then
                        If Doors(Door_num).state = 0 Then
                            PlayerMsg index, "You have not fliped the right switch to unlock this door.", BrightBlue
                        End If
                    ElseIf Doors(Door_num).UnlockType = 2 Then
                        PlayerMsg index, "This door has no lock.", BrightBlue
                    End If

                Else
                    PlayerMsg index, "This door is already unlocked.", BrightBlue
                End If
            ElseIf Doors(Door_num).DoorType = 1 Then
                If Player(index).PlayerDoors(Door_num).state = 0 Then
                                If TempPlayer(index).inParty > 0 Then
                                    For n = 1 To MAX_PARTY_MEMBERS
                                        tmpIndex = Party(TempPlayer(index).inParty).Member(n)
                                        If tmpIndex > 0 Then
                                            Player(tmpIndex).PlayerDoors(Door_num).state = 1
                                            Player(tmpIndex).PlayerDoors(Doors(Door_num).Switch).state = 1
                                            SendPlayerData (tmpIndex)
                                            If index <> tmpIndex Then
                                                PlayerMsg tmpIndex, "A member of your party filped a switch on and unlocked a door.", BrightBlue
                                            Else
                                                PlayerMsg tmpIndex, "You filp the switch on and unlocked a door.", BrightBlue
                                            End If
                                        End If
                                    Next
                                Else
                                    Player(index).PlayerDoors(Door_num).state = 1
                                    Player(index).PlayerDoors(Doors(Door_num).Switch).state = 1
                                    PlayerMsg index, "You filp the switch on and unlocked a door.", BrightBlue
                                    SendPlayerData (index)
                                End If

                Else
                                If TempPlayer(index).inParty > 0 Then
                                    For n = 1 To MAX_PARTY_MEMBERS
                                        tmpIndex = Party(TempPlayer(index).inParty).Member(n)
                                        If tmpIndex > 0 Then
                                            Player(tmpIndex).PlayerDoors(Door_num).state = 0
                                            Player(tmpIndex).PlayerDoors(Doors(Door_num).Switch).state = 0
                                            SendPlayerData (tmpIndex)
                                            If index <> tmpIndex Then
                                                PlayerMsg tmpIndex, "A member of your party filped a switch off and locked a door.", BrightBlue
                                            Else
                                                PlayerMsg tmpIndex, "You filp the switch off and locked a door.", BrightBlue
                                            End If
                                        End If
                                    Next
                                Else
                                    Player(index).PlayerDoors(Door_num).state = 0
                                    Player(index).PlayerDoors(Doors(Door_num).Switch).state = 0
                                    PlayerMsg index, "You filp the switch off and locked a door.", BrightBlue
                                    SendPlayerData (index)
                                End If
                End If
            End If
        End If
    End If
End Sub

```
Link to comment
Share on other sites

**CLIENT**

Add the attached door and switch editor to your client project.

http://heroofathea.com/Downloads/frmEditor_Doors.frm

In modClientTCP at the bottom add

```

Public Sub SendSavedoor(ByVal DoorNum As Long)

Dim Buffer As clsBuffer

Dim DoorSize As Long

Dim DoorData() As Byte

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

DoorSize = LenB(Doors(DoorNum))

ReDim DoorData(DoorSize - 1)

CopyMemory DoorData(0), ByVal VarPtr(Doors(DoorNum)), DoorSize

Buffer.WriteLong CSaveDoor

Buffer.WriteLong DoorNum

Buffer.WriteBytes DoorData

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "SendSavedoor", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Sub SendRequestDoors()

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CRequestDoors

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "SendRequestDoors", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Public Sub SendRequestEditdoors()

Dim Buffer As clsBuffer

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteLong CRequestEditDoors

SendData Buffer.ToArray()

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "SendRequestEditdoors", "modClientTCP", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

In modDatabase at the bottom add

```

Sub ClearDoor(ByVal Index As Long)

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Call ZeroMemory(ByVal VarPtr(Doors(Index)), LenB(Doors(Index)))

Doors(Index).Name = vbNullString

' Error handler

Exit Sub

errorhandler:

HandleError "ClearDoor", "modDatabase", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

Sub ClearDoors()

Dim i As Long

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

For i = 1 To MAX_DOORS

Call ClearDoor(i)

Next

' Error handler

Exit Sub

errorhandler:

HandleError "ClearDoors", "modDatabase", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

In modGameEditors

find "Public Sub MapEditorMouseDown"

In "Public Sub MapEditorMouseDown" find "If frmEditor_Map.optDoor.Value Then" and replace with

```

' door

If frmEditor_Map.optDoor.Value Then

.Type = TILE_TYPE_DOOR

.Data1 = DoorEditorNum

.Data2 = 0

.Data3 = 0

End If

```

at the bottom of modGameEditors add

```

'/////////

'//DOORS//

'/////////

Public Sub DoorEditorInit()

If frmEditor_Doors.Visible = False Then Exit Sub

EditorIndex = frmEditor_Doors.lstIndex.ListIndex + 1

With frmEditor_Doors

.txtName.text = Doors(EditorIndex).Name

If Doors(EditorIndex).DoorType = 0 Then

.optDoor(0).Value = True

Else

.optDoor(1).Value = True

End If

.scrlKey.Value = Doors(EditorIndex).key

.scrlSwitch.Value = Doors(EditorIndex).Switch

.scrlMap.Value = Doors(EditorIndex).WarpMap

.scrlX.Value = Doors(EditorIndex).WarpX

.scrlY.Value = Doors(EditorIndex).WarpY

If Doors(EditorIndex).UnlockType = 0 Then

.OptUnlock(0).Value = True

ElseIf Doors(EditorIndex).UnlockType = 1 Then

.OptUnlock(1).Value = True

Else

.OptUnlock(2).Value = True

End If

End With

Door_Changed(EditorIndex) = True

End Sub

Public Sub DoorEditorOk()

Dim i As Long

For i = 1 To MAX_DOORS

If Door_Changed(i) Then

Call SendSavedoor(i)

End If

Next

Unload frmEditor_Doors

Editor = 0

ClearChanged_Doors

End Sub

Public Sub DoorEditorCancel()

Editor = 0

Unload frmEditor_Doors

ClearChanged_Doors

ClearDoors

SendRequestDoors

End Sub

Public Sub ClearChanged_Doors()

ZeroMemory Door_Changed(1), MAX_DOORS * 2 ' 2 = boolean length

End Sub

```

In modGlobals

Add anywhere to modGlobals

```

'map doors

Public DoorEditorNum As Long

```

find ' Editor edited items array and add

```

Public Door_Changed(1 To MAX_DOORS) As Boolean

```

In modHandleData add to the Top in InitMessages()

```

HandleDataSub(SDoorsEditor) = GetAddress(AddressOf HandleDoorsEditor)

HandleDataSub(SUpdateDoors) = GetAddress(AddressOf HandleUpdateDoors)

```

In modHandleData add to the Bottom

```

Private Sub HandleDoorsEditor()

Dim i As Long

With frmEditor_Doors

Editor = EDITOR_DOORS

.lstIndex.Clear

' Add the names

For i = 1 To MAX_DOORS

.lstIndex.AddItem i & ": " & Trim$(Doors(i).Name)

Next

.Show

.lstIndex.ListIndex = 0

DoorEditorInit

End With

End Sub

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

Dim DoorNum As Long

Dim Buffer As clsBuffer

Dim DoorSize As Long

Dim DoorData() As Byte

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

Set Buffer = New clsBuffer

Buffer.WriteBytes Data()

DoorNum = Buffer.ReadLong

DoorSize = LenB(Doors(DoorNum))

ReDim DoorData(DoorSize - 1)

DoorData = Buffer.ReadBytes(DoorSize)

ClearDoor DoorNum

CopyMemory ByVal VarPtr(Doors(DoorNum)), ByVal VarPtr(DoorData(0)), DoorSize

Set Buffer = Nothing

' Error handler

Exit Sub

errorhandler:

HandleError "HandleUpdateDoors", "modHandleData", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

**FORM WORK/CODING**

frmEditor_Map

Enable the Door attrb.

Now double click on the door attrb and replace the code with

```

Private Sub optDoor_Click()

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

ClearAttributeDialogue

picAttributes.Visible = True

fradoor.Visible = True

' Error handler

Exit Sub

errorhandler:

HandleError "optDoor_Click", "frmEditor_Map", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

End Sub

```

Now make a new Frame like shown

![](http://www.mediafire.com/imgbnc.php/548f2518f1272635d96bc42c8a69b94b1b6855bf7baa4351110bfd42161c06ae6g.jpg)

Name each of the parts as follows

Frame = fradoor

Label = lblDoor

Hscroll = scrlDoor

Command Button = cmdDoor

Set the frame visible to off in the properties

Doubble click on the scrldoor and add

```

If scrlDoor.Value > 0 Then

lblDoor.Caption = "Door/Switch: " & Doors(scrlDoor.Value).Name

Else

lblDoor.Caption = "Door/Switch: None"

End If

```

double click on the cmbDoor and add

```

DoorEditorNum = scrlDoor.Value

picAttributes.Visible = False

fradoor.Visible = False

```

on frmMain stretch the right side a bit and you will find the admin pannel make a new Button

double click it and add

```

' If debug mode, handle error then exit out

If Options.Debug = 1 Then On Error GoTo errorhandler

If GetPlayerAccess(MyIndex) < ADMIN_DEVELOPER Then

Exit Sub

End If

SendRequestEditdoors

' Error handler

Exit Sub

errorhandler:

HandleError "cmdAItem_Click", "frmMain", Err.Number, Err.Description, Err.Source, Err.HelpContext

Err.Clear

Exit Sub

```

And dont forget to move the edge of your screen Back to normal.

**CREDIT PLEASE**
Link to comment
Share on other sites

Well, it's been a couple days… and I haven't heard a report from my number one fan one if the code works right or not... He said he was gona test it out.

Justn, did you die from the epicness of the feature, of die from its horrible crashing? (not that i'm saying this thing crashes, because it dosnt.... for me at least)

DAMN IT XD some feed back would be nice.. >.< sotvotkong, your tried it too, didn't you? any luck?
Link to comment
Share on other sites

Just didnt want to speak too soon but I been playing around with it for an hour or so made like 20 doors and guess what…. They all work!! Entering a door from any direction works switches and keys work (keys were messing up on me in your old one) this is great! Only thing i havent tested out is opening a door while in a party but im sure it works. Thanks alot man glad you took time to rewrite this, it was a must have for my project im working on!! Will let you know if i run into any problems but I doubt I will
:star: :star: :star: :star: :star:
Link to comment
Share on other sites

well i didnt really have errors to begin with, but the new code seems to work fine for me, i just redid the center section of this tut on top of the old one.  so for what its worth it works great.  as for errors i personally didnt find any.  but that doesnt mean those that had errors before could grasp this one.
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
I didn't want to try and sort out a 1/2 finished system made by Robin, I had no Idea the direction it was going. As far as I can tell he left no room for the state of the door, just where it warped to.

And I made an editor for this version because I gave it a slightly more advanced options for what you can do with the doors rather than just use a key on them.

If you don't like it fix Robin's doors yourself.
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...