• 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!

How can i disable keyboards letters hotkeys while chat is enable?

leocbertholo

New Member
Joined
Feb 17, 2018
Messages
2
Reaction score
0
Hey everyone,
I'm looking to make work a wasd movement script like the way it works on the old tibia flash client.
Like this:
"Chat enable -> The hotkeys that are not components of F1, F2, F3... will be disabled.
Chat disable -> Wasd walk will work and all the hotkeys including letters like "Q" and "E" will be enabled"

I looked everywhere for a complete hotkey code that worked like this but i couldn't find, so I decided to work on the Wasd movement code that I already have, but I don't know much about coding and I have no idea on how to start.

Do you guys know any code that does that? Or a function that I could use to desactivate some hotkeys like the letters?

Thanks in advance
 
Last edited:
I do not know if I did it right, but it works for me. I added the rotating character with "Ctrl + AWSD"


Find this code, and replace
modules\game_console\console.lua
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")
 
  gameInterface.unbindWalkKey('Ctrl+W', North)
  gameInterface.unbindWalkKey('Ctrl+D', East)
  gameInterface.unbindWalkKey('Ctrl+S', South)
  gameInterface.unbindWalkKey('Ctrl+A', West)

   modules.game_hotkeys.toggleChat(false)
  consoleToggleChat:setTooltip(tr("Disable chat mode, allow to walk using ASDW"))
end

function disableChat()
  local gameInterface = modules.game_interface

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

  local quickFunc = function()
    if consoleToggleChat:isChecked() then
      consoleToggleChat:setChecked(false)
    end
    enableChat()
  end
  g_keyboard.bindKeyUp("Space", quickFunc)
  g_keyboard.bindKeyUp("Enter", quickFunc)
  g_keyboard.bindKeyUp("Escape", quickFunc)
  g_keyboard.unbindKeyUp("1", 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)
 
  gameInterface.bindTurnKey('Ctrl+W', North)
  gameInterface.bindTurnKey('Ctrl+D', East)
  gameInterface.bindTurnKey('Ctrl+S', South)
  gameInterface.bindTurnKey('Ctrl+A', West)

     modules.game_hotkeys.toggleChat(true)
  consoleToggleChat:setTooltip(tr("Enable chat mode"))
end

and in hotkeys_manager i add this
modules\game_hotkeys\hotkeys_manager.lua
Code:
chatOn = true
chat = true

function toggleChat(chat)
chatOn = chat
end

and i add one IF in DoKeyCombo

Lua:
function doKeyCombo(keyCombo)
    if chatOn == true then
  if not g_game.isOnline() then return end
  local hotKey = hotkeyList[keyCombo]
  if not hotKey then return end

  if g_clock.millis() - lastHotkeyTime < modules.client_options.getOption('hotkeyDelay') then
    return
  end
  lastHotkeyTime = g_clock.millis()

  if hotKey.itemId == nil then
    if not hotKey.value or #hotKey.value == 0 then return end
    if hotKey.autoSend then
      modules.game_console.sendMessage(hotKey.value)
    else
      modules.game_console.setTextEditText(hotKey.value)
    end
  elseif hotKey.useType == HOTKEY_MANAGER_USE then
    if g_game.getClientVersion() < 780 or hotKey.subType then
      local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
      if item then
        g_game.use(item)
      end
    else
      g_game.useInventoryItem(hotKey.itemId)
    end
  elseif hotKey.useType == HOTKEY_MANAGER_USEONSELF then
    if g_game.getClientVersion() < 780 or hotKey.subType then
      local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
      if item then
        g_game.useWith(item, g_game.getLocalPlayer())
      end
    else
      g_game.useInventoryItemWith(hotKey.itemId, g_game.getLocalPlayer())
    end
  elseif hotKey.useType == HOTKEY_MANAGER_USEONTARGET then
    local attackingCreature = g_game.getAttackingCreature()
    if not attackingCreature then
      local item = Item.create(hotKey.itemId)
      if g_game.getClientVersion() < 780 or hotKey.subType then
        local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
        if not tmpItem then return end
        item = tmpItem
      end

      modules.game_interface.startUseWith(item)
      return
    end

    if not attackingCreature:getTile() then return end
    if g_game.getClientVersion() < 780 or hotKey.subType then
      local item = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
      if item then
        g_game.useWith(item, attackingCreature)
      end
    else
      g_game.useInventoryItemWith(hotKey.itemId, attackingCreature)
    end
  elseif hotKey.useType == HOTKEY_MANAGER_USEWITH then
    local item = Item.create(hotKey.itemId)
    if g_game.getClientVersion() < 780 or hotKey.subType then
      local tmpItem = g_game.findPlayerItem(hotKey.itemId, hotKey.subType or -1)
      if not tmpItem then return true end
      item = tmpItem
    end
    modules.game_interface.startUseWith(item)
  end
  end
end

If someone wants to turn off the chat with the key
In Console.lua, in functuin init()
add this (You can insert any other button instead of Ctrl + F)
Lua:
g_keyboard.bindKeyDown('Ctrl+F', disableChat)
 

Attachments

Back
Top