Utrit

MobHp

Jun 26th, 2019 (edited)
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. function onSave()
  2.   return JSON.encode(MobStats)
  3. end
  4. MobStats={}
  5. function onLoad(save_state)
  6.   IsMobScript = true
  7.   self.UI.setXml(generate())
  8.   if save_state!=nil and save_state!='' then
  9.     MobStats=JSON.decode(save_state)
  10.   else
  11.     MobStats={}
  12.     MobStats.maxhp = 1
  13.     MobStats.curhp = 1
  14.   end
  15.   Wait.frames(function() edit() end, 10)
  16. end
  17. function generate()
  18. gen = "<image id='hpbar1' width='175' height='30' position ='0,-100,-200' color='#ff000066' rotation='-45,0,0'><text id='name1'></text></image>"
  19. gen = gen.."<image id='hpbar2' width='175' height='30' position ='0,100,-200' color='#ff000066' rotation='45,0,180'><text id='name2'></text></image>"
  20. return gen
  21. end
  22. function edit()
  23.     if MobStats.maxhp!=0 then
  24.     proc = MobStats.curhp/MobStats.maxhp
  25.     if proc>1 then
  26.       proc = 1 end
  27.       self.UI.setAttribute('hpbar1', 'width', (#self.getName()*10)..'')
  28.       self.UI.setAttribute('hpbar2', 'width', (#self.getName()*10)..'')
  29.       self.UI.setAttribute('hpbar1', 'color', '#'..gethex((proc*255)..'')..gethex((proc*150)..'')..gethex((proc*150)..'')..'A6')
  30.       self.UI.setAttribute('hpbar2', 'color', '#'..gethex((proc*255)..'')..gethex((proc*150)..'')..gethex((proc*150)..'')..'A6')
  31.     end
  32.     if MobStats.curhp==0 then
  33.     self.UI.setAttribute('name1', 'color', '#cc3333')
  34.     self.UI.setAttribute('name2', 'color', '#cc3333')  
  35.     self.UI.setAttribute('name1', 'text', 'DIE')
  36.     self.UI.setAttribute('name2', 'text', 'DIE')  
  37.   else
  38.     self.UI.setAttribute('name1', 'color', '#222222')
  39.     self.UI.setAttribute('name2', 'color', '#222222')  
  40.     self.UI.setAttribute('name1', 'text', self.getName())
  41.     self.UI.setAttribute('name2', 'text', self.getName())
  42.     end
  43. end
  44. function gethex(val)
  45.   hval = string.format('%x', val)
  46.   if #hval==1 then
  47.     hval='0'..hval end
  48.   return hval
  49. end
Add Comment
Please, Sign In to add comment