Advertisement
neonerz

dwButton

Mar 17th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. transSide="back"
  2. receiveSide="right"
  3. m = peripheral.wrap("top")
  4. m.clear()
  5. m.setBackgroundColor(colors.black)
  6. trans = peripheral.wrap(transSide)
  7. receive = peripheral.wrap(receiveSide)
  8.  
  9. local button={}
  10.  
  11. --create mob to frequency tables
  12.     mobTableOn = {pig = 4001,
  13.                 angryzombie = 4002,
  14.                 cavespider = 4003,
  15.                 pigman = 4004,
  16.                 chicken = 4005,
  17.                 mooshroom = 4006,
  18.                 skeleton = 4007,
  19.                 blaze = 4008,
  20.                 creeper = 4009,
  21.                 endermen = 4010,
  22.                 witherskeleton = 4011}
  23.     mobTableOff = {pig = 4101,
  24.                 angryzombie = 4102,
  25.                 cavespider = 4103,
  26.                 pigman = 4104,
  27.                 chicken = 4105,
  28.                 mooshroom = 4106,
  29.                 skeleton = 4107,
  30.                 blaze = 4108,
  31.                 creeper = 4109,
  32.                 endermen = 4110,
  33.                 witherskeleton = 4111}
  34.                
  35. function setTable(name, text, xmin, ymin, width, height, onFreq, offFreq)
  36.    button[name] = {}
  37.    button[name]["text"] = text
  38.    button[name]["active"] = false
  39.    button[name]["xmin"] = xmin
  40.    button[name]["ymin"] = ymin
  41.    button[name]["width"] = width
  42.    button[name]["height"] = height
  43.    button[name]["onFreq"] = onFreq
  44.    button[name]["offFreq"] = offFreq
  45. end
  46.  
  47. function toggleButton(name)
  48.    button[name]["active"] = not buttonAPI[name]["active"]
  49. end    
  50.                
  51. function drawButton(x, y, width, height, bcolor, tcolor, text)
  52.     m.setBackgroundColor(bcolor)
  53.     --Draw the background
  54.     for i=1,height do
  55.         m.setCursorPos(x,y+i-1)
  56.         m.write(string.rep(" ", width))
  57.     end
  58. --  m.setBackgroundColor(colors.black)
  59.     --Write the text
  60.      m.setTextColor(tcolor)
  61.     local textX = x + math.floor(width/2 - string.len(text)/2)
  62.     local textY = y + math.floor(height/2)
  63.     m.setCursorPos(textX, textY)
  64.     m.write(text)
  65. end
  66.  
  67. --name, text, xmin, ymin, width, height, onFreq, offFreq
  68. function regButtons()
  69.     setTable("creeper", "Creeper", 2, 1, 7, 1, 4009 ,4109)
  70.     setTable("endermen", "Endermen", 10, 1, 8, 1, 4010 ,4110)
  71.     setTable("angryzombie", "Angry Zombie", 19, 1, 12, 1, 4009,4109)
  72.     setTable("cavespider", "Cave Spider", 32, 1, 11, 1, 4009,4109)
  73.     setTable("pigman", "Pigmen", 44, 1, 6, 1, 4009,4109)
  74.     setTable("witherskeleton", "Wither Skeleton", 2, 3, 15, 1, 4009,4109)
  75.     setTable("skeleton", "Skeleton", 18, 3, 8, 1, 4009,4109)
  76.     setTable("blaze", "Blaze", 27, 3, 5, 1, 4009,4109)
  77.     setTable("mooshroom", "Mooshroom", 33, 3, 9, 1, 4009,4109)
  78.     setTable("chicken", "Chicken", 43, 3, 7, 1, 4009,4109)
  79.     setTable("pig", "Pig", 2, 5, 3, 1, 4009,4109)
  80.     setTable("twmobs", "Twilight Forest Mobs", 6 ,5 ,20 ,1 , 4009,4109)
  81.     setTable("xp_mode", "XP Mode", 43, 5, 7, 1 , 0,0)
  82.  
  83. end
  84.  
  85. function displayGUI()
  86.     m.clear()
  87.     m.setBackgroundColor(colors.black)
  88.     regButtons()
  89.    
  90.     for name,data in pairs(button) do
  91.         print(name.." : "..data)
  92.     end
  93.    
  94. --  drawButton(button["pig"][xmin],button["pig"][ymin],button["pig"][width],button["pig"][height],colors.blue, colors.white,button["pig"][text])
  95.    
  96. --  drawButton(2,1,7,1,colors.blue, colors.white, "Creeper")
  97. --  drawButton(10,1,8,1,colors.blue, colors.white, "Endermen")
  98. --  drawButton(19,1,12,1,colors.blue, colors.white, "Angry Zombie")
  99. --  drawButton(32,1,11,1,colors.blue, colors.white, "Cave Spider")
  100. --  drawButton(44,1,6,1,colors.blue, colors.white, "Pigmen")   
  101.    
  102. --  drawButton(2,3,15,1,colors.blue, colors.white, "Wither Skeleton")
  103. --  drawButton(18,3,8,1,colors.blue, colors.white, "Skeleton")
  104. --  drawButton(27,3,5,1,colors.blue, colors.white, "Blaze")
  105. --  drawButton(33,3,9,1,colors.blue, colors.white, "Mooshroom")
  106. --  drawButton(43,3,7,1,colors.blue, colors.white, "Chicken")  
  107.  
  108. --  drawButton(2,5,3,1,colors.blue, colors.white, "Pig")
  109. --  drawButton(6,5,20,1,colors.blue, colors.white, "Twilight Forest Mobs")
  110.    
  111. --  drawButton(43,5,7,1,colors.lime, colors.white, "XP Mode")
  112.  
  113. end
  114.                
  115. function enableSpawer(mob)
  116.     if checkMobDisabled(mob) then
  117.         trans.setFreq(mobTableOn[mob])
  118.         redstone.setOutput(transSide, true)
  119.         sleep(.4)
  120.         redstone.setOutput(transSide, false)
  121.         print(mob.." enabled")
  122.     else
  123.         print(mob.." already enabled")
  124.     end
  125.     trans.setFreq(0)
  126. end
  127.  
  128. function disableSpawer(mob)
  129.     if checkMobDisabled(mob) then
  130.         print(mob.." already disabled")
  131.     else
  132.         trans.setFreq(mobTableOn[mob])
  133.         redstone.setOutput(transSide, true)
  134.         sleep(.4)
  135.         redstone.setOutput(transSide, false)
  136.         print(mob.." disabled")
  137.     end
  138.     trans.setFreq(0)
  139. end
  140.  
  141. function toggleSpawner(mob)
  142.    
  143. end
  144.  
  145. function checkMobDisabled(mob)
  146.     receive.setFreq(mobTableOff[mob])
  147.     if redstone.getInput(receiveSide) then
  148.         return true
  149.     else
  150.         return false
  151.     end
  152. end
  153.    
  154. function disableAll()
  155.     for k, v in pairs(mobTableOn) do
  156.         disableSpawer(k)
  157.     end
  158. end
  159.  
  160. function xpMode()
  161.  
  162. end
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. tArgs = {...}
  170.  
  171. if tArgs[1] == nil then
  172.     print("Usage: spawner enable|disable <mob>")
  173.     print("Alt Usage: spawner disableAll")
  174.     print("Mob options:")
  175.     for k, v in pairs(mobTableOn) do
  176.         print(k)
  177.         sleep(0.1)
  178.     end
  179. elseif string.lower(tArgs[1]) == "enable" and string.lower(tArgs[2]) ~= nil then
  180.     enableSpawer(string.lower(tArgs[2]))
  181. elseif string.lower(tArgs[1]) == "disable" and tArgs[2] ~= nil then
  182.     disableSpawer(string.lower(tArgs[2]))
  183. elseif string.lower(tArgs[1]) == "disableall" then
  184.     disableAll()
  185. elseif string.lower(tArgs[1]) == "gui" then
  186.     displayGUI()
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement