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

Problem to show window

Samuel Bili

New Member
Joined
Oct 3, 2021
Messages
8
Reaction score
0
I'm having trouble showing the window only when I get the Opcode buffer, only when I get a result from the buffer do I want to show the window. Here's my code:

Lua:
local mymodule
local Opcodes = 100
local healthBar = nil
local manaBar = nil

function init()

  ProtocolGame.registerExtendedOpcode(Opcodes, function(protocol, opcode, buffer)
    onHealthChange(buffer)
    online()
    window(buffer)
  end)
    
  mymodule = g_ui.loadUI('health', modules.game_interface.getMapPanel())
  mymodule:hide()
 
  healthBar = mymodule:recursiveGetChildById('healthBar')
  manaBar = mymodule:recursiveGetChildById('manaBar')

  g_keyboard.bindKeyPress('Ctrl+F', toggle)
    
  connect(LocalPlayer, { onHealthChange = onHealthChange,
                         onManaChange = onManaChange })
end

function terminate()
  disconnect(LocalPlayer, { onHealthChange = onHealthChange,
                            onManaChange = onManaChange })

  mymodule:destroy()
  mymodule = nil
  g_keyboard.unbindKeyPress('Ctrl+F')
end

function onHealthChange(buffer)
  healthBar:setValue(buffer, 0, 2850)
end

function onManaChange(localPlayer, mana, maxMana)
  manaBar:setValue(mana, 0, maxMana)
end

function hide()
  mymodule:hide()
end

function show()
  mymodule:show()
  g_game.getProtocolGame():sendExtendedOpcode(Opcodes, '')
end

function online()
    if g_game.isOnline() then
        g_game.getProtocolGame():sendExtendedOpcode(Opcodes, '')
    end
end

function toggle()
    if mymodule:isVisible() then
        mymodule:setFocusable(false)
        mymodule:hide()
    else
        mymodule:show()
        g_game.getProtocolGame():sendExtendedOpcode(Opcodes, '')
    end
end

function window(buffer)
  if buffer then
    mymodule:show()
  else
    mymodule:hide()
  end
end
 
How to reload the module by script?
Post automatically merged:

How to reload the module by script?
I searched the sources and found "g_modules", now just the first question, how to make the window only appear when you have a result in Opcode.
 
Last edited:
Back
Top