Advertisement
ecco7777

CC VR Holodeck

Apr 29th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.29 KB | None | 0 0
  1. function wrapPs(peripheralName)
  2.     periTab={}
  3.     sideTab={}
  4.         if peripheralName==nil then
  5.         print("Fehler")
  6.         end
  7.     local peripherals = peripheral.getNames()
  8.     local i2 = 1
  9.         for i =1, #peripherals do
  10.             if peripheral.getType(peripherals[i])==peripheralName then
  11.                 periTab[i2]=peripheral.wrap(peripherals[i])
  12.                 sideTab[i2]=peripherals[i]
  13.                 i2=i2+1
  14.             end
  15.         end
  16.         if periTab~={} then
  17.             return periTab,sideTab
  18.         else
  19.             return nil
  20.         end
  21. end
  22.  
  23. function scan(s)
  24.     entity={}
  25.     entity.item={}
  26.     entity.mob={}
  27.     entity.player={}
  28.     entity.minecart={}
  29.     entity.itemFrame={}
  30.     mobs=s.getEntityIds("mob")
  31.         for i=1, #mobs do
  32.             data=nil
  33.             data=s.getEntityData(mobs[i],"mob")
  34.                 if data~=nil then
  35.                     entity.mob[i]=data.all()
  36.                 else
  37.                     entity.mob[i]="lost"
  38.                 end
  39.         end
  40.      
  41.     items=s.getEntityIds("item")
  42.         for i=1, #items do
  43.             data=nil
  44.             data=s.getEntityData(items[i],"item")
  45.                 if data~=nil then
  46.                     entity.item[i]=data.all()
  47.                 else
  48.                     entity.item[i]="lost"
  49.                 end
  50.         end
  51.      
  52.     players=s.getPlayers()
  53.         for i=1, #players do
  54.                 data=nil
  55.                 data=s.getPlayerByName(players[i].name)
  56.                     if data~=nil then
  57.                         entity.player[i]=data.all()
  58.                         inv=entity.player[i].player.inventory
  59.                             for i2=1, 40 do
  60.                                 if inv[i2]~=nil then
  61.                                     fp=fs.open("temp","w")
  62.                                     itemp=i
  63.                                     i2temp=i2
  64.                                     error=true
  65.                                     fp.write("entity.player[itemp].player.inventory[i2temp]=inv[i2temp].all() error=false")
  66.                                     fp.close()
  67.                                     shell.run("temp")
  68.                                     shell.run("rm temp")
  69.                                         if error then
  70.                                         entity.player[itemp].player.inventory[i2temp]=nil
  71.                                         end
  72.                                 end
  73.                         end
  74.                     else
  75.                     entity.player[i]="lost"
  76.                     end
  77.         end
  78.      
  79.     minecarts=s.getEntityIds("minecart")
  80.         for i=1, #minecarts do
  81.             data=nil
  82.             data=s.getEntityData(minecarts[i],"minecart")
  83.                 if data~=nil then
  84.                     entity.minecart[i]=data.all()
  85.                 else
  86.                     entity.minecart[i]="lost"
  87.                 end
  88.         end
  89.      
  90.     itemFrames=s.getEntityIds("item_frame")
  91.         for i=1, #itemFrames do
  92.             data=nil
  93.             data=s.getEntityData(itemFrames[i],"item_frame")
  94.                 if data~=nil then
  95.                     entity.itemFrame[i]=data.all()
  96.                 else
  97.                     entity.itemFrame[i]="lost"
  98.                 end
  99.         end
  100.     return entity
  101. end
  102.  
  103. function eval(command)
  104.     fp=fs.open("eval","w")
  105.     fp.writeLine(command)
  106.     fp.close()
  107.     shell.run("eval")
  108.     shell.run("rm eval")
  109. end
  110.  
  111. s=wrapPs("openperipheral_sensor")
  112. p=wrapPs("openperipheral_bridge")
  113. g=p[1]
  114.  
  115. g.clear()
  116.  
  117. function showGrid()
  118.     local x=0
  119.     local y=0
  120.     g.clear()
  121.         while y<=1000 do   
  122.                 while x<=1000 do
  123.                     g.addText(x+1,1,x,0)
  124.                     x=x+50
  125.                 end
  126.             g.addText(1,y+1,y,0)
  127.             y=y+10
  128.         end
  129.     g.sync()
  130. end
  131.  
  132. function showPlayerInfo()
  133.     scan(s[1])
  134.     local y=1
  135.     local i
  136.     g.clear()
  137.         if #entity.player>0 then
  138.             for i=1,#entity.player do
  139.                 local player=entity.player[i]
  140.                     if player.living.lookingAt==nil then
  141.                         player.living.lookingAt={}
  142.                         player.living.lookingAt.position={x=0,y=0,z=0}
  143.                     end
  144.                 content={player.position.x, player.position.y, player.position.z, player.living.yaw, player.living.pitch, player.living.lookingAt.position.x, player.living.lookingAt.position.y, player.living.lookingAt.position.z}
  145.                     for ic=1,#content do
  146.                         g.addText(1,y,content[ic],0)
  147.                         y=y+10
  148.                     end
  149.             end
  150.         g.sync()
  151.         end
  152. end
  153.  
  154. function getPositions()
  155.     scan(s[1])
  156.             pVec={}
  157.             pLookVec={}
  158.             pXAngle={}
  159.             pYAngle={}
  160.         for i=1, #entity.player do
  161.             player=entity.player[i]
  162.             pVec[i]=vector.new(player.position.x, player.position.y, player.position.z)
  163.             pLookVec[i]=vector.new(player.living.lookingAt.position.x, player.living.lookingAt.position.y, player.living.lookingAt.position.z)
  164.             pXAngle[i]=player.living.yaw
  165.             pYAngle[i]=player.living.pitch
  166.         end
  167.     obj=vector.new(0,2,0)
  168. end
  169.  
  170. function setScreenSize(x,y)
  171. screenX=x
  172. screenY=y
  173. end
  174.  
  175. function showObj()
  176.     g.clear()
  177.     getPositions()
  178.     objY=screenY/2
  179.      U=pVec[1]
  180.      O=obj
  181.      UO=O:sub(U)
  182.      UU=U:sub(vector.new(math.cos(pXAngle[1])*U.x,U.y,math.sin(pXAngle[1])*U.z))
  183.      alpha=math.acos((UO:cross(UU))/(UO:length()*UU:length()))
  184.      beta=180-(alpha+90)
  185.      OO=O:sub(vector.new(math.cos(beta)*O.x,O.y,math.sin(beta)*O.z))
  186.     --objX=
  187. end
  188.    
  189. function test()
  190. setScreenSize(950,490)
  191. getPositions()
  192. showObj()
  193. end
  194.  
  195. function main()
  196.     while true do
  197.         showPlayerInfo()
  198.         sleep(0)
  199.     end
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement