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

Fightmode Button

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
59
Hello!

In my actions module I create a fightmode button, but I need connect this button with the console Checkbox.

How can I start this? Any idea ?


FightMode.png
 
Solution
  • set sandboxed to false for both modules (otui)
  • create a variable that isn't local
  • use same function to enable/disable both buttons at the same time
  • set sandboxed to false for both modules (otui)
  • create a variable that isn't local
  • use same function to enable/disable both buttons at the same time
 
Last edited:
Solution
  • set sandboxed to false for both modules (otui)
  • create a variable that isn't local
  • use same function to enable/disable both buttons at the same time

thanks for your attention @zbizu, you are helping me a lot!! I have some doubts.

1) set sandboxed to false for both modules (otui)
In otml file I placed "sandboxed: false", okay?

2) create a variable that isn't local
You can give me a variable model for me to understand? Where I create this variable? In console or actions module?

3) use same function to enable/disable both buttons at the same time
In console.otui I was using on toggleChat button this "@onCheckChange: toggleChat()", I use this in my actions.otui button too ?

Sorry for all this questions, but I'm a begginer and I'm trying to learn this.
 
thought you're more advanced judging by the heavily modded client you're using

1. yes
2. that button on the console I think, it's only thing you need to access through other module
3. yeah, should be togglechat
 
thought you're more advanced judging by the heavily modded client you're using

I only changed my design interface OTUI, nothing with LUA.

1. yes
2. that button on the console I think, it's only thing you need to access through other module
3. yeah, should be togglechat

