Advertisement
ecco7777

me logger

Feb 25th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. function wrapP(peripheralName)
  2. if peripheralName==nil then
  3. print("Fehler")
  4. end
  5. local peripherals = peripheral.getNames()
  6. local i = 1
  7. while i < #peripherals and peripheral.getType(peripherals[i])~=peripheralName do
  8. i=i+1
  9. end
  10. if peripheral.getType(peripherals[i])==peripheralName then
  11. return peripheral.wrap(peripherals[i])
  12. else
  13. return nil
  14. end
  15. end
  16.  
  17. function listItems(me)
  18. itemsTab=me.listItems()
  19. itemsRaw=textutils.serialize(itemsTab)
  20. i=1
  21. items={}
  22. itemName={}
  23. while string.find(itemsRaw,",") do
  24. items[i]=tonumber(string.sub(itemsRaw,string.find(itemsRaw,"{")+2,string.find(itemsRaw,"]")-1))
  25. itemsRaw="{"..string.sub(itemsRaw,string.find(itemsRaw,",")+1)
  26. i=i+1
  27. end
  28. end
  29.  
  30. function say(message)
  31. print(message)
  32. if c~=nil then
  33. c.say(message)
  34. end
  35. end
  36.  
  37. me=wrapP("meBridge")
  38. c=wrapP("chat")
  39.  
  40. function main()
  41. listItems(me)
  42. list2=itemsTab
  43. list2Sort=items
  44. while true do
  45. list1=list2
  46. list1Sort=list2Sort
  47. sleep(1) say("debug")
  48. listItems(me)
  49. list2=itemsTab
  50. list2Sort=items
  51. if textutils.serialize(list1)~=textutils.serialize(list2) then
  52.  
  53. for i=1,#list1Sort do
  54. if list2[list1Sort[i]]==nil then
  55. id=math.fmod(list1Sort[i],32768)
  56. dmg=math.floor(list1Sort[i]/32768)
  57. say(tostring(id)..":"..tostring(dmg).." wurde dem System entnommen")
  58. end
  59. end
  60.  
  61. for i=1,#list2Sort do
  62. if list1[list2Sort[i]]==nil then
  63. id=math.fmod(list2Sort[i],32768)
  64. dmg=math.floor(list2Sort[i]/32768)
  65. say(tostring(id)..":"..tostring(dmg).." wurde dem System hinzugefügt")
  66. end
  67. end
  68.  
  69. end
  70. end
  71. end
  72.  
  73. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement