• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient Chat/walking System

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,324
Solutions
68
Reaction score
998
So I am trying to make it so players use WASD walking always. The chat box should activate by pressing enter.

I can't figure out how to get it so when I press enter the chatbox is enabled and if I press it again (even with no text) it will disable.

Any help would be great.

Lua:
function enableChat()
  local gameInterface = modules.game_interface

  consoleTextEdit:setVisible(true)
  consoleTextEdit:setText("")

  g_keyboard.unbindKeyUp("Space")
  g_keyboard.unbindKeyUp("Enter")
  g_keyboard.unbindKeyUp("Escape")

  gameInterface.unbindWalkKey("W")
  gameInterface.unbindWalkKey("D")
  gameInterface.unbindWalkKey("S")
  gameInterface.unbindWalkKey("A")

  gameInterface.unbindWalkKey("E")
  gameInterface.unbindWalkKey("Q")
  gameInterface.unbindWalkKey("C")
  gameInterface.unbindWalkKey("Z")

  consoleToggleChat:setTooltip(tr("Disable chat mode, allow to walk using ASDW"))
end

function disableChat()
  local gameInterface = modules.game_interface

  consoleTextEdit:setVisible(false)
  consoleTextEdit:setText("")

  g_keyboard.bindKeyUp("Space", quickFunc)
  g_keyboard.bindKeyUp("Enter", quickFunc)
  g_keyboard.bindKeyUp("Escape", quickFunc)

  gameInterface.bindWalkKey("W", North)
  gameInterface.bindWalkKey("D", East)
  gameInterface.bindWalkKey("S", South)
  gameInterface.bindWalkKey("A", West)

  gameInterface.bindWalkKey("E", NorthEast)
  gameInterface.bindWalkKey("Q", NorthWest)
  gameInterface.bindWalkKey("C", SouthEast)
  gameInterface.bindWalkKey("Z", SouthWest)

  consoleToggleChat:setTooltip(tr("Enable chat mode"))
end

function sendCurrentMessage()
  local message = consoleTextEdit:getText()
  if #message == 0 then return end
  consoleTextEdit:clearText()

  -- send message
  sendMessage(message)
  consoleToggleChat:setChecked(true)
  disableChat()
end

I tried adding
Lua:
g_keyboard.bindKeyPress("Enter", enableChat())
to disableChat() function but it automatically enables the chat because I press it to send the message.
Post automatically merged:

Figured it out. Just add

console.lua
Lua:
function newToggle()
    if consoleToggleChat:isChecked() then
        consoleToggleChat:setChecked(false)
        enableChat()
    else
        consoleToggleChat:setChecked(true)
        disableChat()
    end
end

and add

Lua:
g_keyboard.bindKeyUp('Enter', newToggle, consolePanel)

under

Lua:
g_keyboard.bindKeyDown('Enter', sendCurrentMessage, consolePanel)
 
Last edited:
Hello there, ltutorial,

OTClient is a cunt most of the times, you could always use the inbuilt terminal and debug your situation, I think I can help you out on this one.

I don't know why you have two functions for this, enabling chat and disabling chat, which is kind of redundant since it just can go on and off, so an if statement would be more than enough.

When you call your way to toggle WASD mode, you should check if consoleTextEdit:isEnabled() then you call consoleTextEdit:disable().
If you toggle the WASD mode out, then you call consoleTextEdit:enable() and then consoleTextEdit:focus() so you go directly to the chat, like it usually is in OTC.

If you need coding help let me know, I might provide you an example.

Best Wishes,
Okke
 
Please tell me what you did Itutorial.

I added:

Lua:
function newToggle()
    if consoleToggleChat:isChecked() then
        consoleToggleChat:setChecked(false)
        enableChat()
    else
        consoleToggleChat:setChecked(true)
        disableChat()
    end
end

to console.lua,

and added

Lua:
g_keyboard.bindKeyUp('Enter', newToggle, consolePanel)

Right under:

Lua:
g_keyboard.bindKeyDown('Enter', sendCurrentMessage, consolePanel)

But when I press the Enter key to enter chat mode, the cursor doesn't appear like it's supposed to, and doesn't let me chat.

Snip 2.PNG

Please help,

Thanks.
 
Back
Top