Advertisement
pepeknamornik

Player Core

Dec 24th, 2020 (edited)
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. verze = "20.1224.R1"
  2. local speaker = nil
  3. local tArgs = { ... }
  4. local n = 0
  5. local s = 0
  6. local nastroj = {}
  7.  
  8. nastroje = {
  9.   [1] = "harp",
  10.   [2] = "bass",
  11.   [3] = "basedrum",
  12.   [4] = "bell",
  13.   [5] = "chime",
  14.   [6] = "flute",
  15.   [7] = "hat",
  16.   [8] = "snare",
  17.   [9] = "xylophone",
  18. }
  19.  
  20. local function load(name)
  21.     local file = fs.open(name,"r")
  22.     local data = file.readAll()
  23.     file.close()
  24.     return textutils.unserialize(data)
  25. end
  26.  
  27. if fs.exists("/C/system/RAM/devices/speaker.tmp") then
  28.     speakers = {}
  29.     speakers = load("/C/system/RAM/devices/speaker.tmp")
  30.     speaker = peripheral.wrap(tostring(speakers[0]))
  31.     if speaker == nil then speaker = peripheral.wrap(tostring(speakers[1])) end
  32. else
  33.     speaker = peripheral.find("speaker")
  34. end
  35.  
  36.  
  37. function p(note,s,nas)
  38.         if note > 1 then speaker.playNote(nastroje[nas],1,note) end
  39.         sleep(0.15*s)
  40.     end
  41.    
  42. function play (soubor)
  43.     if fs.exists(soubor) then
  44.            
  45.         file = fs.open(soubor, "r")
  46.                 if file then
  47.                   i = 0
  48.                   while file.readLine() do
  49.                     i = i + 1
  50.                   end
  51.                   file.close()
  52.                 end
  53.        
  54.         file = fs.open(soubor, "r")
  55.        
  56.         for q=1, i do
  57.         radek = file.readLine()
  58.         n = tonumber(string.sub(radek,1,2))
  59.         s = tonumber(string.sub(radek,4,6))
  60.         nastroj = tonumber(string.sub(radek,8,8))
  61.         hlasitost = tonumber(string.sub(radek,10,10))
  62.        
  63.         p(n,s, nastroj)
  64.         end
  65.        
  66.         file.close()
  67.        
  68.     end
  69. end
  70.  
  71.  
  72. if #tArgs > 0 then
  73.     play(tArgs[1])
  74. else
  75.     play(shell.dir().."/nahravka.txt")
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement