Advertisement
Firestorm002

Voting Booth Program v2.0

Aug 13th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. w,h = term.getSize()
  3. modemside = "top"
  4.  
  5. function clear()
  6.   term.clear()
  7. end
  8.  
  9. function write(str,xpos,ypos)
  10.   term.setCursorPos(xpos,ypos)
  11.   term.write(str)
  12. end
  13.  
  14. function printCenter(str,ypos)
  15.   term.setCursorPos(w/2 - #str/2,ypos)
  16.   term.write(str)
  17. end
  18.  
  19. function header(str)
  20.   printCenter(string.rep("-",w),1)
  21.   printCenter(str,3)
  22.   printCenter(string.rep("-",w),5)
  23. end
  24.  
  25. function connect()
  26.   clear()
  27.   term.setTextColor(colors.lime)
  28.   header("<VOTING BOOTH>")
  29.   term.setTextColor(colors.yellow)
  30.   printCenter("<Please click the block below this terminal.>",10)
  31.   ev,user = os.pullEvent("player")
  32. end
  33. while true do
  34.   rednet.open(modemside)
  35.   connect()
  36.   clear()
  37.   rednet.broadcast("needvoter")
  38.   sleep(.1)
  39.   rednet.broadcast(user)
  40.   ev,p1,p2,p3 = os.pullEvent("rednet_message")
  41.   if p2 == "yes" then
  42.     term.setTextColor(colors.red)
  43.     header("<YOU CAN NOT VOTE>")
  44.     term.setTextColor(colors.orange)
  45.     printCenter("You have already voted "..user..".",10)
  46.     sleep(3)
  47.   elseif p2 == "no" then
  48.     term.setTextColor(colors.lime)
  49.     header("<PLACE YOUR VOTE>")
  50.     term.setTextColor(colors.yellow)
  51.     printCenter("Press 'a' to vote for the left option, and",10)
  52.     printCenter("press 'b' to vote for the right option.",11)
  53.     ev,p1,p2,p3 = os.pullEvent("char")
  54.     if p1 == "a" then
  55.       rednet.broadcast("vote1")
  56.     elseif p1 == "b" then
  57.       rednet.broadcast("vote2")
  58.     end
  59.     rednet.broadcast("newvoter")
  60.     sleep(.1)
  61.     rednet.broadcast(user)
  62.     clear()
  63.     term.setTextColor(colors.lime)
  64.     header("<VOTE SENT>")
  65.     term.setTextColor(colors.yellow)
  66.     printCenter("Thanks for voting!",8)
  67.     sleep(3)
  68.   end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement