Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- --Killing Floor Spawner Touchscreen by neonerZ v1.0
- --http://youtube.com/neonerz
- --
- --Variables
- transSide="back"
- receiveSide="right"
- wirelessModem="top"
- --os.loadAPI("button")
- m = peripheral.wrap("front")
- m.clear()
- m.setBackgroundColor(colors.black)
- trans = peripheral.wrap(transSide)
- receive = peripheral.wrap(receiveSide)
- local button={}
- --Function to create button table
- function setTable(name, text, xmin, ymin, width, height, onFreq, offFreq, bcolor, tcolor)
- button[name] = {}
- button[name]["text"] = text
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["width"] = width
- button[name]["height"] = height
- button[name]["onFreq"] = onFreq
- button[name]["offFreq"] = offFreq
- button[name]["bcolor"] = bcolor
- button[name]["tcolor"] = tcolor
- end
- --Toggle button on and off
- function toggleButton(name, state)
- if state=="on" then
- button[name]["active"] = true
- else
- button[name]["active"] = false
- end
- end
- --Draw button on screen
- function drawButton(x, y, width, height, bcolor, tcolor, text)
- m.setBackgroundColor(bcolor)
- --Draw the background
- for i=1,height do
- m.setCursorPos(x,y+i-1)
- m.write(string.rep(" ", width))
- end
- -- m.setBackgroundColor(colors.black)
- --Write the text
- m.setTextColor(tcolor)
- local textX = x + math.floor(width/2 - string.len(text)/2)
- local textY = y + math.floor(height/2)
- m.setCursorPos(textX, textY)
- m.write(text)
- end
- --Check if a button within the table has been clicked
- --(returns button name if matches, or false if not)
- function checkxy(x, y)
- returnCheckxy=false
- for name, data in pairs(button) do
- if data["height"] == 1 then
- ymax = data["ymin"]
- else
- ymax = data["height"] + data["ymin"]
- end
- if data["width"] == 1 then
- xmax = data["xmin"]
- else
- xmax = data["width"] + data["xmin"]
- end
- if y>=data["ymin"] and y <= ymax then
- if x>=data["xmin"] and x<= xmax then
- returnCheckxy = {name = name,
- text = data["text"],
- onFreq = data["onFreq"],
- offFreq = data["offFreq"],
- bcolor = data["bcolor"],
- tcolor = data["tcolor"],
- active = data["active"]}
- end
- end
- end
- end
- --name, text, xmin, ymin, width, height, onFreq, offFreq, bcolor, tcolor
- --Register buttons
- function regButtons()
- setTable("creeper", "Creeper", 2, 1, 7, 1, 4009 ,4109, colors.blue, colors.white)
- setTable("endermen", "Endermen", 10, 1, 8, 1, 4010 ,4110, colors.blue, colors.white)
- setTable("angryzombie", "Angry Zombie", 19, 1, 12, 1, 4002,4102, colors.blue, colors.white)
- setTable("cavespider", "Cave Spider", 32, 1, 11, 1, 4003,4103, colors.blue, colors.white)
- setTable("pigman", "Pigmen", 44, 1, 6, 1, 4004,4104, colors.blue, colors.white)
- setTable("witherskeleton", "Wither Skeleton", 2, 3, 15, 1, 4011,4111, colors.blue, colors.white)
- setTable("skeleton", "Skeleton", 18, 3, 8, 1, 4007,4107, colors.blue, colors.white)
- setTable("blaze", "Blaze", 27, 3, 5, 1, 4008,4108, colors.blue, colors.white)
- setTable("mooshroom", "Mooshroom", 33, 3, 9, 1, 4006,4106, colors.blue, colors.white)
- setTable("chicken", "Chicken", 43, 3, 7, 1, 4005,4105, colors.blue, colors.white)
- setTable("pig", "Pig", 2, 5, 3, 1, 4001,4101, colors.blue, colors.white)
- setTable("twmobs", "Twilight Forest Mobs", 6 ,5 ,20 ,1 , 4009,4109, colors.blue, colors.white)
- setTable("xp_mode", "XP Mode", 43, 5, 7, 1 , 0,0, colors.red, colors.white)
- end
- --Draw out GUI using the buttons registered in the regButtons function
- function displayGUI()
- m.clear()
- m.setBackgroundColor(colors.black)
- for name,data in pairs(button) do
- -- print(name)
- text=data["text"]
- xmin=data["xmin"]
- ymin=data["ymin"]
- width=data["width"]
- height=data["height"]
- tcolor=data["tcolor"]
- active=data["active"]
- if active == true then
- bcolor = colors.lime
- else
- bcolor=data["bcolor"]
- end
- drawButton(xmin, ymin, width, height, bcolor, tcolor, text)
- end
- end
- --Turns the spawners on
- function enableSpawer(mob)
- toggle="on"
- --If you select XP Mode, make sure to turn off all other mobs first
- --Then turn on the required mobs for XP mode
- if mob=="xp_mode" and button["xp_mode"]["active"] == false then
- disableAll()
- enableSpawer("witherskeleton")
- enableSpawer("pigman")
- -- enableSpawer("angryzombie")
- enableSpawer("mooshroom")
- return
- end
- --Don't allow any other mobs to be activated if XP mode is active
- if button["xp_mode"]["active"] == true and mob~="xp_mode" then
- print("no other mobs allowed when in XP mode")
- toggle="off"
- return
- end
- --If turning on creepers, disable all other mobs
- if mob=="creeper" then
- disableAll()
- elseif button["creeper"]["active"] == true then
- print("no other mobs allowed when in creeper mode")
- toggle="off"
- return
- end
- --Check to see if the mob is disabled before activating it
- -- if running, do nothing, if not, enable it
- if checkMobDisabled(mob) then
- freq = button[mob]["onFreq"]
- trans.setFreq(freq)
- redstone.setOutput(transSide, true)
- sleep(.4)
- redstone.setOutput(transSide, false)
- print(mob.." enabled")
- else
- print(mob.." already enabled")
- end
- trans.setFreq(0)
- end
- --Disable spawners
- function disableSpawer(mob)
- if mob=="xp_mode" then
- print("new test")
- disableAll()
- return
- end
- if checkMobDisabled(mob) and mob~="xp_mode" then
- print(mob.." already disabled")
- else
- freq = button[mob]["onFreq"]
- trans.setFreq(freq)
- redstone.setOutput(transSide, true)
- sleep(.4)
- redstone.setOutput(transSide, false)
- print(mob.." disabled")
- end
- trans.setFreq(0)
- end
- --Check to see if a mob(button) is disabled or not
- --checks offFreq to see if there's a redstone signal
- --if there is, spawner is enabled
- function checkMobDisabled(mob)
- freq = button[mob]["offFreq"]
- receive.setFreq(freq)
- if redstone.getInput(receiveSide) then
- return true
- else
- return false
- end
- end
- --Quick disable all function (used in various parts)
- function disableAll()
- for name,data in pairs(button) do
- if name ~= "xp_mode" then
- disableSpawer(name)
- toggleButton(name,"off")
- end
- end
- end
- tArgs = {...}
- --register buttons and disable all spawners
- --this is necessary as sometimes wireless redstone
- --messes up when the chunks load and some spawners
- --get enabled
- regButtons()
- disableAll()
- --If you run the script without passing a variable
- --show usage commands
- if tArgs[1] == nil then
- print("Usage: spawner enable|disable <mob>")
- print(" spawner gui | spawner disableAll")
- print(" spawner disableAll")
- print("Mob options:")
- for name,data in pairs(button) do
- print(name)
- sleep(0.1)
- end
- --If you send it "spawner enable <mob>" turn just that mob on
- elseif string.lower(tArgs[1]) == "enable" and string.lower(tArgs[2]) ~= nil then
- enableSpawer(string.lower(tArgs[2]))
- --If you send it "spawner disable <mob>", disable just that mob
- elseif string.lower(tArgs[1]) == "disable" and tArgs[2] ~= nil then
- disableSpawer(string.lower(tArgs[2]))
- --If you send it "spawner disableall", disable all mobs
- elseif string.lower(tArgs[1]) == "disableall" then
- disableAll()
- --If you send is "spawner gui", start the script in GUI mode
- elseif string.lower(tArgs[1]) == "gui" then
- --Display GUI and wait for touch input
- displayGUI()
- while true do
- local e, side, x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- if returnCheckxy ~= false then
- --If touch input is detected, and the x,y of the click
- --matches a registered button, and that mob is disabled
- --activate that mob, else deactivate the spawner
- if not returnCheckxy["active"] then
- print(returnCheckxy["name"].." turned on")
- enableSpawer(returnCheckxy["name"])
- toggleButton(returnCheckxy["name"],"on")
- if toggle=="off" then toggleButton(returnCheckxy["name"],"off") end
- m.clear()
- m.setBackgroundColor(colors.black)
- displayGUI()
- else
- print(returnCheckxy["name"].." turned off")
- toggleButton(returnCheckxy["name"],"off")
- disableSpawer(returnCheckxy["name"])
- m.clear()
- m.setBackgroundColor(colors.black)
- displayGUI()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement