bobmarley12345

ShopDirectory_WEST

Feb 25th, 2022 (edited)
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. Shop_L1 = { x = -1726, y = 30, z = 30 }
  2. Shop_L2 = { x = -1710, y = 30, z = 30 }
  3. Shop_L3 = { x = -1692, y = 30, z = 30 }
  4. Shop_L4 = { x = -1674, y = 30, z = 30 }
  5. Shop_L5 = { x = -1656, y = 30, z = 30 }
  6. Shop_R1 = { x = -1726, y = 30, z = -8 }
  7. Shop_R2 = { x = -1710, y = 30, z = -8 }
  8. Shop_R3 = { x = -1692, y = 30, z = -8 }
  9. Shop_R4 = { x = -1674, y = 30, z = -8 }
  10. Shop_R5 = { x = -1656, y = 30, z = -8 }
  11. Shop_H1 = { x = -1731, y = 38, z = 18 }
  12. Shop_H2 = { x = -1731, y = 38, z = 4 }
  13.  
  14. direction = "bottom"
  15. const_rent = "FOR RENT"
  16.  
  17. function getText(sign, line)
  18.     if (line == nil) then
  19.         line = 0
  20.     end
  21.     -- use sign.x, etc
  22.     return adminapi.getSignLine("PlayerShop", sign.x, sign.y, sign.z, line)
  23. end
  24.  
  25. function string.jsub(str, startIndex, endIndex)
  26.     if (endIndex == nil) then
  27.         endIndex = string.len(str) + 1
  28.     end
  29.    
  30.     return string.sub(str, startIndex, endIndex - 1)
  31. end
  32.  
  33. function cpos(x, y)
  34.     monitor.setCursorPos(x, y)
  35. end
  36. function writeText(x, y, text)
  37.     cpos(x, y)
  38.     monitor.write(text)
  39. end
  40.  
  41. function writeTextColour(x, y, text, brush)
  42.     cpos(x, y)
  43.     monitor.setTextColour(brush)
  44.     monitor.write(text)
  45.     monitor.setTextColour(colours.white)
  46. end
  47.  
  48. function writeCentered(x1, x2, y, text)
  49.     local len = string.len(text)
  50.     local mid = math.ceil(x1 + ((x2 - x1) / 2))
  51.     local startX = mid - (len / 2)
  52.     writeText(startX, y, text)
  53. end
  54.  
  55. function writeCenteredColour(x1, x2, y, text, brush)
  56.     local len = string.len(text)
  57.     local mid = math.ceil(x1 + ((x2 - x1) / 2))
  58.     local startX = mid - (len / 2)
  59.     writeTextColour(startX, y, text, brush)
  60. end
  61.  
  62. function drawLineV(x, y, height, brush)
  63.     for i = y, height, 1 do
  64.         writeTextColour(x, i, "|", brush)
  65.     end
  66. end
  67.  
  68. function drawLineH(x, y, width, brush)
  69.     for i = x, width, 1 do
  70.         writeTextColour(i, y, "-", brush)
  71.     end
  72. end
  73.  
  74. function writeSignTop(sign, x1, x2, y)
  75.     local text = string.jsub(getText(sign), 3)
  76.     local brush = colours.orange
  77.     if (text == const_rent) then
  78.         brush = colours.green
  79.     else
  80.         text = string.jsub(getText(sign, 3), 3)
  81.     end
  82.    
  83.     writeCenteredColour(x1, x2, y, text, brush)
  84. end
  85.  
  86. function writeSignLeft(sign, y, w, h)
  87.     local text = string.jsub(getText(sign), 3)
  88.     local brush = colours.orange
  89.     if (text == const_rent) then
  90.         brush = colours.green
  91.     else
  92.         text = string.jsub(getText(sign, 3), 3)
  93.     end
  94.    
  95.     writeTextColour(2, y, text, brush)
  96. end
  97.  
  98. function writeSignRight(sign, y, w, h)
  99.     local text = string.jsub(getText(sign), 3)
  100.     local len = string.len(text)
  101.     local brush = colours.orange
  102.     if (text == const_rent) then
  103.         brush = colours.green
  104.     else
  105.         text = string.jsub(getText(sign, 3), 3)
  106.     end
  107.  
  108.     writeTextColour(w - len, y, text, brush)
  109. end
  110.  
  111. function main()
  112.     monitor = peripheral.wrap(direction)
  113.     cpos(1,1)
  114.     monitor.clear()
  115.     local w,h = monitor.getSize()
  116.  
  117.     monWidth = w
  118.     monHeight = h
  119.  
  120.     yOff = 2
  121.     mid = (w / 2)
  122.     gap = 2
  123.  
  124.     while (true) do
  125.         local i = 0
  126.         drawLineV(mid, 1, h, colours.red)
  127.         drawLineH(1, 4, w, colours.red)
  128.         writeSignTop(Shop_H1, 2, mid - 2, 2)
  129.         writeSignTop(Shop_H2, mid + 2, w - 2, 2)
  130.         writeSignLeft(Shop_L1, yOff + 4, w, h)
  131.         writeSignLeft(Shop_L2, yOff + 8, w, h)
  132.         writeSignLeft(Shop_L3, yOff + 12, w, h)
  133.         writeSignLeft(Shop_L4, yOff + 16, w, h)
  134.         writeSignLeft(Shop_L5, yOff + 20, w, h)
  135.         writeSignRight(Shop_R1, yOff + 4, w, h)
  136.         writeSignRight(Shop_R2, yOff + 8, w, h)
  137.         writeSignRight(Shop_R3, yOff + 12, w, h)
  138.         writeSignRight(Shop_R4, yOff + 16, w, h)
  139.         writeSignRight(Shop_R5, yOff + 20, w, h)
  140.         os.sleep(10)
  141.     end
  142. end
  143.  
  144. main()
  145.  
Add Comment
Please, Sign In to add comment