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

[EO 2.0] Advanced Doors, Keys, and Switches V3.0


RyokuHasu
 Share

Recommended Posts

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

**Part 2**

**CLIENT**

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

[http://www.touchofdeathforums.com/smf/index.php?action=dlattach;topic=73764.0;attach=18927](http://www.touchofdeathforums.com/smf/index.php?action=dlattach;topic=73764.0;attach=18927)

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.
![](http://www.touchofdeathforums.com/smf/index.php?action=dlattach;topic=73764.0;attach=19171)

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
![](http://www.touchofdeathforums.com/smf/index.php?action=dlattach;topic=73764.0;attach=18970)

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

Ok the movement calc was very dificult for such a complex tile, but it's done.

Tutorial updated. See section on modPlayer to fix player movement.

Next update: Doors for parties… (when i feel like it)

OH MY GAWD >.< my tut was sooo long after the update that it overflowed the post limit on characters and cut off my last chunck of code....Its fixed now. Please, no one blame me if I make another topic for more updates.
Link to comment
Share on other sites

@Mïlk:

> To do the party thing, just find instances of
>
> ```
> Player(index).PlayerDoors(Door_num).state =
> ```
> and make it check if the player is in a party, if so do the same for the rest of the group.

Not Quite. Ill be making the party doors so that the rest of the party only gets the unlocked effect when the door gets unlocked.

The way you say it will cause wide spread "door-Sharing" witch if one member of the party leaves and joins another party then he transfers the unlocked door to every one in the new party.
Link to comment
Share on other sites

Exactly! thats how I want it. That player already did the work, BUT none of the other players did, why should they leach his door state … and guess what its done! =D

(Its to way too much to add to the original post since I already hit the max character count x.x)

To add Party doors just replace Sub CheckDoor with
```
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)
                                        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
                                    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
                        key = Doors(Door_num).Switch
                        If Doors(key).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)
                                        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
                                    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)
                                        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
                                    Next
                                Else
                                    Player(index).PlayerDoors(Door_num).state = 1
                                    Player(index).PlayerDoors(Doors(Door_num).Switch).state = 1
                                    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

Has anyone added this to their project yet? I'm getting a compile error on both server side and client side and was wondering if it was just me…

SERVER
getting variable not defined in modplayer

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

CLIENT
getting variable not defined on my cmdDoor

>! Private Sub cmdDoor_Click()
    **DoorEditorNum** = scrlDoor.Value
    picAttributes.Visible = False
    fraDoor.Visible = False

End Sub
Link to comment
Share on other sites

@Piernik:

> Justn, give this code to this sub:
>
> Dim DoorNum as long
> Dim DoorEditorNum as long

No. one of those was sposed to be a global.

@Justn:

> Has anyone added this to their project yet? I'm getting a compile error on both server side and client side and was wondering if it was just me…
>
> -code-

you are right XD i added the wrong Thing to the Globals

Client

Add anywhere to modGlobals
```
'map doors
Public DoorEditorNum As Long

```
server

In modPlayer at the top of sub PlayerMove add
```
Dim DoorNum As Long

```

* * *

Thanks for the info. It was a lot of data to keep track of, I knew i forgot somthing. The tut is updated.

Just feed me any more errors and ill patch them up =P
Link to comment
Share on other sites

Whoops XD ummmm… one sec... >.< I forgot that part.

Just give me 3 min.

* * *

DONE

Sorry, In the big Tuts is always the small things that get left out.

on frmMain stretch the right side a bit and you will find the admin pannel make a new Button
![](http://www.mediafire.com/imgbnc.php/a3e68d3b7411246fdbc64375f97bc53c427f9f71b1eaf11aa2d1e602838524ca6g.jpg)

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.
Link to comment
Share on other sites

HOLY CRAP >.< I forgot the Inti Messages

In modHandleData

Client
```
HandleDataSub(SDoorsEditor) = GetAddress(AddressOf HandleDoorsEditor)
    HandleDataSub(SUpdateDoors) = GetAddress(AddressOf HandleUpdateDoors)

```
Server
```
    HandleDataSub(CSaveDoor) = GetAddress(AddressOf HandleSaveDoor)
    HandleDataSub(CRequestDoors) = GetAddress(AddressOf HandleRequestDoors)
    HandleDataSub(CRequestEditDoors) = GetAddress(AddressOf HandleEditDoors)

```
TUT UPDATED!!! x.x lol now i feel like a jack ass…
Link to comment
Share on other sites

@Azure:

> It's the only one because this is one of those things best programmed in instances where it's needed and then reuesed later if need be.

Thats not entirely true. =P doors like this are kinda hard to make from scratch. Doors in my opinion are really good for making dungeons and such, it adds that standard bit of Puzzling that RPGs kinda need.

* * *

@Jimmy:

> great tutorial. All the bugs are fixed?

Yep! Just grab the editor and add everything.
Link to comment
Share on other sites

Oh Im sorry, do you have a better door system?

If you do, take pride in it then leave.

If you don't, Take mine and say "thank you".

its just a tut, a long and complex one, but still just a TuT, nothing to bash.

Also im not saying WOOHOo generic!  Of course people still have to make some custom features for them selves.
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...