Advertisement
jig487

chat_v2

Mar 1st, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
  2.  
  3. local function txt(x,y,t,c)
  4. if c then term.setTextColour(c) end
  5. term.setCursorPos(x,y)
  6. if type(t) == "string" or type(t) =="number" then
  7. write(t)
  8. else
  9. write(textutils.serialise(t))
  10. end
  11. term.setTextColour(colors.white)
  12. end
  13.  
  14. local function stxt(x,y,t,r,c)
  15. if c then term.setTextColour(c) end
  16. term.setCursorPos(x,y)
  17. textutils.slowPrint(t,r)
  18. term.setTextColour(colors.white)
  19. end
  20.  
  21. local function randomPercent(val)
  22. if math.random(100) <= val then
  23. return true
  24. else
  25. return false
  26. end
  27. end
  28.  
  29. local function drawOptionsList(x,y,cursor,list,al)
  30. for i = 1, #list do
  31. local cursStr = "["..i.."] "
  32. local cursCol = al.color
  33. if i == cursor then
  34. cursStr = ">"..i.."< "
  35. cursCol = al.curs
  36. end
  37.  
  38. txt(x,y+i-1,cursStr,cursCol)
  39. txt(x+#cursStr,y+i-1,list[i],al.color)
  40. end
  41. end
  42.  
  43. local function updateCursor(list,cursor)
  44. local _, key = os.pullEvent("key")
  45. local choice = false
  46. if key == keys.up or key == keys.numPad8 then
  47. if cursor > 1 then
  48. cursor = cursor - 1
  49. end
  50. elseif key == keys.down or key == keys.numPad2 then
  51. if cursor < #list then
  52. cursor = cursor + 1
  53. end
  54. elseif key == keys.enter or key == keys.numPadEnter then
  55. choice = tonumber(cursor)
  56. end
  57. return cursor,choice
  58. end
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement