Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. function split(s, delimiter)
  2. result = {};
  3. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  4. table.insert(result, match);
  5. end
  6. return result;
  7. end
  8.  
  9. local function redstoneUpdate()
  10.  
  11. local spawnersInactive = {};
  12. for _,spawnerItem in pairs(spawners) do
  13.  
  14. if(not spawnerItem["isActive"]) then
  15.  
  16. local redstoneSpawner = spawnerItem["redstone"];
  17. local spawnerSide = tostring(redstoneSpawner[1]);
  18. local spawnerColor = tonumber(redstoneSpawner[2]);
  19.  
  20. local oldValue = (spawnersInactive[spawnerSide] == nil and 0 or tonumber(spawnersInactive[spawnerSide]));
  21. spawnersInactive[spawnerSide] = oldValue + spawnerColor;
  22. end
  23. end
  24.  
  25. if(#spawnersInactive == 0 then
  26.  
  27. redstone.setBundledOutput("right", 131070);
  28. redstone.setBundledOutput("back", 131070);
  29. else
  30. for side,totalColor in pairs(spawnersInactive) do
  31. redstone.setBundledOutput(side, totalColor);
  32. end
  33. end
  34. end
  35.  
  36. spawners = {
  37. {
  38. name = "Blaze",
  39. isActive = false,
  40. redstone = {"front", colors.yellow}
  41. },
  42. {
  43. name = "Enderman",
  44. isActive = false,
  45. redstone = {"front", colors.black}
  46. }
  47. };
  48.  
  49. redstoneUpdate();
  50.  
  51. local modem = peripheral.wrap("left");
  52. modem.open(3);
  53.  
  54. while true do
  55.  
  56. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message");
  57.  
  58. local args = split(tostring(message), ":");
  59.  
  60. if(message == "spawnerGet") then
  61. modem.transmit(1, 3, spawners);
  62. elseif(message:find("spawnerActivate")) then
  63.  
  64. local indexFuturChange = tonumber(args[2]);
  65. local currentSpawner = spawners[indexFuturChange];
  66.  
  67. spawners[indexFuturChange]["isActive"] = not spawners[indexFuturChange]["isActive"];
  68. redstoneUpdate(spawners);
  69.  
  70. modem.transmit(1, 3, spawners);
  71.  
  72. elseif(message:find("spawnerOff")) then
  73.  
  74. for _,spawner in pairs(spawners) do
  75. spawner["isActive"] = false;
  76. end
  77.  
  78. redstone.setBundledOutput("right", 131070);
  79. redstone.setBundledOutput("back", 131070);
  80.  
  81. modem.transmit(1, 3, spawners);
  82. else
  83. print("ici error");
  84. print(message);
  85. end
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement