zurbo

cc_serialRednet

Dec 20th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local arg= {...}
  2. argData=arg[1]
  3.  
  4. if argData==nil then
  5.  
  6.   data="0000000000000000"
  7.  
  8. elseif #argData>16 then
  9.  
  10.   print("votre donee doit pas contenir plus de 16 bits")
  11.   do return end
  12.  
  13. else
  14.  
  15.   if #argData<16 then
  16.  
  17.     for i=1,16-#argData do
  18.    
  19.       argData="0"..argData
  20.    
  21.     end
  22.  
  23.   end
  24.  
  25.   for i=1,#argData do
  26.  
  27.   ascii=string.byte(argData,i)
  28.  
  29.     if ascii<48 or ascii>49 then
  30.    
  31.       print("la donnee doit etre un nombre binaire")
  32.       do return end
  33.      
  34.     end
  35.  
  36.   end
  37.  
  38.   data=string.reverse(argData)
  39.  
  40. end
  41.  
  42. argTick=arg[2]
  43.  
  44. if argTick==nil then
  45.  
  46.   tick=4
  47.  
  48. else
  49.  
  50.   for i=1,#argTick do
  51.    
  52.     ascii=string.byte(argTick,i)
  53.    
  54.     if ascii<48 or ascii>57 then
  55.      
  56.       print("cette donnee doit etre un nombre")
  57.       do return end
  58.              
  59.     end
  60.      
  61.     tick=(ascii-48)*10^(i-1)
  62.      
  63.   end      
  64.    
  65. end
  66.  
  67. argSideClk=arg[3]
  68. argSideDat=arg[4]
  69.  
  70. if argSideClk==nil or argSideDat==nil then
  71.  
  72.   sideclk="right"
  73.   sidedat="back"
  74.  
  75. elseif (argSideDat~="right" and argSideDat~="left" and argSideDat~="top" and argSideDat~="bottom" and argSideDat~="front" and argSideDat~="back") or (argSideClk~="right" and argSideClk~="left" and argSideClk~="top" and argSideClk~="bottom" and argSideClk~="front" and argSideClk~="back") then
  76.  
  77.   print("cote invalide les cote valides sont: front,back,top,bottom,right,left")
  78.   do return end
  79.  
  80. elseif argSideDat==argSideClk then
  81.  
  82.   print("vous ne pouvez pas envoyer la donnee et l'horloge sur le meme cable redstone")
  83.   do return end
  84.  
  85. elseif peripheral.getType(argSideDat)~="factoryredstonecable" or peripheral.getType(argSideClk)~="factoryredstonecable" then
  86.  
  87.   print("votre cable doit etre un rednet cable venant du mod Mine Factory Reloaded ces cable doivent etre connecte a un programable rednet controler qui effectuera la desserialisation")
  88.   do return end
  89.  
  90. else
  91.  
  92.   sideclk=argSideClk
  93.   sidedat=argSideDat
  94.  
  95. end
  96.  
  97. for i=1,#data do
  98.  
  99.   bit=string.sub(data,i,i)
  100.   redstone.setOutput(sideclk,true)
  101.   os.sleep(tick*0.05)
  102.   redstone.setOutput(sideclk,false)
  103.  
  104.   if bit=="1" then
  105.    
  106.     redstone.setOutput(sidedat,true)
  107.     os.sleep(tick*0.05)
  108.  
  109.   else
  110.    
  111.     redstone.setOutput(sidedat,false)
  112.     os.sleep(tick*0.05)
  113.  
  114.   end
  115.  
  116. end
Advertisement
Add Comment
Please, Sign In to add comment