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

EO - WASD Movement


Rob Janes
 Share

Recommended Posts

Some people have been wondering how to add WASD movement to EO.  It's not that difficult to do; the 'easiest' way to do it, uses a Boolean that is set to either True or False depending on if the player has clicked on the Map (Enabled WASD) or if they have clicked on the chat area (Disabling WASD). 

Enjoy another Tutorial!

All changes are done via the Client!

Step 1\. In modGeneral, Sub SetFocusOnChat, comment out the part where it sets focus on txtMyChat.
```
'frmMain.txtMyChat.SetFocus
```
Step 2\. We need to add a Boolean (True/False) to see if we are typing a message or moving. In modGlobals Add.
```
'Are We Talking or Moving?
Public ChatFocus As Boolean
```
Step 3\. On frmMain, picScreen's MouseDown event, we want to set this flag (ChatFocus) as False, we're going to add it in right after where it says SetFocusonChat. Like so
```
Call SetFocusOnChat
ChatFocus = False
```
Step 4\. On frmMain, txtMyChat, use the drop down at the top right and select 'click'.  There isn't anything in it's 'Click' event right now, only the 'Change' event.  What we need to do is set the ChatFocus flag to 'True' if they 'Click' on the textbox. Add this to txtMyChat's Click Event.
```
ChatFocus = True
```

Step 5\. Now we are going to add the movement in, so in modInput, sub CheckInputKeys, Just after it checks the Arrow Keys, so at the 'end' of CheckInputKeys, add
```
'If we aren't focused on the chat, let's see if we use W/A/S/D to move
    If ChatFocus = False Then
        'Move Up (W)
        If GetKeyState(vbKeyW) < 0 Then
            DirUp = True
            DirDown = False
            DirLeft = False
            DirRight = False
            Exit Sub
        Else
            DirUp = False
        End If

        'Move Right (D)
        If GetKeyState(vbKeyD) < 0 Then
            DirUp = False
            DirDown = False
            DirLeft = False
            DirRight = True
            Exit Sub
        Else
            DirRight = False
        End If

        'Move down (S)
        If GetKeyState(vbKeyS) < 0 Then
            DirUp = False
            DirDown = True
            DirLeft = False
            DirRight = False
            Exit Sub
        Else
            DirDown = False
        End If

        'Move left (A)
        If GetKeyState(vbKeyA) < 0 Then
            DirUp = False
            DirDown = False
            DirLeft = True
            DirRight = False
            Exit Sub
        Else
            DirLeft = False
        End If

    End If
```
Step 6\. Now we just want to simply set the default's so in modGeneral, under the GameInit sub, just after it does Call SetFocusOnChat, add
```
'By Default, we automatically want to Target the Chat Window so players can chat
    'You could choose to set this flag as false if you wanted to
    ChatFocus = True
    frmMain.txtMyChat.SetFocus
```

Hope you all enjoy!  This was built on a clean EO 1.3.1 build!

Feel free to request more tutorials!
Link to comment
Share on other sites

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

Sounds like you are clicking on the RichTextBox (txtChat) where messages are written, try clicking on the txtMyChat box, the smaller one where you would write messages.  Make sure you added the flag to the txtMyChat.

An easy fix to your issue would be on the txtChat Click event, add
```
ChatFocus=True
txtMyChat.setFocus
```
Link to comment
Share on other sites

I would personally use the return key to set focus on the chat box, then when a message is entered, the return key of course sends the message and it loses focus again. Having to use the mouse constantly to type would probably be irritating.
Link to comment
Share on other sites

@Päïñ:

> @Boko, that's what mine is using ;D, great minds think alike!
>
> Regards,
> Païn

Well I play WoW so I'm use to it :P

For those interested in the return key toggle chat method, here's the code:
(Full Client Side, it's not too different to the OP's method)
**(Updated with fix from 2nd page)**
**In modGlobals:**
_Add:_
```
' Chat Focus
Public ChatFocus As Boolean
Public KeyDown As Boolean
```
**In modGeneral:**
_Replace entire_ **Public Sub SetFocusOnChat** _with:_
```
Public Sub SetFocusOnChat()
    On Error Resume Next 'prevent RTE5, no way to handle error
    If ChatFocus = False Then
        ChatFocus = True
        frmMain.txtMyChat.SetFocus
    ElseIf ChatFocus = True Then
        ChatFocus = False
        frmMain.picScreen.SetFocus
    End If
End Sub
```
**In modGeneral:**
_In_ **Sub GameInit**_, just before_ **Call SetFocusOnChat**_, Add:_
```
ChatFocus = True ' Default to screen focus
```_Also, move the following above the_ **Call SetFocusChat** _instead of below it (because it's not possible to set focus on picScreen if it's not visible yet)_
```
frmMain.picScreen.Visible = True
```
**In modInput:**
_Replace:_
```
If GetKeyState(vbKeyReturn) < 0 Then
        CheckMapGetItem
End If
```_With: (Replace_ **NEWKEY** _with which ever key you'd prefer to have for picking up items)_
_(If you're going the route of WASD movement, a key like Q wouldn't be a bad choice, replace with_ **vbKeyQ** _for example)_
```
If GetKeyState(vbKeyNEWKEY) < 0 Then
        CheckMapGetItem
End If
```
_Just under or above that add:_
```
If GetKeyState(vbKeyReturn) < 0 And KeyDown = False Then
        KeyDown = True
    ElseIf Not GetKeyState(vbKeyReturn) < 0 And KeyDown = True Then
        KeyDown = False
        Call SetFocusOnChat
    End If
```
You may now also add OP's WASD movement config to this **modInput** _file._
_But I recommend just adding Or statements to the arrow key ones instead of making new individual statements, for example:_
_Replace:_
```
If GetKeyState(vbKeyUp) < 0 Then
```_With:_
```
If GetKeyState(vbKeyUp) < 0 Or GetKeyState(vbKeyW) < 0 Then
```
_You will still need the_ **ChatFocus** _if statement around them to ensure you're not moving when typing w/a/s/d.
You may also prefer to wrap it around all the key presses to ensure when you're typing, you're only typing. (If you were to attempt to paste something in to the chat for example and you're standing next to someone, you're going to end up accidentally hitting them by the control key press.)_

**Optional Step:**

**In frmMain (Code):**
_In_ **Private Sub picScreen_MouseDown** _Remove/Comment:_
```
Call SetFocusOnChat
```_(This causes the return key to be the only method of switching focus, but it's not required.. personally preference)_

I might be forgetting something, I patched this up in just a couple minutes by looking at OP's code.
Link to comment
Share on other sites

@Boko:

> Well I play WoW so I'm use to it :P
>
> For those interested in the return key toggle chat method, here's the code:
> (Full Client Side, it's not too different to the OP's method)
> **In modGlobals:**
> _Add:_
> ```
> ' Chat Focus
> Public ChatFocus As Boolean
> ```
> **In modGeneral:**
> _Replace entire_ **Public Sub SetFocusOnChat** _with:_
> ```
> Public Sub SetFocusOnChat()
>     On Error Resume Next 'prevent RTE5, no way to handle error
>     If ChatFocus = False Then
>         ChatFocus = True
>         frmMain.txtMyChat.SetFocus
>     ElseIf ChatFocus = True Then
>         ChatFocus = False
>         frmMain.picScreen.SetFocus
>     End If
> End Sub
> ```
> **In modGeneral:**
> _In_ **Sub GameInit**_, just before_ **Call SetFocusOnChat**_, Add:_
> ```
> ChatFocus = True ' Default to screen focus
> ```_Also, move the following above the_ **Call SetFocusChat** _instead of below it (because it's not possible to set focus on picScreen if it's not visible yet)_
> ```
> frmMain.picScreen.Visible = True
> ```
> **In modInput:**
> _Replace:_
> ```
> If GetKeyState(vbKeyReturn) < 0 Then
>         CheckMapGetItem
> End If
> ```_With: (Replace_ **NEWKEY** _with which ever key you'd prefer to have for picking up items)_
> _(If you're going the route of WASD movement, a key like Q wouldn't be a bad choice, replace with_ **vbKeyQ** _for example)_
> ```
> If GetKeyState(vbKeyNEWKEY) < 0 Then
>         CheckMapGetItem
> End If
> ```
> _Just under or above that add:_
> ```
> If GetKeyState(vbKeyReturn) < 0 Then
>         Call SetFocusOnChat
> End If
> ```
> You may now also add OP's WASD movement config to this **modInput** _file._
> _But I recommend just adding Or statements to the arrow key ones instead of making new individual statements, for example:_
> _Replace:_
> ```
> If GetKeyState(vbKeyUp) < 0 Then
> ```_With:_
> ```
> If GetKeyState(vbKeyUp) < 0 Or GetKeyState(vbKeyW) < 0 Then
> ```
> _You will still need the_ **ChatFocus** _if statement around them to ensure you're not moving when typing w/a/s/d.
> You may also prefer to wrap it around all the key presses to ensure when you're typing, you're only typing. (If you were to attempt to paste something in to the chat for example and you're standing next to someone, you're going to end up accidentally hitting them by the control key press.)_
>
> **Optional Step:**
>
> **In frmMain (Code):**
> _In_ **Private Sub picScreen_MouseDown** _Remove/Comment:_
> ```
> Call SetFocusOnChat
> ```_(This causes the return key to be the only method of switching focus, but it's not required.. personally preference)_
>
> I might be forgetting something, I patched this up in just a couple minutes by looking at OP's code.

i tried your method and it works great, cant type in the richtextbox with your method but one problem, whenever i press enter it sets focus on chat but once it sets it on chat i need to press enter more than once sometimes to set it off the chat.
Link to comment
Share on other sites

Theres two things:

1) This isnt a bug but theres a slight flicker when you hit enter, watch the txtmychat, the 'line' thing that shows you're able to type (dunno what it's called xD).

2) This is what probably causes 1, it you can hit enter a million times, if you hold it down for like half a second it will register it as two enters, this probably causes the flicker. I cant tell if the chat focus goes on and off though.
Link to comment
Share on other sites

I'm not entirely sure, I haven't used Boko's mod to my original tutorial.

From looking at his code though, I can see where your problem is coming into play.  It has to do with how fast the engine does CheckInputKeys and how his SetFocusOnChat automatically changes the flag.  So what happens is that if a player holds down Return for a second or 2, it calls SetFocusOnChat a dozen times and continually changes the boolean from True to False.
Link to comment
Share on other sites

Ah sorry, I didn't test the code last time so wasn't sure if it'd work okay.

It's an easy fix though.
The following is changes to my previous code, I've also modified my previous post with these changes.
Deffinately works now, just tested it.

_In_ **modGlobals** _Find:_
```
' Chat Focus
Public ChatFocus As Boolean
```
_Under that Add:_
```
Public KeyDown As Boolean
```
_In_ **modInput**
_In_ **Public Sub CheckInputKeys** _Find:_
```
If GetKeyState(vbKeyReturn) < 0 Then
        Call SetFocusOnChat
End If
```_Replace with:_
```
If GetKeyState(vbKeyReturn) < 0 And KeyDown = False Then
        KeyDown = True
ElseIf Not GetKeyState(vbKeyReturn) < 0 And KeyDown = True Then
        KeyDown = False
        Call SetFocusOnChat
End If
```
This now does nothing when the key is press, but then calls the chat focus function when the key is released from being pressed.
I'm not completely sure which value the GetKeyState returns for releasing a button from being pressed (I don't think it does), if someone knows then the KeyDown variable is unneccessary and the statement can just be changed to If GetKeyState(vbKeyReturn) = #

It's also worth mentioning that the following lines in the **Sub GameInit** in **modGeneral** are not actually neccessary unless your chat is given focuss in some other way to begin with.
```
'ChatFocus = True ' Default to screen focus
    'Call SetFocusOnChat
```
I personally also removed the **Private Sub txtChat_GotFocus** in **frmMain (Code)**
Link to comment
Share on other sites

@Boko:

> Ah sorry, I didn't test the code last time so wasn't sure if it'd work okay.
>
> It's an easy fix though.
> The following is changes to my previous code, I've also modified my previous post with these changes.
> Deffinately works now, just tested it.
>
> _In_ **modGlobals** _Find:_
> ```
> ' Chat Focus
> Public ChatFocus As Boolean
> ```
> _Under that Add:_
> ```
> Public KeyDown As Boolean
> ```
> _In_ **modInput**
> _In_ **Public Sub CheckInputKeys** _Find:_
> ```
> If GetKeyState(vbKeyReturn) < 0 Then
>         Call SetFocusOnChat
> End If
> ```_Replace with:_
> ```
> If GetKeyState(vbKeyReturn) < 0 And KeyDown = False Then
>         KeyDown = True
> ElseIf Not GetKeyState(vbKeyReturn) < 0 And KeyDown = True Then
>         KeyDown = False
>         Call SetFocusOnChat
> End If
> ```
> This now does nothing when the key is press, but then calls the chat focus function when the key is released from being pressed.
> I'm not completely sure which value the GetKeyState returns for releasing a button from being pressed (I don't think it does), if someone knows then the KeyDown variable is unneccessary and the statement can just be changed to If GetKeyState(vbKeyReturn) = #
>
> It's also worth mentioning that the following lines in the **Sub GameInit** in **modGeneral** are not actually neccessary unless your chat is given focuss in some other way to begin with.
> ```
> 'ChatFocus = True ' Default to screen focus
>     'Call SetFocusOnChat
> ```
> I personally also removed the **Private Sub txtChat_GotFocus** in **frmMain (Code)**

yes it works great now, thanks for the code.
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...