Advertisement
NuAoA

serverRules

Mar 1st, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. local p = peripheral.wrap("top")
  2. local mon = peripheral.wrap("front")
  3. os.loadAPI("Draw")
  4.  
  5. function getHTTP()
  6. return http.get("https://raw.github.com/AlienMC/AlienMC-FTBSubreddit-Public-Server/master/Server%20Rules.md")
  7. end
  8. function getxy(x,y,ang)
  9. ang = ang*0.0174532925
  10. local l = (1-x)/math.sin(ang)
  11. return (x+l*math.sin(ang)),(y+l*math.cos(ang)),l
  12. end
  13. function deepcopy(orig)
  14. local orig_type = type(orig)
  15. local copy
  16. if orig_type == 'table' then
  17. copy = {}
  18. for orig_key, orig_value in next, orig, nil do
  19. copy[deepcopy(orig_key)] = deepcopy(orig_value)
  20. end
  21. setmetatable(copy, deepcopy(getmetatable(orig)))
  22. else -- number, string, boolean, etc
  23. copy = orig
  24. end
  25. return copy
  26. end
  27. function notLooking()
  28. mon.setTextScale(5)
  29. local xmax,ymax = mon.getSize()
  30. local tc,tt = Draw.emptyScreen(mon,xmax,ymax)
  31. Draw.tc(tc,1,1,colors.black,xmax,ymax)
  32. Draw.tt(tt,1,3," READ THE",colors.red)
  33. Draw.tt(tt,1,4," DAMN RULES",colors.red)
  34. Draw.draw(mon,tc,1,1,colors.black,tt)
  35. end
  36.  
  37. function getAndParseRules()
  38. local rules = getHTTP()
  39. local tt = {}
  40. local line = ""
  41. while line ~= nil do
  42. line = rules.readLine()
  43. if line ~= nil then
  44. line = string.gsub(line,"<b>","&"..Draw.getHexOf(colors.red))
  45. line = string.gsub(line,"</b>"," &"..Draw.getHexOf(colors.lime))
  46. line = string.gsub(line,"<li>","")
  47. line = string.gsub(line,"<%S+>","")
  48. line = string.gsub(line,"<a %S+>","")
  49. table.insert(tt,line)
  50. end
  51. end
  52. return deepcopy(tt)
  53. end
  54.  
  55. function looking()
  56. mon.setTextScale(1)
  57. local xmax,ymax = mon.getSize()
  58. local tc = Draw.emptyScreen(mon,xmax,ymax)
  59. Draw.tc(tc,1,1,colors.black,xmax,ymax)
  60. Draw.draw(mon,tc,1,1,colors.black,tt2)
  61. end
  62.  
  63. function parse(v)
  64. tab = p.getPlayerData(v)
  65. local x,y,l = getxy(-1*tab.position.x,tab.position.z,tab.yaw)
  66. if math.ceil(y) >1 or math.floor(y) < -7 then --or tab.position.x<1 then
  67. notLooking()
  68. else
  69. looking()
  70. end
  71. end
  72. tt2 = getAndParseRules()
  73. while true do
  74. sleep(0.2)
  75. local iter = 1
  76. for k,v in pairs(p.getPlayerNames()) do
  77. iter = iter+1
  78. parse(v)
  79. end
  80. if iter==1 then sleep(1) print("sleep") end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement