Advertisement
grand_mind1

Potion Shop

Oct 11th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.53 KB | None | 0 0
  1. os.loadAPI("btn")
  2. modemSide = "top"
  3. useSplash = false
  4. brewerID = 82
  5. rednet.open(modemSide)
  6.  
  7. --function that draws all the buff potions
  8. local function buffs()
  9.     btn.deActivateAllDraw()
  10.     btn.activateDraw("strength")
  11.     btn.activateDraw("speed")
  12.     btn.activateDraw("fireResist")
  13.     btn.activateDraw("healing")
  14.     btn.activateDraw("nightVision")
  15.     btn.activateDraw("invisible")
  16.     btn.activateDraw("regen")
  17.     btn.activateDraw("back")
  18.     btn.changeText("back","Back")
  19.     btn.changePos("back",1,7,17,19)
  20.     term.clear()
  21.     btn.createScreen("Buff Potions", colors.white)
  22.     backTo = "main"
  23. end
  24.  
  25. -- function that activates all offensive potions
  26. local function offensive()
  27.     btn.deActivateAllDraw()
  28.     btn.activateDraw("slowness")
  29.     btn.activateDraw("poison")
  30.     btn.activateDraw("harming")
  31.     btn.activateDraw("weakness")
  32.     btn.activateDraw("back")
  33.     btn.changeText("back","Back")
  34.     btn.changePos("back",1,7,17,19)
  35.     term.clear()
  36.     btn.createScreen("Offensive Potions", colors.white)
  37.     backTo = "main"
  38. end
  39.  
  40. --function that draws the main menu
  41. local function mainMenu()
  42.     btn.deActivateAllDraw()
  43.     btn.activateDraw("buffs")
  44.     btn.activateDraw("offensive")
  45.     term.clear()
  46.     btn.createScreen("Select a Category",colors.white)
  47. end
  48.  
  49. --function called when the back button is pressed
  50. local function back()
  51.     if backTo == "main" then
  52.         mainMenu()
  53.     elseif backTo == "offensive" then
  54.         offensive()
  55.         btn.deActivate("splash")
  56.         useSplash = false
  57.         btn.changePos("iDur",12,40,8,12)
  58.         btn.changePos("norm",12,40,14,18)
  59.         btn.changePos("iPotency",12,40,2,6)
  60.         btn.changeText("back","Back")
  61.         btn.changePos("back",1,7,17,19)
  62.     elseif backTo == "buffs" then
  63.         buffs()
  64.         btn.deActivate("splash")
  65.         useSplash = false
  66.         btn.changePos("iDur",12,40,8,12)
  67.         btn.changePos("norm",12,40,14,18)
  68.         btn.changePos("iPotency",12,40,2,6)
  69.     end
  70.     btn.changeText("back","Back")
  71. end
  72.  
  73. --function called when splash button is pressed
  74. local function splash()
  75.     useSplash = not useSplash
  76.     btn.toggle("splash")
  77. end
  78.  
  79. --function called when a potion button is pressed
  80. local function potion(name)
  81.     btn.deActivateAllDraw()
  82.     color = btn.getColor(name)
  83.     potionName = btn.getText(name)
  84.     btn.changeColor("iPotency",color)
  85.     btn.changeColor("iDur",color)
  86.     btn.changeColor("norm",color)
  87.     if name == "speed" or name == "poison" or name == "strength" or name == "regen" then
  88.         btn.activateDraw("iPotency")
  89.     else
  90.         btn.changePos("iDur",12,40,3,7)
  91.         btn.changePos("norm",12,40,11,15)
  92.     end
  93.     btn.activateDraw("iDur")
  94.     btn.activateDraw("norm")
  95.     btn.activateDraw("splash")
  96.     btn.activateDraw("back")
  97.    
  98.     term.clear()
  99.     btn.createScreen("Select Variation of potion",colors.white)
  100.     if name == "slowness" or name == "poison" or name == "harming" or name == "weakness" then
  101.         backTo = "offensive"
  102.     else
  103.         backTo = "buffs"
  104.     end
  105. end
  106.  
  107. local function orderScreen(name)
  108.     btn.deActivateAllDraw()
  109.     term.clear()
  110.     btn.changeText("back"," Cancel")
  111.     btn.changePos("back",1,8,17,19)
  112.     btn.activateDraw("back")
  113.     btn.activateDraw("order")
  114.     if potionName ~= "Fire Resist" and potionName ~= "Healing" then
  115.         if potionName == "  Speed" then
  116.             begin = 3
  117.         else
  118.             begin = 2
  119.         end
  120.         nameLength = string.len(potionName)
  121.         potionName = string.sub(potionName,begin,nameLength)
  122.     end
  123.     btn.createScreen("Order Screen",colors.white)
  124.     btn.centerText(5,"Your order:",colors.white)
  125.     btn.centerText(6,"1 Potion of: "..potionName,colors.white)
  126.     if name == "iPotency" then
  127.         iPotency = true
  128.         btn.centerText(7,"With Increased Potency",colors.white)
  129.     elseif name == "iDur" then
  130.         iDur = true
  131.         btn.centerText(7,"With Increased Duration",colors.white)
  132.     end
  133.     if useSplash == true then
  134.         btn.centerText(8,"Splash Potion",colors.white)
  135.     end
  136. end
  137.  
  138. local function progressScreen()
  139.     term.clear()
  140.     time = 7
  141.     btn.centerText(6,"Brewing...",colors.white)
  142.     btn.centerText(7,"Estimated time: "..time, colors.white)
  143. end
  144.  
  145. local function order(potion, useSplash)
  146.     progressScreen()
  147.     rednet.send(brewerID, potion.." "..useSplash)
  148. end
  149.  
  150. --category buttons
  151. btn.fillTable("buffs",12,40,3,7,"Buff Potions",buffs,colors.red,false)
  152. btn.fillTable("offensive",12,40,11,15,"Offensive Potions",offensive,colors.green,false)
  153.  
  154. --buff potions
  155. btn.fillTable("strength",8,17,2,6," Strength",potion,colors.purple,false)
  156. btn.fillTable("speed",34,44,2,6,"  Speed",potion,colors.lightBlue,false)
  157. btn.fillTable("fireResist",19,32,2,6,"Fire Resist",potion,colors.orange,false)
  158. btn.fillTable("healing",8,17,8,12,"Healing",potion,colors.red,false)
  159. btn.fillTable("nightVision",19,32,8,12," Night Vision",potion,colors.blue,false)
  160. btn.fillTable("invisible",19,32,14,18," Invisibility",potion,colors.lightGray,false)
  161. btn.fillTable("regen",34,44,8,12," Regen",potion,colors.magenta,false)
  162.  
  163. --offensive potions
  164. btn.fillTable("slowness",19,32,3,7," Slowness",potion,colors.lightGray,false)
  165. btn.fillTable("poison",8,17,3,7," Poison",potion,colors.green,false)
  166. btn.fillTable("harming",34,44,3,7," Harming",potion,colors.purple,false)
  167. btn.fillTable("weakness",19,32,9,13," Weakness",potion,colors.gray,false)
  168.  
  169. --variation buttons
  170. btn.fillTable("iPotency", 12,40,2,6,"Increased Potency",orderScreen,color,false)
  171. btn.fillTable("iDur", 12,40,8,12,"Increased Duration",orderScreen,color,false)
  172. btn.fillTable("norm",12,40,14,18,"Normal Potion",orderScreen,color,false)
  173. btn.fillTable("splash",1,8,1,3,"Splash",splash,nil,false)
  174.  
  175. --misc buttons
  176. btn.fillTable("back",1,7,17,19," Back",back,colors.red,false)
  177. btn.fillTable("order",44,51,17,19," Order",order,colors.red,false)
  178.  
  179. mainMenu()
  180. while true do
  181.     event, button, x, y = os.pullEvent("mouse_click")
  182.     btn.checkClick(x,y)
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement