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