Guest User

TTS_StackableStat

a guest
Jan 5th, 2020
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.45 KB | None | 0 0
  1. --[[StartXML
  2.  
  3. <Defaults>
  4.   <Button onClick="onClick" fontSize="80" fontStyle="Bold" textColor="#FFFFFF" color="#000000F0"/>
  5.   <Text fontSize="80" fontStyle="Bold" color="#FFFFFF"/>
  6.   <InputField fontSize="70" color="#000000F0" textColor="#FFFFFF" characterValidation="Integer"/>
  7. </Defaults>
  8.  
  9. <Panel id="panelStat" position="0 0 -180" rotation="270 270 90" scale="0.2 0.2">
  10.   <Panel id="statePanel" height="300" width="-5" position="0 370 0">
  11.     <VerticalLayout>
  12.       <HorizontalLayout spacing="5">
  13.         <Button id="Immobilize" color="#FFFFFF00" active="false"><Image image="Immobilize" preserveAspect="true"></Image><Text id="ImmobilizeText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  14.         <Button id="Wound" color="#FFFFFF00" active="false"><Image image="Wound" preserveAspect="true"></Image><Text id="WoundText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  15.         <Button id="Muddle" color="#FFFFFF00" active="false"><Image image="Muddle" preserveAspect="true"></Image><Text id="MuddleText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  16.         <Button id="Invisible" color="#FFFFFF00" active="false"><Image image="Invisible" preserveAspect="true"></Image><Text id="InvisibleText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  17.         <Button id="Disarm" color="#FFFFFF00" active="false"><Image image="Disarm" preserveAspect="true"></Image><Text id="DisarmText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  18.         <Button id="Strengthen" color="#FFFFFF00" active="false"><Image image="Strengthen" preserveAspect="true"></Image><Text id="StrengthenText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  19.         <Button id="Stun" color="#FFFFFF00" active="false"><Image image="Stun" preserveAspect="true"></Image><Text id="StunText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  20.         <Button id="Poison" color="#FFFFFF00" active="false"><Image image="Poison" preserveAspect="true"></Image><Text id="PoisonText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  21.         <Button id="Curse" color="#FFFFFF00" active="false"><Image image="Curse" preserveAspect="true"></Image><Text id="CurseText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  22.         <Button id="inf_Curse" color="#FFFFFF00" active="false"><Image image="inf_Curse" preserveAspect="true"></Image><Text id="inf_CurseText" visibility="" position="0 200 0" height="100" width="300" text="x0"></Text></Button>
  23.  
  24.       </HorizontalLayout>
  25.     </VerticalLayout>
  26.   </Panel>
  27. </Panel>
  28.  
  29. <Panel id="panel" position="0 -50 -20" rotation="0 0 0" scale="0.2 0.2">
  30.   <Panel id="ressourceBar" position="0 100 0" active="true">
  31.     <ProgressBar id="progressBar" visibility="" height="100" width="600" showPercentageText="false" color="#000000E0" percentage="100" fillImageColor="#710000"></ProgressBar>
  32.     <Text id="hpText" visibility="" height="100" width="600" text="10/10"></Text>
  33.   </Panel>
  34.   <Panel id="ressourceBarS" active="true">
  35.     <ProgressBar id="progressBarS" visibility="" height="100" width="600" showPercentageText="false" color="#000000E0" percentage="100" fillImageColor="#000071"></ProgressBar>
  36.     <Text id="manaText" visibility="" height="100" width="600" text="10/10"></Text>
  37.   </Panel>
  38. </Panel>
  39. StopXML--xml]]
  40.  
  41. statNames = {Immobilize = false, Wound = false, Muddle = false, Invisible = false, Disarm = false, Strengthen = false, Stun = false, Poison = false, Curse = false, inf_Curse = false}
  42.  
  43. function onLoad(save_state)
  44.   local assets = UI.getCustomAssets()
  45.   self.UI.setCustomAssets(assets)
  46.   local script = self.getLuaScript()
  47.   local xml = script:sub(script:find("StartXML")+8, script:find("StopXML")-1)
  48.   self.UI.setXml(xml)
  49.   Wait.frames(load, 10)
  50. end
  51.  
  52. function load()
  53.   for i,j in pairs(statNames) do
  54.     if j == true then
  55.       self.UI.setAttribute(i, "active", true)
  56.     end
  57.   end
  58.   Wait.frames(function() self.UI.setAttribute("statePanel", "width", getStatsCount()*300) end, 1)
  59. end
  60.  
  61. function onClick(player, value, id)
  62.     if statNames[id] ~= nil then
  63.         local word = self.UI.getAttribute(id .. "Text", "text")
  64.         word = word:sub(2)
  65.         word = tonumber(word)
  66.         if (word <=1) then
  67.             word = tonumber(word) - 1
  68.             self.UI.setAttribute(id .. "Text", "text", "x" .. word)
  69.             self.UI.setAttribute(id, "active", false)
  70.             self.UI.setAttribute("statePanel", "width", tonumber(self.UI.getAttribute("statePanel", "width")-300))
  71.             statNames[id] = false
  72.         else
  73.             word = tonumber(word) - 1
  74.             self.UI.setAttribute(id .. "Text", "text", "x" .. word)
  75.         end
  76.     end
  77. end
  78.  
  79. function onCollisionEnter(a)
  80.   local newState = a.collision_object.getName()
  81.   if statNames[newState] ~= nil then
  82.     local word = self.UI.getAttribute(newState .. "Text", "text")
  83.     word = word:sub(2)
  84.     word = tonumber(word) + 1
  85.     self.UI.setAttribute(newState .. "Text", "text", "x" .. word)
  86.     statNames[newState] = true
  87.     a.collision_object.destruct()
  88.     self.UI.setAttribute(newState, "active", true)
  89.     Wait.frames(function() self.UI.setAttribute("statePanel", "width", getStatsCount()*300) end, 1)
  90.   end
  91. end
  92.  
  93. function getStatsCount()
  94.   local count = 0
  95.   for i,j in pairs(statNames) do
  96.     if self.UI.getAttribute(i, "active") == "True" or self.UI.getAttribute(i, "active") == "true" then
  97.       count = count + 1
  98.     end
  99.   end
  100.   return count
  101. end
Advertisement
Add Comment
Please, Sign In to add comment