Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onSave()
- return JSON.encode(MobStats)
- end
- MobStats={}
- function onLoad(save_state)
- IsMobScript = true
- self.UI.setXml(generate())
- if save_state!=nil and save_state!='' then
- MobStats=JSON.decode(save_state)
- else
- MobStats={}
- MobStats.maxhp = 1
- MobStats.curhp = 1
- end
- Wait.frames(function() edit() end, 10)
- end
- function generate()
- gen = "<image id='hpbar1' width='175' height='30' position ='0,-100,-200' color='#ff000066' rotation='-45,0,0'><text id='name1'></text></image>"
- gen = gen.."<image id='hpbar2' width='175' height='30' position ='0,100,-200' color='#ff000066' rotation='45,0,180'><text id='name2'></text></image>"
- return gen
- end
- function edit()
- if MobStats.maxhp!=0 then
- proc = MobStats.curhp/MobStats.maxhp
- if proc>1 then
- proc = 1 end
- self.UI.setAttribute('hpbar1', 'width', (#self.getName()*10)..'')
- self.UI.setAttribute('hpbar2', 'width', (#self.getName()*10)..'')
- self.UI.setAttribute('hpbar1', 'color', '#'..gethex((proc*255)..'')..gethex((proc*150)..'')..gethex((proc*150)..'')..'A6')
- self.UI.setAttribute('hpbar2', 'color', '#'..gethex((proc*255)..'')..gethex((proc*150)..'')..gethex((proc*150)..'')..'A6')
- end
- if MobStats.curhp==0 then
- self.UI.setAttribute('name1', 'color', '#cc3333')
- self.UI.setAttribute('name2', 'color', '#cc3333')
- self.UI.setAttribute('name1', 'text', 'DIE')
- self.UI.setAttribute('name2', 'text', 'DIE')
- else
- self.UI.setAttribute('name1', 'color', '#222222')
- self.UI.setAttribute('name2', 'color', '#222222')
- self.UI.setAttribute('name1', 'text', self.getName())
- self.UI.setAttribute('name2', 'text', self.getName())
- end
- end
- function gethex(val)
- hval = string.format('%x', val)
- if #hval==1 then
- hval='0'..hval end
- return hval
- end
Add Comment
Please, Sign In to add comment