Advertisement
SyasMaster

piano script inject

Jan 10th, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. require("midi")
  2. print(midi.Open(0))
  3. print(midi.IsOpened())
  4.  
  5. local MIDIKeys = {
  6.     [36] = { Sound = "a1"  }, -- C
  7.     [37] = { Sound = "b1"  },
  8.     [38] = { Sound = "a2"  },
  9.     [39] = { Sound = "b2"  },
  10.     [40] = { Sound = "a3"  },
  11.     [41] = { Sound = "a4"  },
  12.     [42] = { Sound = "b3"  },
  13.     [43] = { Sound = "a5"  },
  14.     [44] = { Sound = "b4"  },
  15.     [45] = { Sound = "a6"  },
  16.     [46] = { Sound = "b5"  },
  17.     [47] = { Sound = "a7"  },
  18.     [48] = { Sound = "a8"  }, -- c
  19.     [49] = { Sound = "b6"  },
  20.     [50] = { Sound = "a9"  },
  21.     [51] = { Sound = "b7"  },
  22.     [52] = { Sound = "a10" },
  23.     [53] = { Sound = "a11" },
  24.     [54] = { Sound = "b8"  },
  25.     [55] = { Sound = "a12" },
  26.     [56] = { Sound = "b9"  },
  27.     [57] = { Sound = "a13" },
  28.     [58] = { Sound = "b10" },
  29.     [59] = { Sound = "a14" },
  30.     [60] = { Sound = "a15" }, -- c'
  31.     [61] = { Sound = "b11" },
  32.     [62] = { Sound = "a16" },
  33.     [63] = { Sound = "b12" },
  34.     [64] = { Sound = "a17" },
  35.     [65] = { Sound = "a18" },
  36.     [66] = { Sound = "b13" },
  37.     [67] = { Sound = "a19" },
  38.     [68] = { Sound = "b14" },
  39.     [69] = { Sound = "a20" },
  40.     [70] = { Sound = "b15" },
  41.     [71] = { Sound = "a21" },
  42.     [72] = { Sound = "a22" }, -- c''
  43.     [73] = { Sound = "b16" },
  44.     [74] = { Sound = "a23" },
  45.     [75] = { Sound = "b17" },
  46.     [76] = { Sound = "a24" },
  47.     [77] = { Sound = "a25" },
  48.     [78] = { Sound = "b18" },
  49.     [79] = { Sound = "a26" },
  50.     [80] = { Sound = "b19" },
  51.     [81] = { Sound = "a27" },
  52.     [82] = { Sound = "b20" },
  53.     [83] = { Sound = "a28" },
  54.     [84] = { Sound = "a29" }, -- c'''
  55.     [85] = { Sound = "b21" },
  56.     [86] = { Sound = "a30" },
  57.     [87] = { Sound = "b22" },
  58.     [88] = { Sound = "a31" },
  59.     [89] = { Sound = "a32" },
  60.     [90] = { Sound = "b23" },
  61.     [91] = { Sound = "a33" },
  62.     [92] = { Sound = "b24" },
  63.     [93] = { Sound = "a34" },
  64.     [94] = { Sound = "b25" },
  65.     [95] = { Sound = "a35" },
  66. }
  67.  
  68. hook.Add("MIDI", "playablePiano", function(time, command, note, velocity)
  69.     local instrument = LocalPlayer().Instrument
  70.     if !IsValid( instrument ) then return end
  71.  
  72.     -- Zero velocity NOTE_ON substitutes NOTE_OFF
  73.     if !midi || midi.GetCommandName( command ) != "NOTE_ON" || velocity == 0 || !MIDIKeys || !MIDIKeys[note] then return end
  74.  
  75.      instrument:OnRegisteredKeyPlayed(MIDIKeys[note].Sound)
  76.  
  77.     net.Start("InstrumentNetwork")
  78.         net.WriteEntity(instrument)
  79.         net.WriteInt(INSTNET_PLAY, 3)
  80.         net.WriteString(MIDIKeys[note].Sound)
  81.     net.SendToServer()
  82. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement