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

Mouse Movement V2


Vilmen
 Share

Recommended Posts

**Introduction**
This is something old I once did. If you look at this screenshot you can see that it has 4 triangles. Depending on in which you press the character will walk that way.

Update 1: Fixed so you dont move if you press a target.
Update 2: Option to disable mouse movement.

![](http://www.key2heaven.com/screenshots/ec1.png)
**Client Side**
At the botto of modGameLogic, add:
```
' Mouse Movement
Public Sub CharMove(ByVal X As Single, ByVal Y As Single)
'Finds the heading way with our mouse position
Dim iScrX As Integer
Dim iScrY As Integer
Dim lAngle As Long

iScrX = X - frmMain.picScreen.Left - (frmMain.picScreen.width / 2)
iScrY = Y - frmMain.picScreen.top - (frmMain.picScreen.height / 2)

iScrY = -iScrY
If iScrY = 0 Then
    lAngle = 0
Else
    lAngle = Atn(iScrX / iScrY) * 180 / 3.14159265
End If

If (lAngle >= -45 And lAngle <= 0) Or (lAngle <= 45 And lAngle >= 0) Then
    If iScrY > 0 Then
        DirUp = True
        DirDown = False
        DirLeft = False
        DirRight = False
        If CanMove = True Then
            Call SetPlayerDir(MyIndex, DIR_UP)
            Call CheckMovement
        End If
    Else
        DirUp = False
        DirDown = True
        DirLeft = False
        DirRight = False
        If CanMove = True Then
            Call SetPlayerDir(MyIndex, DIR_DOWN)
            Call CheckMovement
        End If
    End If
ElseIf (lAngle > 45 And lAngle <= 90) Or (lAngle < -45 And lAngle >= -90) Then
    If iScrX < 0 Then
                DirUp = False
        DirDown = False
        DirLeft = True
        DirRight = False
        If CanMove = True Then
            Call SetPlayerDir(MyIndex, DIR_LEFT)
            Call CheckMovement
        End If
    Else
        DirUp = False
        DirDown = False
        DirLeft = False
        DirRight = True
        If CanMove = True Then
            Call SetPlayerDir(MyIndex, DIR_RIGHT)
            Call CheckMovement
        End If
    End If
End If
End Sub
```
In frmMain, add:
```
Private Sub picScreen_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not InMapEditor Then
        xMouseMovement = 0
        yMouseMovement = 0
    End If
End Sub
```
In frmMain, inside the sub picScreen_MouseDown. Find this:
```
If InMapEditor Then
        Call MapEditorMouseDown(Button, X, Y, False)
    Else
        ' left click
        If Button = vbLeftButton Then
```Below that, add:
```
tempMouseX = X
tempMouseY = Y
```
In modGameLogic, find this:
```
' Process input before rendering, otherwise input will be behind by 1 frame
        If WalkTimer < Tick Then

            For i = 1 To Player_HighIndex
                If IsPlaying(i) Then
                    Call ProcessMovement(i)
                End If
            Next i

            ' Process npc movements (actually move them)
            For i = 1 To Npc_HighIndex
                If Map.Npc(i) > 0 Then
                    Call ProcessNpcMovement(i)
                End If
            Next i

            WalkTimer = Tick + 30 ' edit this value to change WalkTimer
        End If
```Below that, add:
```
If xMouseMovement > 0 And yMouseMovement > 0 Then
            Call CharMove(xMouseMovement, yMouseMovement)
        End If
```Add this in any module:
```
Public xMouseMovement As Long
Public yMouseMovement As Long
Public tempMouseX As Long
Public tempMouseY As Long
```
At the bottom of modHandleData, add:
```
Private Sub HandleMouseMovement(ByVal Index As Long, ByRef Data() As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
    xMouseMovement = tempMouseX
    yMouseMovement = tempMouseY
    Exit Sub
End Sub
```
In sub InitMessages, at the bottom of that list, add:
```
HandleDataSub(SMouseMovement) = GetAddress(AddressOf HandleMouseMovement)
```
In Public Enum ServerPackets, at the bottom of that list, add:
```
SMouseMovement
```
**Server Side**
In Sub HandleSearch, just before the End Sub, add:
```
Call SendMouseMovement(index)
```
While you are in that Sub, you might want to fix this: http://www.touchofdeathforums.com/smf/index.php/topic,75973.new.html#new

In the bottom of modServerTCP, add:
```
Sub SendMouseMovement(ByVal index As Long)
Dim Buffer As clsBuffer, i As Long

    Set Buffer = New clsBuffer
    Buffer.WriteLong SMouseMovement
    Buffer.WriteLong index

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

```Find Public Enum ServerPackets, in the bottom of that list, add:
```
SMouseMovement
```
**Addon**
Do this if you want a option to disable mouse movement.

Go to frmMain, press on picParty and move it to the side. Now press on the next black thing called picSpells and move that to the side also. Now you see the picOptions. First press on the Sound label, copy it and paste it. Dont create a array. Move it below the sound optionbuttons and name it Mouse Movement. Now the 2 optionbuttons for Sound is located in a picturebox called Picture4\. It could be tricky to press on that cause everything is black. But find it, copy it and paste it. 3 messages will appear, dont create any arrays. Change the Name on the 2 buttons to optMMOn and optMMOff. Set the "On Optionbutton" value to true. Now double click on the "On" button, and add this:
```
MouseMovementDisabled = False
```Now press the off button and add this:
```
MouseMovementDisabled = True
```Now, on the place you put:
```
Public xMouseMovement As Long
Public yMouseMovement As Long
Public tempMouseX As Long
Public tempMouseY As Long
```Just below that add:
```
Public MouseMovementDisabled as Boolean
```Now search for:
```
If xMouseMovement > 0 And yMouseMovement > 0 Then
            Call CharMove(xMouseMovement, yMouseMovement)
        End If
```Replace that with:
```
If xMouseMovement > 0 And yMouseMovement > 0 Then
            If MouseMovementDisabled = False Then
                Call CharMove(xMouseMovement, yMouseMovement)
            End If
        End If
```
Now you might want it to save each time the player logs in. Well, I'm not gonna do that unless its actually requested.

Finished, you should now have a working mouse movement in your game.
Link to comment
Share on other sites

Mouse movement with pathfinding is a totally different feature. If you have scrolling maps. And your player is always centered. I would prefer this system way more. Pathfinding in a game where you are centered is kinda weird imo.
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...
@Lee:

> ive followed through this, even did the update to my code involving the "end sub / end if"… but when my character clicks on the screen to move, then the game client closes with no reasons as to why... any suggestions for me?

Open the game in VB6 and try there then  tell the text wich appear in highlight or  the error
Link to comment
Share on other sites

  • 4 weeks later...
I tested the code again in a vanilla eclipse source and it worked. Just redo it and make sure you follow each step correctly. I didnt add the addon or my bug fix due to lazyness, but they should also work just fine.
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...