Advertisement
stefbrad15

MinecraftParkourTimer

Mar 10th, 2021 (edited)
853
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- By: Stefan B
  2. -- Website: beapython.dev
  3. -- Contact : beapythondev@gmail.com
  4. --
  5. -- youtube.com/beapythondev
  6. -- Youtube Video in progress
  7.  
  8. -- Initialize our variables
  9. cur_split = -1
  10. num_splits = 4
  11. mon_y = 1
  12. mon = peripheral.wrap("right")
  13. total_time = 0
  14. time_start = nil
  15. prev_split_start = nil
  16.  
  17. -- Functions
  18. function inc_mon ()
  19.   mon_y = mon_y + 1
  20.   mon.setCursorPos(1,mon_y)
  21.   return
  22. end
  23.  
  24. -- Initialize our monitor
  25. mon.clear()
  26. mon.setCursorPos(1,mon_y)
  27. mon.write("Parkour Challenge")
  28. inc_mon()
  29. mon.write("Waiting for runner")
  30.  
  31. while true do
  32.   os.pullEvent("redstone") -- wait for a "redstone" event
  33.   split_event = 15 - rs.getAnalogueInput("left")
  34.  
  35.   if rs.getInput("left") then -- check the input
  36.     if cur_split == split_event - 1 then
  37.       if split_event == 0 then
  38.         time_start = os.clock()
  39.         prev_split_start = time_start
  40.         mon.clear()
  41.         mon_y = 1
  42.         total_time = 0
  43.         mon.setCursorPos(1,mon_y)
  44.         mon.write("Parkour Challenge")
  45.         inc_mon()
  46.         mon.write("Good luck runner")
  47.       elseif split_event > 0 then
  48.         cur_time = os.clock()
  49.         split_time = cur_time - prev_split_start
  50.         prev_split_start = cur_time
  51.         total_time = total_time + split_time
  52.         inc_mon()
  53.         mon.write(split_event)
  54.         mon.write(" : ")
  55.         mon.write(string.format("%." .. (2 or 0) .. "f", split_time))
  56.       end
  57.  
  58.       if split_event == num_splits then
  59.         cur_split = -1
  60.         inc_mon()
  61.         inc_mon()
  62.         mon.write("Total time")
  63.         inc_mon()
  64.         mon.write(string.format("%." .. (2 or 0) .. "f", total_time))
  65.         mon.setCursorPos(1,2)
  66.         mon.clearLine()
  67.         mon.write("Waiting for runner")
  68.       else
  69.         cur_split = split_event
  70.       end
  71.     end
  72.   end
  73. end
  74.  
  75.  
Advertisement
RAW Paste Data Copied
Advertisement