Advertisement
Guest User

Untitled

a guest
Jan 21st, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. Icons = {}
  2. Icons[1] = { tooltip = tr('You are poisoned'), path = '/images/game/states/poisoned', id = 'condition_poisoned' }
  3. Icons[2] = { tooltip = tr('You are burning'), path = '/images/game/states/burning', id = 'condition_burning' }
  4. Icons[4] = { tooltip = tr('You are electrified'), path = '/images/game/states/electrified', id = 'condition_electrified' }
  5. Icons[8] = { tooltip = tr('You are drunk'), path = '/images/game/states/drunk', id = 'condition_drunk' }
  6. Icons[16] = { tooltip = tr('You are protected by a magic shield'), path = '/images/game/states/magic_shield', id = 'condition_magic_shield' }
  7. Icons[32] = { tooltip = tr('You are paralysed'), path = '/images/game/states/slowed', id = 'condition_slowed' }
  8. Icons[64] = { tooltip = tr('You are hasted'), path = '/images/game/states/haste', id = 'condition_haste' }
  9. Icons[128] = { tooltip = tr('You may not logout during a fight'), path = '/images/game/states/logout_block', id = 'condition_logout_block' }
  10. Icons[256] = { tooltip = tr('You are drowning'), path = '/images/game/states/drowning', id = 'condition_drowning' }
  11. Icons[512] = { tooltip = tr('You are freezing'), path = '/images/game/states/freezing', id = 'condition_freezing' }
  12. Icons[1024] = { tooltip = tr('You are dazzled'), path = '/images/game/states/dazzled', id = 'condition_dazzled' }
  13. Icons[2048] = { tooltip = tr('You are cursed'), path = '/images/game/states/cursed', id = 'condition_cursed' }
  14. Icons[4096] = { tooltip = tr('You are strengthened'), path = '/images/game/states/strengthened', id = 'condition_strengthened' }
  15. Icons[8192] = { tooltip = tr('You may not logout or enter a protection zone'), path = '/images/game/states/protection_zone_block', id = 'condition_protection_zone_block' }
  16. Icons[16384] = { tooltip = tr('You are within a protection zone'), path = '/images/game/states/protection_zone', id = 'condition_protection_zone' }
  17. Icons[32768] = { tooltip = tr('You are bleeding'), path = '/images/game/states/bleeding', id = 'condition_bleeding' }
  18. Icons[65536] = { tooltip = tr('You are hungry'), path = '/images/game/states/hungry', id = 'condition_hungry' }
  19.  
  20. healthInfoWindow = nil
  21. healthBar = nil
  22. manaBar = nil
  23. soulBar = nil
  24. healthLabel = nil
  25. manaLabel = nil
  26. soulLabel = nil
  27.  
  28. function init()
  29. connect(LocalPlayer, { onHealthChange = onHealthChange,
  30. onManaChange = onManaChange,
  31. onStatesChange = onStatesChange,
  32. onExperienceChange = onExperienceChange,
  33. onSkillChange = onSkillChange,
  34. })
  35.  
  36. connect(g_game, { onGameEnd = refresh,onGameStart = begingaem })
  37.  
  38. healthInfoButton = modules.client_topmenu.addRightGameToggleButton('healthInfoButton', tr('Health Information'), '/images/topbuttons/healthinfo', toggle)
  39. healthInfoButton:setOn(true)
  40.  
  41. healthInfoWindow = g_ui.loadUI('healthinfo.otui', modules.game_interface.getRightPanel())
  42. healthInfoWindow:disableResize()
  43. healthBar = healthInfoWindow:recursiveGetChildById('healthBar')
  44. --manaBar = healthInfoWindow:recursiveGetChildById('manaBar')
  45. healthLabel = healthInfoWindow:recursiveGetChildById('healthLabel')
  46. --manaLabel = healthInfoWindow:recursiveGetChildById('manaLabel')
  47. soulBar = healthInfoWindow:recursiveGetChildById('soulBar')
  48. soulLabel = healthInfoWindow:recursiveGetChildById('soulLabel')
  49.  
  50.  
  51. tourLabel = healthInfoWindow:recursiveGetChildById('tourlab')
  52.  
  53.  
  54. expLabel = healthInfoWindow:recursiveGetChildById('expeLabel')
  55. expBar = healthInfoWindow:recursiveGetChildById('expbar')
  56.  
  57. if g_game.isOnline() then
  58. local localPlayer = g_game.getLocalPlayer()
  59. onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
  60. onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
  61. onStatesChange(localPlayer, localPlayer:getStates(), 0)
  62. --onSoulChange(localPlayer, 0)
  63.  
  64. healthInfoWindow:recursiveGetChildById('naem'):setText(localPlayer:getName())
  65. local lavel = healthInfoWindow:recursiveGetChildById('laevl')
  66. lavel:setText(tr('Lvl') .. ': ' .. localPlayer:getLevel())
  67. end
  68.  
  69. healthInfoWindow:setup()
  70. refresh()
  71. begingaem()
  72.  
  73. end
  74. function begingaem()
  75. scheduleEvent(function() refresh() begingaem() end, 1000)
  76. end
  77. function terminate()
  78. disconnect(LocalPlayer, { onHealthChange = onHealthChange,
  79. onManaChange = onManaChange,
  80. onStatesChange = onStatesChange,
  81. onExperienceChange = onExperienceChange,
  82. onSkillChange = onSkillChange, })
  83.  
  84. disconnect(g_game, { onGameEnd = refresh,onGameStart = refresh })
  85.  
  86. healthInfoWindow:destroy()
  87. healthInfoButton:destroy()
  88. healthInfoWindow = nil
  89. healthInfoButton = nil
  90.  
  91. healthBar = nil
  92. manaBar = nil
  93. soulBar = nil
  94. tourLabel =nil
  95. expLabel = nil
  96. expBar= nil
  97. healthLabel = nil
  98. manaLabel = nil
  99. soulLabel = nil
  100.  
  101. HealthInfo = nil
  102. end
  103. function setSkillBase(id, value, baseValue)
  104. if id ~= 2 or id ~= 6 then
  105. return
  106. end
  107. if baseValue <= 0 or value < 0 then
  108. return
  109. end
  110. if id == 2 then
  111. local widget = skillsWindow:recursiveGetChildById("tourlab")
  112.  
  113.  
  114. if value > baseValue then
  115. widget:setColor('#008b00') -- green
  116. skill:setTooltip(baseValue .. ' +' .. (value - baseValue))
  117. elseif value < baseValue then
  118. widget:setColor('#b22222') -- red
  119. skill:setTooltip(baseValue .. ' ' .. (value - baseValue))
  120. else
  121. widget:setColor('#bbbbbb') -- default
  122. skill:removeTooltip()
  123. end
  124. else
  125. local skill = skillsWindow:recursiveGetChildById(id)
  126. local widget = skill:getChildById('value')
  127.  
  128. if value > baseValue then
  129. widget:setColor('#008b00') -- green
  130. skill:setTooltip(baseValue .. ' +' .. (value - baseValue))
  131. elseif value < baseValue then
  132. widget:setColor('#b22222') -- red
  133. skill:setTooltip(baseValue .. ' ' .. (value - baseValue))
  134. else
  135. widget:setColor('#bbbbbb') -- default
  136. skill:removeTooltip()
  137. end
  138. end
  139. end
  140.  
  141. function setSkillValue(id, value)
  142. local skill = skillsWindow:recursiveGetChildById(id)
  143. local widget = skill:getChildById('value')
  144. widget:setText(value)
  145. end
  146.  
  147. function refresh()
  148. local player = g_game.getLocalPlayer()
  149. if not player then return end
  150. healthInfoWindow:recursiveGetChildById('naem'):setText(player:getName())
  151.  
  152. onExperienceChange(player, player:getExperience(),true)
  153.  
  154. onSkillChange(player, 2, player:getSkillLevel(2), player:getSkillLevelPercent(2),true)
  155. onSkillChange(player, 6, player:getSkillLevel(6), player:getSkillLevelPercent(6),true)
  156. local outfitCreature=player:getOutfit()
  157. local outfitCreatureBox = healthInfoWindow:recursiveGetChildById('outfitCreatureBox')
  158. local lavel = healthInfoWindow:recursiveGetChildById('laevl')
  159. lavel:setText(tr('Lvl') .. ': ' .. player:getLevel())
  160. if outfitCreatureBox then
  161. outfitCreatureBox:setCreature(player)
  162. end
  163. if g_game.isOnline() then
  164. local localPlayer = g_game.getLocalPlayer()
  165. onHealthChange(localPlayer, localPlayer:getHealth(), localPlayer:getMaxHealth())
  166. onManaChange(localPlayer, localPlayer:getMana(), localPlayer:getMaxMana())
  167. --onStatesChange(localPlayer, localPlayer:getStates(), 0)
  168. --onSoulChange(localPlayer, 0)
  169.  
  170. healthInfoWindow:recursiveGetChildById('naem'):setText(localPlayer:getName())
  171. end
  172. --toggleIcon(0)
  173.  
  174. end
  175.  
  176. function onExperienceChange(localPlayer, value,hur)
  177. if not hur then
  178. refresh()
  179. end
  180. expLabel:setText(localPlayer:getLevelPercent()..'% ('..value..')')
  181. expBar:setPercent(localPlayer:getLevelPercent())
  182.  
  183. local lavel = healthInfoWindow:recursiveGetChildById('laevl')
  184. lavel:setText(tr('Lvl') .. ': ' .. localPlayer:getLevel())
  185.  
  186. end
  187.  
  188. function onSkillChange(localPlayer, id, level, percent,hur)
  189. if not hur then
  190. refresh()
  191. end
  192. end
  193.  
  194. function toggle()
  195. if healthInfoButton:isOn() then
  196. healthInfoWindow:close()
  197. healthInfoButton:setOn(false)
  198. else
  199. healthInfoWindow:open()
  200.  
  201. healthInfoButton:setOn(true)
  202. refresh()
  203. end
  204. end
  205.  
  206. function hideLabels()
  207. soulLabel:hide()
  208. healthInfoWindow:setHeight(healthInfoWindow:getHeight() - removeHeight)
  209. end
  210.  
  211. function onMiniWindowClose()
  212. healthInfoButton:setOn(false)
  213. end
  214.  
  215. function offline()
  216. healthInfoWindow:recursiveGetChildById('conditionPanel'):destroyChildren()
  217. end
  218.  
  219. -- hooked events
  220. function onHealthChange(localPlayer, health, maxHealth)
  221. healthLabel:setText(health .. ' / ' .. maxHealth)
  222. healthBar:setPercent(health / maxHealth * 100)
  223. end
  224.  
  225. function onManaChange(localPlayer, mana, maxMana)
  226. --manaLabel:setText(mana .. ' / ' .. maxMana)
  227.  
  228. local percent
  229. if maxMana == 0 then
  230. percent = 100
  231. else
  232. percent = (mana * 100)/maxMana
  233. end
  234. if mana <= 6 and mana > -1 then
  235. for i=1,mana do
  236. healthInfoWindow:recursiveGetChildById('call'..i):setImageSource('pokeball.png')
  237. end
  238. for i=mana+1,6 do
  239. if i ~= 0 then
  240. healthInfoWindow:recursiveGetChildById('call'..i):setImageSource('bolas.png')
  241. end
  242. end
  243.  
  244. end
  245. --manaBar:setPercent(percent)
  246. end
  247.  
  248. function onSoulChange(localPlayer, soul)
  249. soulLabel:setText(tr('Catch') .. ': ' .. string.format("%.3d",soul))
  250. end
  251.  
  252.  
  253. function onStatesChange(localPlayer, now, old)
  254. if now == old then return end
  255. local bitsChanged = bit32.bxor(now, old)
  256. for i = 1, 32 do
  257. local pow = math.pow(2, i-1)
  258. if pow > bitsChanged then break end
  259. local bitChanged = bit32.band(bitsChanged, pow)
  260. if bitChanged ~= 0 then
  261. toggleIcon(bitChanged)
  262. end
  263. end
  264. end
  265.  
  266. function toggleIcon(bitChanged)
  267. local content = healthInfoWindow:recursiveGetChildById('conditionPanel')
  268.  
  269. local icon = content:getChildById(Icons[bitChanged].id)
  270. if icon then
  271. icon:destroy()
  272. else
  273. icon = g_ui.createWidget('ConditionWidget', content)
  274. icon:setId(Icons[bitChanged].id)
  275. icon:setImageSource(Icons[bitChanged].path)
  276. icon:setTooltip(Icons[bitChanged].tooltip)
  277. end
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement