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

my window doesn't close

Scremo

Member
Joined
Jul 13, 2014
Messages
51
Reaction score
14
I have this script:

Lua:
WindowButton = nil
MainWindow = nil

function init()   
connect(g_game, { onGameEnd = offline })

  connect(LocalPlayer, { onHealthChange = onHealthChange,
                         onManaChange = onManaChange})                             

  ProtocolGame.registerExtendedOpcode(90, SendATT)
 
  WindowButton = modules.client_topmenu.addLeftGameButton('WindowButton', tr('Points Panel'), '/game_points/images/icon', closing)
  WindowButton:setIconOffsetY(3)
  WindowButton:setOn(false)

  MainWindow = g_ui.displayUI('game_points')
  MainWindow:hide()
 
 
  allTabs = MainWindow:recursiveGetChildById('allTabs')
  allTabs:setContentWidget(MainWindow:getChildById('optionsTabContent'))
  HealthInfoText = MainWindow:recursiveGetChildById('HealthGet')
  InfoPointsText = MainWindow:recursiveGetChildById('InfoPoints')

    if g_game.isOnline() then
    local localPlayer = g_game.getLocalPlayer()
    onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
    onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
  end
 refresh()
end

function terminate()
disconnect(g_game, { onGameEnd = offline })
  
  disconnect(LocalPlayer, { onHealthChange = onHealthChange,
                            onManaChange = onManaChange})                                                                                                       
  ProtocolGame.unregisterExtendedOpcode(90)
   WindowButton:destroy()
   MainWindow:destroy()
end

function onHealthChange(localPlayer, health, maxHealth)
local player = g_game.getLocalPlayer()
HealthInfoText:setText ("[" .. player:getMaxHealth() .. "]")
end

function onManaChange(localPlayer, mana, maxMana)
end

function offline()
onMainWindowClose()
MainWindow:hide()
MainWindow:setVisible(false)
MainWindow:destroy()
end

function refresh()
  local player = g_game.getLocalPlayer()
  if not player then return end
end

function closing()
local protocolGame = g_game.getProtocolGame()
  if WindowButton:isOn() then
    MainWindow:setVisible(false)
    WindowButton:setOn(false)
  else
    MainWindow:setVisible(true)
    WindowButton:setOn(true)
      if protocolGame then
      protocolGame:sendExtendedOpcode(14, 2)
      end
   end
end

function SendATT(protocol, opcode, buffer, localPlayer)
local player = g_game.getLocalPlayer()
Numb = tonumber(buffer)
HealthInfoText:setText ("[" .. player:getMaxHealth() .. "]")
InfoPointsText:setText ("Your Points: [" .. Numb .. "]")
end

function HealthPoints()
local protocolGame = g_game.getProtocolGame()
  if WindowButton:isOn() then
  if protocolGame then
      protocolGame:sendExtendedOpcode(14, 1)
    end
  else
    MainWindow:setVisible(true)
    WindowButton:setOn(true)
  end
end

function onMainWindowClose()
 WindowButton:setOn(false)
 MainWindow:hide()
 MainWindow:setVisible(false)
 MainWindow:destroy()
end

I swear I wanted to understand why when logging out my script doesn’t close, it doesn’t make any sense, based on other modules I don’t understand why it doesn’t close when logging out ...

if any charitable soul can help me, I’m trying for days
Post automatically merged:

in a test I put:

Lua:
  @onEnter: modules.game_points.onMiniWindowClose()

and in code in .lua:

Code:
function onMiniWindowClose()
  MainWindow:setVisible(false)
  WindowButton:setOn(false)
end

and everything goes well, it works when I press enter it closes the window.

and why when I try to:

Code:
connect(g_game, {onGameEnd = onMiniWindowClose})
and
Code:
disconnect(g_game, { onGameEnd = onMiniWindowClose})

doesn’t work ?, this above makes when I enter or leave to perform such function, and because it doesn’t go man it doesn’t make sense wtf
 
Last edited:
change:

Lua:
function onMiniWindowClose()
  MainWindow:setVisible(false)
  WindowButton:setOn(false)
end

for:

Lua:
function onMiniWindowClose()
   MainWindow:destroy()
end

or if you want it to close when the character disconnects:
add this to your function terminate()

Lua:
disconnect(g_game, {
      onGameStart = onMiniWindowClose,
      onGameEnd = onMiniWindowClose,
    onWalk = check,
    onAutoWalk = check
  })
 
Last edited:
No need for destroying.
Just use MainWindow:hide(). I made new module using MainWindow to test this out, when I log out it just closes.

This is lua code:
Lua:
local rootWindow
local characterName
function init()
    connect(LocalPlayer, {
        onNameChange = onNameChange
    })
    connect(g_game, {
        onGameStart = online,
        onGameEnd = offline
    })
    rootWindow = g_ui.displayUI('test')
    rootWindow:hide()
    characterName = rootWindow:getChildById('characterName')
    if g_game.isOnline() then
        online()
    end
