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

Lua [OTClient] MOD does not close

Cracudoo

New Member
Joined
Jan 22, 2017
Messages
32
Reaction score
0
This mod is not closing when the player exits the game

Code:
--Design
pokedexWindow = nil

--functions
Painel = {
    pokedex = {
        ['pnlDescricao'] = "",
        ['pnlAtaques'] = "",
        ['pnlHabilidades'] = "",       
    }
}
openedDex = {}
dexMax = 0

function init()
    pokedexWindow = g_ui.displayUI('game_pokedex.otui')
    pokedexWindow:hide()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
    connect(g_game, 'onTextMessage', serverComunication)
end

function showPokedex()
    if pokedexWindow then
    end
    pokedexWindow = g_ui.displayUI('game_pokedex')
end

function terminate()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
    pokedexWindow:hide()
    pokedexWindow:destroy()
    disconnect(g_game, 'onTextMessage', serverComunication)
end

function onoff()
    if pokedexWindow:isVisible() then
        pokedexWindow:hide()
    else
        pokedexWindow:show()
    end
end

function PokedexClose()
        pokedexWindow:hide()
end

function Painel.show(childName)   
    pokedexWindow:getChildById('pnlDescricao'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlDescricao'])
    pokedexWindow:getChildById('pnlAtaques'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlAtaques'])
    pokedexWindow:getChildById('pnlHabilidades'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlHabilidades'])
    pokedexWindow:getChildById('pnlDescricao'):setVisible(false)
    pokedexWindow:getChildById('scrDescricao'):setVisible(false)
    pokedexWindow:getChildById('pnlAtaques'):setVisible(false)
    pokedexWindow:getChildById('scrAtaques'):setVisible(false)
    pokedexWindow:getChildById('pnlHabilidades'):setVisible(false)
    pokedexWindow:getChildById('scrHabilidades'):setVisible(false)
   
    pokedexWindow:getChildById(childName):setVisible(true)
    pokedexWindow:getChildById('scr'..childName:sub(4,#childName)):setVisible(true)
   
end



function showPokemonDescription(id, itemId, maxLength, texto, writter, time)
    if not g_game.isOnline() then return end    --Se nao estiver online
    local name = texto:match('Name: (.-)\n')
    local type = texto:match('Type: (.-)\n')
    --Se for chamada de pokedex
    if name and type then 
        showPokedex()
       
        --Required Level
        local requieredLevel = texto:match('Required level: (.-)\n')
       
        --Evolution Description
        local evoDesc = texto:match('\nEvolutions:\n(.-)\n')
       
        --MOVES
        local moves = texto:match('\nMoves:\n(.-)\nAbility:')
       
        --Ability
        local ability = texto:sub(texto:find('Ability:\n')+9,#texto)
       
        pokedexWindow:getChildById('lblPokeName'):setText(name)
        if name:find("Shiny") then
            name = name:sub(7,#name)
            pokedexWindow:getChildById('lblPokeName'):setColor("red")
        end
        local f = io.open("modules/game_pokedex/imagens/pokemons/"..name..".png","r");
        if not f then
            print("Essa imagem não foi encontrada "..name)
        else
            f:close()
            pokedexWindow:getChildById('imgPokemon'):setImage("/game_pokedex/imagens/pokemons/"..name..".png")
        end
        Painel.pokedex["pnlDescricao"] = "Tipo: "..type.."\nNível requerido: "..requieredLevel.."\n\nEvolucões:\n"..evoDesc
        Painel.pokedex["pnlAtaques"] = moves
        Painel.pokedex["pnlHabilidades"] = ability
        Painel.show('pnlDescricao')
    end
end

function serverComunication(mode, text)
        if not g_game.isOnline() then
            return
        end

function hide()
    pokedexWindow:hide()
    pokedexWindow:setVisible(false)
end
end
 
The function "hide" is declared inside "serverComunication".
With proper indentation it looks like this.
Lua:
function serverComunication(mode, text)
    if not g_game.isOnline() then
        return
    end

    function hide()
       pokedexWindow:hide()
       pokedexWindow:setVisible(false)
    end
end
 
The function "hide" is declared inside "serverComunication".
With proper indentation it looks like this.
Lua:
function serverComunication(mode, text)
    if not g_game.isOnline() then
        return
    end

    function hide()
       pokedexWindow:hide()
       pokedexWindow:setVisible(false)
    end
end


It's closing now thanks, but if the player leaves without opening the mod this error happens

Code:
ERROR: protected lua call failed: LUA ERROR:
/game_pokedex/game_pokedex.lua:100: attempt to index global 'pokedexWindow' (a nil value)
stack traceback:
    [C]: ?
    /game_pokedex/game_pokedex.lua:100: in function </game_pokedex/game_pokedex.lua:99>

game_pokedex.lua

Code:
--Design
pokedexWindow = nil

--functions
Painel = {
    pokedex = {
        ['pnlDescricao'] = "",
        ['pnlAtaques'] = "",
        ['pnlHabilidades'] = "",       
    }
}
openedDex = {}
dexMax = 0

function init()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
end

function showPokedex()
    if pokedexWindow then
    end
    pokedexWindow = g_ui.displayUI('game_pokedex')
end

function terminate()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
    pokedexWindow:destroy()
end

function onoff()
    if pokedexWindow:isVisible() then
        pokedexWindow:hide()
    else
        pokedexWindow:show()
    end
end

function PokedexClose()
        pokedexWindow:hide()
end

function Painel.show(childName)   
    pokedexWindow:getChildById('pnlDescricao'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlDescricao'])
    pokedexWindow:getChildById('pnlAtaques'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlAtaques'])
    pokedexWindow:getChildById('pnlHabilidades'):getChildById('lblConteudo'):setText(Painel.pokedex['pnlHabilidades'])
    pokedexWindow:getChildById('pnlDescricao'):setVisible(false)
    pokedexWindow:getChildById('scrDescricao'):setVisible(false)
    pokedexWindow:getChildById('pnlAtaques'):setVisible(false)
    pokedexWindow:getChildById('scrAtaques'):setVisible(false)
    pokedexWindow:getChildById('pnlHabilidades'):setVisible(false)
    pokedexWindow:getChildById('scrHabilidades'):setVisible(false)
   
    pokedexWindow:getChildById(childName):setVisible(true)
    pokedexWindow:getChildById('scr'..childName:sub(4,#childName)):setVisible(true)
   
end



function showPokemonDescription(id, itemId, maxLength, texto, writter, time)
    if not g_game.isOnline() then return end    --Se nao estiver online
    local name = texto:match('Name: (.-)\n')
    local type = texto:match('Type: (.-)\n')
    --Se for chamada de pokedex
    if name and type then 
        showPokedex()
       
        --Required Level
        local requieredLevel = texto:match('Required level: (.-)\n')
       
        --Evolution Description
        local evoDesc = texto:match('\nEvolutions:\n(.-)\n')
       
        --MOVES
        local moves = texto:match('\nMoves:\n(.-)\nAbility:')
       
        --Ability
        local ability = texto:sub(texto:find('Ability:\n')+9,#texto)
       
        pokedexWindow:getChildById('lblPokeName'):setText(name)
        if name:find("Shiny") then
            name = name:sub(7,#name)
            pokedexWindow:getChildById('lblPokeName'):setColor("red")
        end
        local f = io.open("modules/game_pokedex/imagens/pokemons/"..name..".png","r");
        if not f then
            print("Essa imagem não foi encontrada "..name)
        else
            f:close()
            pokedexWindow:getChildById('imgPokemon'):setImage("/game_pokedex/imagens/pokemons/"..name..".png")
        end
        Painel.pokedex["pnlDescricao"] = "Tipo: "..type.."\nNível requerido: "..requieredLevel.."\n\nEvolucões:\n"..evoDesc
        Painel.pokedex["pnlAtaques"] = moves
        Painel.pokedex["pnlHabilidades"] = ability
        Painel.show('pnlDescricao')
    end
end

function hide()
    pokedexWindow:hide()
    pokedexWindow:setVisible(false)
end
 
Try this.
Lua:
function hide()
    if pokedexWindow then
        pokedexWindow:hide()
        pokedexWindow:setVisible(false)
    end
end

I love you <3
Could you tell me what function you use to close the mod when the player exits? Because I have 5 mods here that do not close, so I wanted to put the function in all
 
I'm not that familiar with OTClient to be honest. From what I remember you register a function to execute when the player disconnects.
In this case you have this.
Lua:
function init()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
end
See "onGameEnd = hide", this means that the function "hide" will be called when the player disconnects. In that function you put any code that is needed to close/hide the window.
 
I'm not that familiar with OTClient to be honest. From what I remember you register a function to execute when the player disconnects.
In this case you have this.
Lua:
function init()
    connect(g_game, { onEditText = showPokemonDescription, onGameEnd = hide } )
end
See "onGameEnd = hide", this means that the function "hide" will be called when the player disconnects. In that function you put any code that is needed to close/hide the window.

I'm not much of a fan of OTClient (but I do not need to), these two mods there that are not closing when the player exits the game

Code:
AtributosPanel = nil
AtributosButton = nil

function init()
  AtributosButton = modules.client_topmenu.addRightGameToggleButton('AtributosButton', tr('Ditto Memory'), 'ditto.png', toggle)
  AtributosButton:setOn(false)

  AtributosWindow = g_ui.displayUI('battle.otui')
  connect(g_game, { onGameStart = online,
    onGameEnd = offline})
   
  if not g_game.isOnline() then
    AtributosWindow:hide()
  end

  if AtributosButton:isOn() then
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  else
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  end
end

function terminate()
  disconnect(g_game, { onGameStart = online,
   onGameEnd = offline})
   
 g_keyboard.unbindKeyDown('Ctrl+8') 

   AtributosWindow:destroy()
   AtributosButton:destroy()
end

function hide()
    AtributosWindow:destroy()
end

function DittoClose()
    AtributosWindow:hide()
end

function toggle()
  if AtributosButton:isOn() then
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  else
    AtributosWindow:show()
    AtributosButton:setOn(true)
  end
end

function onMainWindowClose()
 AtributosButton:setOn(false)
end

Code:
local shopWindow
local shopButton
local shopTabBar
local addonsPanel
local itemsPanel
local premiumPanel
local mountsPanel
local acceptWindow

function init()
  shopWindow = g_ui.displayUI('shop')
  shopWindow:hide()
 
  shopTabBar = shopWindow:getChildById('shopTabBar')
  shopTabBar:setContentWidget(shopWindow:getChildById('shopTabContent'))

  addonsPanel = g_ui.loadUI('tms')
  shopTabBar:addTab(tr('Items'), addonsPanel, '/modules/game_shop/images/shoptabs/tmcase')

  mountsPanel = g_ui.loadUI('eggs')
  shopTabBar:addTab(tr('Poke Eggs'), mountsPanel, '/modules/game_shop/images/shoptabs/eggs')

  premiumPanel = g_ui.loadUI('premium')
  shopTabBar:addTab(tr('Premium'), premiumPanel, '/modules/game_shop/images/shoptabs/premium')

  shopButton = modules.client_topmenu.addRightGameToggleButton('Shop', tr('PokeArli Shop'), '/modules/game_shop/images/shop', toggle,true)
end

function terminate()
  shopWindow:destroy()
  shopButton:destroy()
end

function toggle()
  if shopWindow:isVisible() then
    hide()
  else
    show()
  end
end

function show()
  shopWindow:show()
  shopWindow:raise()
  shopWindow:focus()
end

function hide()
  shopWindow:hide()
  if acceptWindow then
    acceptWindow:destroy()
    acceptWindow = nil
  end
end

function addTab(name, panel, icon)
  shopTabBar:addTab(name, panel, icon)
end

function addButton(name, func, icon)
  shopTabBar:addButton(name, func, icon)
end

-- Buy functions:
function carbos()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy carbos')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function hpup()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy hpup')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function iron()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy iron')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function protein()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy protein')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function calcium()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy calcium')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function premium3()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy premium3')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function premium2()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy premium2')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function premium1()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy premium1')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

-- Addons
function tm03reflect()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-AttackT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm06toxic()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-DefenseT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm11bubblebeam()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-HellfireT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm07zapcannon()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-ReturnT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm12watergun()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-PoisonT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm13icebeam()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-ExperienceT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm14blizzard()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#X-ElementalT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm15hyperbeam()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#Y-RegenerationT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm18raindance()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#Y-CureT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm19gigadrain()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('#Y-WingT2#')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm21megadrain()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy megadrain')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm22solarbeam()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy solarbeam')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm24dragonbreath()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy dragonbreath')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm25thunder()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy thunder')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm26earthquake()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy earthquake')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm29psychic()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy psychic')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm33icepunch()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy icepunch')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm38fireblast()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy fireblast')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm41thunderpunch()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy thunderpunch')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm48firepunch()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy firepunch')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

function tm44rest()
  if acceptWindow then
    return true
  end

  local acceptFunc = function()
    g_game.talk('!shopbuy rest')
    acceptWindow:destroy()
    acceptWindow = nil
  end
 
  local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end

  acceptWindow = displayGeneralBox(tr('Accept transaction'), tr("Do you really want to buy this item?"),
  { { text=tr('Yes'), callback=acceptFunc },
    { text=tr('No'), callback=cancelFunc },
    anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  return true
end

thank you <3
 
On the first spoiler you have onGameEnd = offline,
Add
Lua:
function offline()
--code to hide window
end

Thanks, I left it so:

Code:
AtributosPanel = nil
AtributosButton = nil

function init()
  AtributosButton = modules.client_topmenu.addRightGameToggleButton('AtributosButton', tr('Ditto Memory'), 'ditto.png', toggle)
  AtributosButton:setOn(false)

  AtributosWindow = g_ui.displayUI('battle.otui')
  connect(g_game, { onGameStart = online,
    onGameEnd = offline})
   
  if not g_game.isOnline() then
    AtributosWindow:hide()
  end

  if AtributosButton:isOn() then
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  else
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  end
end

function terminate()
  disconnect(g_game, { onGameStart = online,
   onGameEnd = offline})
   
 g_keyboard.unbindKeyDown('Ctrl+8') 

   AtributosWindow:destroy()
   AtributosButton:destroy()
end

function hide()
    AtributosWindow:destroy()
end

function offline()
    AtributosWindow:destroy()
end

function DittoClose()
    AtributosWindow:hide()
end

function toggle()
  if AtributosButton:isOn() then
    AtributosWindow:hide()
    AtributosButton:setOn(false)
  else
    AtributosWindow:show()
    AtributosButton:setOn(true)
  end
end

function onMainWindowClose()
 AtributosButton:setOn(false)
end

now the mod leaves when leaving but when it enters novamento and tries to open the mod it does not open more and it appears this warning in the terminal:

Code:
WARNING: attempt to destroy widget 'AtributosWindow' two times
 
In offline function and hide function change from :destroy() to :hide()

Thank you so much, my friend. <3

When I leave with the mod open it goes straight, but when I enter again I have to press twice for the mod to appear, the same happens with the closed button.

And the shop.lua mod has no solution?
 
To shop.lua add
Lua:
connect(g_game, { onGameEnd = offline }) -- inside init()
disconnect(g_game, { onGameEnd = offline }) -- inside terminate()
And ofc add the function offline().

The other problem you have is rather simple, you need to not only hide the module, but to set buttons to false.
Lua:
AtributosButton:setOn(false) -- add this to hide and offline function
 
Back
Top