Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. -- MusPlayer (ver 2.01), you can find more scripts at aionmusic.blogspot.com
  2. -- play_list={"Tree of Savior - Rondo of Tedium","FF XI - Republic Bastok"}
  3. random=true
  4. wsec=2
  5. share=true
  6.  
  7. function s(n)return ("r16"):rep(n) end
  8. function st(n)return "t"..n.." " end
  9.  
  10. sl=_G.LBoxList
  11. r={}w={}z=0
  12. x=coroutine
  13. y=x.resume
  14. ot=os.time
  15. sct=ot()
  16. PS=H.PlaySound
  17. RM=H.RegisterMenu
  18. SI=H.SetInstrument
  19. SP=H.SetPercussion
  20. SA=H.SayAll
  21. msl=nil
  22. msz=0
  23. psz=0
  24. sync=0
  25. mc=0
  26. nm=0
  27. ft=1.0
  28. mn={}
  29. ch_t={}
  30. cur_m=0
  31. cs=nil
  32.  
  33. function prt(s) PS(1,"r8[11]") SA(11,s)end
  34. function v()
  35. repeat
  36. new_m=(cur_m+nm)%msz
  37. if(random)then
  38. repeat
  39. new_m=math.random(0,msz-1)
  40. until(cur_m~=new_m)
  41. end
  42. cur_m=new_m
  43. set_music(cur_m)
  44. nm=1
  45. _i=cs.s_info
  46. PS(0, st(_i.temp).."r1[10]")
  47. H.AlertAll(10, _i.name..". Be patient while channels synchronizing.")
  48. x.yield()
  49. dsync=5
  50. ntry=64
  51. sync=dsync
  52. _ab=0.01
  53. sync_s={}
  54. ctry=0
  55. slnce=st(_i.temp)..s(64)
  56. for c=0,mc do sync_s[c]=st(240).."r64[9]r64r64" end
  57. for c=0,mc do PS(c, slnce) end
  58. repeat
  59. ctry=ctry+1
  60. for c=0,mc do PS(c, sync_s[c])end
  61. if(ctry>ntry)then
  62. _ab=_ab*1.5 ntry=math.max(16,ntry*0.5) ctry=0
  63. SA(9, "Synchronizing...[".._ab.."]")
  64. end
  65. x.yield()
  66. _a=999999999
  67. _b=0
  68. for c=0,mc do _a=math.min(_a,ch_t[c]) _b=math.max(_b,ch_t[c])end
  69. if((_b-_a)<=_ab) then sync=sync-1 else sync=dsync end
  70. until(sync<1)
  71. for c=0,7 do PS(c,r[c])end
  72. x.yield()
  73. until(false)
  74. end
  75.  
  76. u=x.create(v)
  77.  
  78. function search_script(n)
  79. cpl=play_list[(n%psz)+1]
  80. if(type(msl[cpl])=="table")then cs=msl[cpl]else cs=msl[mn[n%msz]]end
  81. end
  82.  
  83. function set_music(n)
  84. if(psz>0)then search_script(n) else cs=msl[mn[n%msz]]end
  85. for c=0,7 do SI(c,0)end
  86. r={}
  87. z=0
  88. if(type(cs.r)=="table")then
  89. local sz=table.getn(cs.r)
  90. for c=1,sz do _tr={cs.r[c]()}
  91. for k,v in pairs(_tr) do if(r[k])then r[k]=r[k].."[1]v10"..v else r[k]=v end end
  92. end
  93. end
  94. if(type(cs.r)=="function")then
  95. r={cs.r()}
  96. end
  97. ft=(240.0/cs.s_info.temp)-0.1
  98. mc=table.getn(r)-1
  99. for c=1,mc+1 do r[c-1]=r[c].."[9]" end
  100. for c=mc+1,7 do r[c]=st(cs.s_info.temp)..s(1024*8)end
  101. end
  102.  
  103. function add_script(s)
  104. if(s and s.s_info and s.s_info.name and (s.r or s.s_info.run))then
  105. _i=s.s_info
  106. _r=s.r
  107. _p=_i.part
  108. _s=msl[_i.name]
  109. if(_s and (not _s.ct or _s.ct<sct))then _s=nil end
  110. if(_i.run)then _r=_i.run end
  111. if(_p)then
  112. if(not _s)then _s={r={},ct=ot()}end
  113. _s.r[_p]=_r
  114. else
  115. _s={r=_r,ct=ot()}
  116. _p=0
  117. end
  118. if(not _i.temp)then _i.temp=120 end
  119. _s.s_info=_i
  120. msl[_i.name]=_s
  121. end
  122. end
  123.  
  124. function f1(k,v)
  125. if(v and v.s_info)then
  126. if(v.s_info.type=="music")then add_script(v)end
  127. if(v.s_info.type=="multi_music" and v.s_info.array)then
  128. sz=table.getn(v.s_info.array)
  129. for j=1,sz do add_script({["s_info"]=v.s_info.array[j],["r"]=v.r})end
  130. end
  131. end
  132. end
  133.  
  134. function f2(k,v)
  135. if(type(v)=="table" and v.s_info and v.s_info.name)then
  136. _h="[-] "
  137. if(v.ct>=sct)then _h="[+] "end
  138. prt(_h..k)
  139. mn[msz]=k
  140. msz=msz+1
  141. end
  142. end
  143.  
  144. function scan()
  145. table.foreach(sl,f1)
  146. table.foreach(msl,f2)
  147. if((psz>0 and psz<3) or msz<3)then random=false end
  148. RM("> Next",2)
  149. if(not random)then RM("> Prev",3)RM("> Repeat",4)end
  150. if(msz>0)then y(u)end
  151. end
  152.  
  153. function OnSoundPlay(a,b,c,d)
  154. if(cs and cs.s_info.onsound)then cs.s_info.onsound(a,b,c,d)end
  155. if(d)then
  156. if(d>0 and d<6)then SI(a,d-1)
  157. elseif(d>20)then SP(a,d-20)end
  158. end
  159. if(d==9)then ch_t[a]=os.clock() z=z+1 if(z>mc)then z=0 y(u)end end
  160. if(d==10)then y(u)
  161. elseif(d==12)then scan()
  162. elseif(d==0 and b and w[b])then
  163. H.GlowNow(w[b],ft/c,255,255,255)
  164. --H.JumpNow(w[b],16.0/(c+7))
  165. end
  166. end
  167.  
  168. function setup()
  169. if((not _G.MPlayer) or (not share))then _G.MPlayer={}end
  170. msl=_G.MPlayer
  171. i=1("cdefgab"):gsub(".",function(c)w[c]=i i=i+1 end)
  172. h_str="MusPlayer (ver 2.01)"
  173. if(random)then h_str=h_str.." [random mode]"end
  174. prt(h_str..":")
  175. if(play_list)then psz=table.getn(play_list)end
  176. if(wsec<=0)then scan()else PS(2,"t120"..s(wsec*8).."[12]")end
  177. end
  178. function OnInit()
  179. H.SetOutletCount(7)
  180. H.EnableSoundCallback(1)
  181. setup()
  182. end
  183.  
  184. function mf(_a)
  185. if(sync<1)then nm=_a y(u)end
  186. end
  187. mfa={0,1,-1,0}
  188. function OnMenu(a)
  189. mf(mfa[a])
  190. end
  191. function OnUserSay(str)
  192. str=str:lower()
  193. if(str=="list")then end
  194. if(str=="next")then mf(1) end
  195. if(not random)then
  196. if(str=="prev")then mf(-1)end
  197. if(str=="try again")then mf(0)end
  198. end
  199. if(str:len()>4)then for m=0,msz-1 do
  200. if(mn[m]:lower():find(str) ~= nil)then cur_m=m tr=random random=false mf(0)random=tr break end end end
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement