Advertisement
ecco7777

CC Sensor Entity Display Screen

Oct 18th, 2020 (edited)
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 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.  
  22.     function getPSide(peripheralName)
  23.         if peripheralName == nil then
  24.             print("Fehler")
  25.         end
  26.         local peripherals = peripheral.getNames()
  27.         local i = 1
  28.         while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
  29.             i = i + 1
  30.         end
  31.         if peripheral.getType(peripherals[i]) == peripheralName then
  32.             return peripherals[i]
  33.         else
  34.             return nil
  35.         end
  36.     end
  37. end
  38.  
  39. s=wrapPs("openperipheral_sensor")[1]
  40.  
  41. function scan()
  42. entity={}
  43. entity.item={}
  44. entity.mob={}
  45. entity.player={}
  46. entity.minecart={}
  47. entity.itemFrame={}
  48.  
  49. mobs=s.getEntityIds("mob")
  50. for i=1, #mobs do
  51. data=nil
  52. data=s.getEntityData(mobs[i],"mob")
  53. if data~=nil then
  54. entity.mob[i]=data.all()
  55. else
  56. entity.mob[i]="lost"
  57. end
  58. end
  59.  
  60. items=s.getEntityIds("item")
  61. for i=1, #items do
  62. data=nil
  63. data=s.getEntityData(items[i],"item")
  64. if data~=nil then
  65. entity.item[i]=data.all()
  66. else
  67. entity.item[i]="lost"
  68. end
  69. end
  70.  
  71. players=s.getPlayers()
  72. for i=1, #players do
  73. data=nil
  74. data=s.getPlayerByName(players[i].name)
  75. if data~=nil then
  76. entity.player[i]=data.all()
  77. inv=entity.player[i].player.inventory
  78. for i2=1, 40 do
  79. if inv[i2]~=nil then
  80. fp=fs.open("temp","w")
  81. itemp=i
  82. i2temp=i2
  83. error=true
  84. fp.write("entity.player[itemp].player.inventory[i2temp]=inv[i2temp].all() error=false")
  85. fp.close()
  86. shell.run("temp")
  87. shell.run("rm temp")
  88. if error then
  89. entity.player[itemp].player.inventory[i2temp]=nil
  90. end
  91. end
  92. end
  93. else
  94. entity.player[i]="lost"
  95. end
  96. end
  97.  
  98. minecarts=s.getEntityIds("minecart")
  99. for i=1, #minecarts do
  100. data=nil
  101. data=s.getEntityData(minecarts[i],"minecart")
  102. if data~=nil then
  103. entity.minecart[i]=data.all()
  104. else
  105. entity.minecart[i]="lost"
  106. end
  107. end
  108.  
  109. itemFrames=s.getEntityIds("item_frame")
  110. for i=1, #itemFrames do
  111. data=nil
  112. data=s.getEntityData(itemFrames[i],"item_frame")
  113. if data~=nil then
  114. entity.itemFrame[i]=data.all()
  115. else
  116. entity.itemFrame[i]="lost"
  117. end
  118. end
  119.  
  120. return entity
  121. end
  122.  
  123. function string.cut(txt,char)
  124. while string.find(txt,char) do
  125. txt=string.sub(txt,1,string.find(txt,char)-1)..string.sub(txt,string.find(txt,char)+1,#txt)
  126. end
  127. return txt
  128. end
  129.  
  130.     scanned=scan()
  131.     content=""
  132.     term.clear()
  133.     term.setCursorPos(1,1)
  134.     for i=1,#scanned.mob do
  135.         content=content..", "..scanned.mob[i].name
  136.     end
  137.     print(content)
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement