Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. -- Local variables
  2. local barWindow = nil
  3. local barPanel = nil
  4. local barButton = nil
  5. local healthBar = nil
  6. local invButton = nil
  7. local pokeHealthTooltip = 'Your pokemon health is %d out of %d.'
  8. local path = '/images/topbuttons/'
  9.  
  10. local InventorySlotStyles = {
  11. [InventorySlotLeg] = "LegSlot",
  12. }
  13. -- End local variables
  14.  
  15. -- Public functions
  16. function init()
  17. connect(g_game, { onGameStart = reload, onGameEnd = reload})
  18. barWindow = g_ui.displayUI('pokeWindow', modules.game_interface.getRootPanel())
  19.  
  20. barButton = modules.client_topmenu.addRightGameToggleButton('BarButton', tr('Pokemon Information'), 'pokeinfo.png', toggle)
  21. barButton:setVisible(true)
  22.  
  23. healthBar = barWindow:recursiveGetChildById("healthBar")
  24.  
  25. connect(LocalPlayer, { onInventoryChange = onInventoryChange})
  26. connect(g_game, {
  27. onGameStart = refresh,
  28. onGameEnd = hide
  29. })
  30. connect(g_game, 'onTextMessage', onPokeHealthChange)
  31. reload()
  32. end
  33.  
  34. function onPokeHealthChange(mode, text)
  35. if not g_game.isOnline() then return end
  36. if mode == MessageModes.Failure then
  37. if string.find(text, '#ph#,') then
  38. local t = text:explode(',')
  39. local hp, maxHp = tonumber(t[2]), tonumber(t[3])
  40. pokeHealthBar:setText(hp .. ' / ' .. maxHp)
  41. barWindow:recursiveGetChildById("pokeHealthIcon"):setTooltip(tr(pokeHealthTooltip, hp, maxHp))
  42. pokeHealthBar:setValue(hp, 0, maxHp)
  43. end
  44. end
  45. end
  46.  
  47. function onInventoryChange(player, slot, item, oldItem)
  48. if slot >= InventorySlotPurse then return end
  49. local itemWidget = barWindow:getChildById('slot' .. slot)
  50. if itemWidget then
  51. if item then
  52. itemWidget:setStyle(InventorySlotStyles[slot])
  53. itemWidget:setItem(item)
  54. else
  55. itemWidget:setStyle(InventorySlotStyles[slot])
  56. itemWidget:setItem(nil)
  57. end
  58. end
  59. end
  60.  
  61.  
  62. --[[ End onChange ]]--
  63.  
  64. function toggle()
  65. if barWindow:isVisible() then
  66. barButton:setIcon(path..'duel icon')
  67. barWindow:setVisible(false)
  68. else
  69. barButton:setIcon(path..'duel icon')
  70. barWindow:setVisible(true)
  71. end
  72. end
  73.  
  74. function changeDir(dir, stop)
  75.  
  76. if stop then
  77. --SendStopWalkAtAll
  78. local protocolGame = g_game.getProtocolGame() if protocolGame then protocolGame:sendExtendedOpcode(36, dir) end
  79. end
  80. local protocolGame = g_game.getProtocolGame() if protocolGame then protocolGame:sendExtendedOpcode(35, dir) end
  81. --SendToChangeDirection
  82. end
  83.  
  84. function startWalk(dir)
  85. if g_keyboard.getModifiers() == KeyboardNoModifier then
  86. --SendToWalkAhead
  87. local protocolGame = g_game.getProtocolGame() if protocolGame then protocolGame:sendExtendedOpcode(37, dir) end
  88. end
  89. end
  90.  
  91. function refresh()
  92. if barWindow:isVisible() then
  93. barButton:setIcon(path..'duel icon')
  94. end
  95. online()
  96. local player = g_game.getLocalPlayer()
  97. for i=InventorySlotFirst,InventorySlotLast do
  98. if g_game.isOnline() then
  99. onInventoryChange(player, i, player:getInventoryItem(i))
  100. else
  101. onInventoryChange(player, i, nil)
  102. end
  103. end
  104. end
  105.  
  106. function online()
  107. local player = g_game.getLocalPlayer()
  108. if g_game.isOnline() then
  109. barButton:setVisible(true)
  110. end
  111. end
  112.  
  113. function hide()
  114. barButton:setVisible(false)
  115. barWindow:setVisible(false)
  116. end
  117.  
  118. function reload()
  119. barWindow:setVisible(g_game.isOnline())
  120. end
  121.  
  122. function onMiniWindowClose()
  123. end
  124. -- End public functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement