Vilmen Posted October 24, 2011 Author Share Posted October 24, 2011 **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 MovementPublic Sub CharMove(ByVal X As Single, ByVal Y As Single)'Finds the heading way with our mouse positionDim iScrX As IntegerDim iScrY As IntegerDim lAngle As LongiScrX = X - frmMain.picScreen.Left - (frmMain.picScreen.width / 2)iScrY = Y - frmMain.picScreen.top - (frmMain.picScreen.height / 2)iScrY = -iScrYIf iScrY = 0 Then lAngle = 0Else lAngle = Atn(iScrX / iScrY) * 180 / 3.14159265End IfIf (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 IfElseIf (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 IfEnd IfEnd 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 IfEnd 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 = XtempMouseY = 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 LongPublic yMouseMovement As LongPublic tempMouseX As LongPublic 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 SubEnd 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#newIn 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 = NothingEnd 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 LongPublic yMouseMovement As LongPublic tempMouseX As LongPublic 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 More sharing options...
Sealbreaker Posted October 24, 2011 Share Posted October 24, 2011 But why would you want that? doesn't that even cause unwanted movements when targeting etc. ???-seal Link to comment Share on other sites More sharing options...
Vilmen Posted October 24, 2011 Author Share Posted October 24, 2011 I updated the tutorial so you dont move if you press on a target. And why would you want mouse movement in a rpg game? Well thats up to you, i however like it in rpgs. Link to comment Share on other sites More sharing options...
RyokuHasu Posted October 24, 2011 Share Posted October 24, 2011 there is a better tutorial that uses path finding with mouse movement. ;P i dont the see the need for this one… (even with lightning's "some people might find it useful") Link to comment Share on other sites More sharing options...
Vilmen Posted October 24, 2011 Author Share Posted October 24, 2011 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 More sharing options...
Kemerd Posted October 24, 2011 Share Posted October 24, 2011 For the next update in this tutorial. Make an option in-game button to enable and disable this. A programmer could easily do this himself, But for the people who can't, I advise adding that to your tutorial. Link to comment Share on other sites More sharing options...
Vilmen Posted October 25, 2011 Author Share Posted October 25, 2011 Not sure if I want to spend much more time on this thing. But I can make a short simple Addon for that.Done, Addon added to first post. Link to comment Share on other sites More sharing options...
Annahstas Posted October 28, 2011 Share Posted October 28, 2011 Nice I really like this. When I get back ima try this out and see if I can add this in. Thanks ^^ Link to comment Share on other sites More sharing options...
Charles-Z Posted November 10, 2011 Share Posted November 10, 2011 uhhhmmm . . how do you use this in the game? Link to comment Share on other sites More sharing options...
Lee Evermore Posted April 20, 2012 Share Posted April 20, 2012 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? Link to comment Share on other sites More sharing options...
Guest Posted April 20, 2012 Share Posted April 20, 2012 @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 More sharing options...
Vilmen Posted May 18, 2012 Author Share Posted May 18, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now