end
function terminate()
    disconnect(LocalPlayer, {
        onNameChange = onNameChange
    })
    disconnect(g_game, {
        onGameStart = online,
        onGameEnd = offline
    })
    rootWindow:destroy()
end
function online()
    local player = g_game.getLocalPlayer()
    onNameChange(player, g_game.getCharacterName())
end
function offline()
    rootWindow:hide()
end

function onNameChange(player, name)
    characterName:setText(name)
end

function toggle()
    if rootWindow:isVisible() then
        hide()
    else
        show()
    end
end
 
function show()
    rootWindow:show()
    rootWindow:raise()
    rootWindow:focus()
end
 
function hide()
    rootWindow:hide()
end

And otui:
Code:
MainWindow
  id: rootWindow
  size: 480 300

  @onEnter: modules.module_test.toggle()
  @onEscape: modules.module_test.toggle()

  Label
    id: characterName
    anchors.top: parent.top
    anchors.left: parent.left
    anchors.right: parent.right
    margin: 2 0 0 4
    height: 18
    font: terminus-14px-bold
    color: white

  Button
    !text: tr('Close')
    width: 64
    anchors.right: parent.right
    anchors.bottom: parent.bottom
    @onClick: modules.module_test.hide()
 
Last edited:
first thanks for the help of both, so I trying and testing a lot I realized that my terminate () function doesn't work, I tried something like:

Lua:
disconnect(g_game, {onGameEnd = Offline})

and then

Code:
function onMiniWindowClose()
print("successful exit ")
end


I do not print when disconnecting after connecting, nothing appears, I tried on other modules and on other modules it works, I also checked my otmod file and everything is ok, this really is very strange ...
Post automatically merged:

I used your @margoh script, and the same thing happens, the terminate function does not work, simply the init when I print a message works, but the terminate when I try to do the same thing does not work ...
Post automatically merged:

the strangest thing is that when i try to do this in an existing module like HealthInfo, the terminate, onGameEnd function works, since any other module created doesn’t work, am I forgetting anything? in otmod the unload function is indicated for terminate ()
 
Last edited:
That's really weird, never encountered that before, so there is not much I can help with.
 
I have read that here so I must make it right: otmod unload function (customary terminate()) doesn't execute on character logout.
Your whole code is so messy so we cannot help you in a simple way. Let's try to make some changes:

First: you must make your whitespaces clear cause your code is unreadable without them.
Second: you shouldn't use connecting to localPlayer in init function. It executes on module load, so usually when client starts - you have not logged character there yet. I reccomend you to move it to some onGameStart function
Third: you don't need these refresh function. It does nothing here.
Fourth: sometimes you mix MAIN and MINI prefix in your functions mentioned here. There exist onMAINwindowclose and onMINIwindowclose indicators. Be careful using such extensive indicators.

I suggest you to rewrite your module starting from this pattern I wrote you basing on your code:

Lua:
WindowButton = nil
MainWindow = nil

function init()
    connect(g_game, { onGameStart = online, onGameEnd = offline })

    WindowButton = modules.client_topmenu.addLeftGameButton('WindowButton', tr('Points Panel'), '/game_points/images/icon', toggle)

    --here is your extended opcodes register, ui create etc.

    if g_game.isOnline() then
        online()
    end
end

function online()
    connect(LocalPlayer, { onHealthChange = onHealthChange, onManaChange = onManaChange})
    --extra onHealthChange and onManaChange are unnesseccary, they are executed on character login also
end

function terminate()
    disconnect(g_game, { onGameStart = online, onGameEnd = offline })

    ProtocolGame.unregisterExtendedOpcode(90)

    onMainWindowClose()
    WindowButton:destroy()
    WindowButton = nil
    MainWindow:destroy()
    MainWindow = nil
end

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

    onMainWindowClose()
end

function toggle()
    if WindowButton:isOn() then
        onMainWindowClose()
    else
        onMainWindowOpen()
        local protocolGame = g_game.getProtocolGame()
        if protocolGame then
            protocolGame:sendExtendedOpcode(14, 2)
        end
    end
end

function onMainWindowOpen()
    WindowButton:setOn(true)
    MainWindow:show()
end

function onMainWindowClose()
    WindowButton:setOn(false)
    MainWindow:hide()
end

-- the rest of your module functions here
 
Thank you very much @Bakasura , I rewrote the code, this is a bit messy because my only intention was to understand why the terminate () didn’t work, maybe it was wrong, I will try, if successful I update you here ..
Post automatically merged:

@Bakasura I tried here with your code and with a more organized structure, I had done this before and the terminate () function still doesn't work, I've tried everything, now just try with another version of otclient ..
 
Last edited:
I'll say it again: terminate() function doesn't execute on character logout. It works when you totally exit the client. You won't see it's effect untill you open the terminal log file.
 
yes thanks, i realized this, my problem is in the onGameEnd function, only it
 
Back
Top