I already set sandboxed to false and placed the function @onCheckChange: toggleChat(), but I can't create a variable to acess the other module... I'm all day trying to do this, but it seems impossible... I was reading the Lua tutorial [ Manual de Referência de Lua 5.1 (https://www.lua.org/manual/5.1/pt/manual.html#2.3) ], and nothing clears my mind...

This is my actions.lua
LUA:
actionsWindow = nil
actionsPanel = nil
chaseModeButton = nil

function init()

  actionsWindow = g_ui.loadUI('actions', modules.game_interface.getRightPanel())
  actionsWindow:open()
  actionsWindow:disableResize()

  actionsPanel = actionsWindow:getChildById('contentsPanel')

  chaseModeButton = actionsWindow:recursiveGetChildById('chaseModeBox')

  connect(chaseModeButton, { onCheckChange = onSetChaseMode })
  connect(g_game, {
    onGameStart = online,
    onGameEnd = offline,
    onChaseModeChange = update
  })

  if g_game.isOnline() then
    online()
  end

  actionsWindow:setup()
end

function terminate()
  if g_game.isOnline() then
    offline()
  end

  actionsWindow:destroy()

  disconnect(g_game, {
    onGameStart = online,
    onGameEnd = offline,
    onChaseModeChange = update
  })
end

function update()
  local chaseMode = g_game.getChaseMode()
  chaseModeButton:setChecked(chaseMode == ChaseOpponent)
end

function check()
  if modules.client_options.getOption('autoChaseOverride') then
    if g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent then
      g_game.setChaseMode(DontChase)
    end
  end
end

function onSetChaseMode(self, checked)
  local chaseMode
  if checked then
    chaseMode = ChaseOpponent
  else
    chaseMode = DontChase
  end
  g_game.setChaseMode(chaseMode)
end

function getActions()
  return actionsWindow
end

and my actions.otui
CSS:
MiniWindow
  id: actionsWindow
  !text: tr('Actions')
  height: 197
  width: 165

  MiniWindowContents
    InsideWindow
      id: insidewindow1
      size: 151 42
      image-border: 3
      anchors.top: parent.top
      anchors.left: parent.left
      margin-top: 3
      margin-left: 4

    ActionButton
      id: button1
      !text: tr('Buy Premium Cards')
      font: verdana-11px-rounded
      color: #82ff82
      size: 149 20
      anchors.top: insidewindow1.top
      anchors.left: insidewindow1.left
      margin-top: 1
      margin-left: 1

    ActionButton
      id: button2
      !text: tr('Open Premium Shop')
      font: verdana-11px-rounded
      color: #82ff82
      size: 149 20
      anchors.top: button1.bottom
      anchors.left: button1.left
      margin-top: 1

    InsideWindow
      id: insidewindow2
      size: 151 22
      image-border: 3
      anchors.top: insidewindow1.bottom
      anchors.left: insidewindow1.left
      margin-top: 5

    CheckBox2
      id: chaseModeBox
      !text: tr('Autofollow')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: insidewindow2.top
      anchors.left: insidewindow2.left
      margin-top: 1
      margin-left: 1

    CheckBox2
      id: toggleChat
      !text: tr('Fightmode')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: insidewindow2.top
      anchors.left: chaseModeBox.right
      anchors.right: insidewindow2.right
      margin-top: 1
      margin-left: 1
      margin-right: 1
      @onCheckChange: modules.game_console.toggleChat()

    InsideWindow
      id: insidewindow3
      size: 151 82
      image-border: 3
      anchors.top: insidewindow2.bottom
      anchors.left: insidewindow2.left
      margin-top: 5

    ActionButton
      id: button4
      !text: tr('Quests')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: insidewindow3.top
      anchors.left: insidewindow3.left
      margin-top: 1
      margin-left: 1

    ActionButton
      id: button5
      !text: tr('Spells')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: insidewindow3.top
      anchors.left: button4.right
      anchors.right: insidewindow3.right
      margin-top: 1
      margin-left: 1
      margin-right: 1

    ActionButton
      id: button6
      !text: tr('Talents')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: button4.bottom
      anchors.left: button4.left
      margin-top: 1

    ActionButton
      id: button7
      !text: tr('Guild')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 74 20
      anchors.top: button6.top
      anchors.left: button6.right
      anchors.right: insidewindow3.right
      margin-left: 1
      margin-right: 1

    ActionButton
      id: button8
      !text: tr('Options')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 149 20
      anchors.top: button6.bottom
      anchors.left: button6.left
      margin-top: 1
      @onClick: modules.client_options.show()

    ActionButton
      id: button9
      !text: tr('Logout')
      font: verdana-11px-rounded
      color: #c8c8c8
      size: 149 20
      anchors.top: button8.bottom
      anchors.left: button8.left
      margin-top: 1
      @onClick: g_game.safeLogout()


@Edit:
I tried to put this in actions.lua but it didn't work:
LUA:
function toggleChat()
  if toggleChat:isChecked() then
    consoleToggleChat:setChecked(true)
  else
    consoleToggleChat:setChecked(false)
  end
end
 
Last edited:
CSS:
ERROR: protected lua call failed: LUA ERROR:
/game_actions/actions.lua:32: attempt to index global 'buttonChat' (a nil value)
stack traceback:
    [C]: in function '__index'
    /game_actions/actions.lua:32: in function 'ligaChat'
    /game_actions/actions.otui:69: [@onCheckChange]:2: in function </game_actions/actions.otui:69: [@onCheckChange]:1>
    [C]: in function 'setChecked'
    /corelib/ui/uicheckbox.lua:12: in function </corelib/ui/uicheckbox.lua:11>

I finally got it! This is the correct Script.

I changed the function name, and others variables. Excludes somethings that I don't need. With your help and some Lua tutoriais I learned few other things.

LUA:
actionsWindow = nil
actionsPanel = nil
chaseModeButton = nil

function init()

  actionsWindow = g_ui.loadUI('actions', modules.game_interface.getRightPanel())
  actionsWindow:open()
  actionsWindow:disableResize()

  actionsPanel = actionsWindow:getChildById('contentsPanel')

  chaseModeButton = actionsWindow:recursiveGetChildById('chaseModeBox')

  connect(chaseModeButton, { onCheckChange = onSetChaseMode })
  connect(g_game, {
    onGameStart = online,
    onGameEnd = offline,
    onChaseModeChange = update
  })

  if g_game.isOnline() then
    online()
  end

  actionsWindow:setup()
end

function ligaChat()
  local buttonChat = actionsWindow:recursiveGetChildById('actionsToggleChat')
  if buttonChat:isChecked() then
    consoleToggleChat:setChecked(true)
  else
    consoleToggleChat:setChecked(false)
  end
end

function terminate()
  if g_game.isOnline() then
    offline()
  end

  actionsWindow:destroy()

  disconnect(g_game, {
    onGameStart = online,
    onGameEnd = offline,
    onChaseModeChange = update
  })
end

function update()
  local chaseMode = g_game.getChaseMode()
  chaseModeButton:setChecked(chaseMode == ChaseOpponent)
end

function check()
  if modules.client_options.getOption('autoChaseOverride') then
    if g_game.isAttacking() and g_game.getChaseMode() == ChaseOpponent then
      g_game.setChaseMode(DontChase)
    end
  end
end

function onSetChaseMode(self, checked)
  local chaseMode
  if checked then
    chaseMode = ChaseOpponent
  else
    chaseMode = DontChase
  end
  g_game.setChaseMode(chaseMode)
end

function getActions()
  return actionsWindow
end

@Edit: But I need some changes yet.

I placed this "actionsWindow:recursiveGetChildById" but, How is the diference to getChildById and recursiveGetChildById ?

with recursiveGetChildById I can go further ?

LUA:
function ligaChat()
  local buttonChat = actionsWindow:recursiveGetChildById('actionsToggleChat')
  if buttonChat:isChecked() then
    consoleToggleChat:setChecked(true)
  else
    consoleToggleChat:setChecked(false)
  end
end
 
Last edited:
Back
Top