Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function split(s, delimiter)
- result = {};
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- local function redstoneUpdate()
- local spawnersInactive = {};
- for _,spawnerItem in pairs(spawners) do
- if(not spawnerItem["isActive"]) then
- local redstoneSpawner = spawnerItem["redstone"];
- local spawnerSide = tostring(redstoneSpawner[1]);
- local spawnerColor = tonumber(redstoneSpawner[2]);
- local oldValue = (spawnersInactive[spawnerSide] == nil and 0 or tonumber(spawnersInactive[spawnerSide]));
- spawnersInactive[spawnerSide] = oldValue + spawnerColor;
- end
- end
- if(#spawnersInactive == 0 then
- redstone.setBundledOutput("right", 131070);
- redstone.setBundledOutput("back", 131070);
- else
- for side,totalColor in pairs(spawnersInactive) do
- redstone.setBundledOutput(side, totalColor);
- end
- end
- end
- spawners = {
- {
- name = "Blaze",
- isActive = false,
- redstone = {"front", colors.yellow}
- },
- {
- name = "Enderman",
- isActive = false,
- redstone = {"front", colors.black}
- }
- };
- redstoneUpdate();
- local modem = peripheral.wrap("left");
- modem.open(3);
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message");
- local args = split(tostring(message), ":");
- if(message == "spawnerGet") then
- modem.transmit(1, 3, spawners);
- elseif(message:find("spawnerActivate")) then
- local indexFuturChange = tonumber(args[2]);
- local currentSpawner = spawners[indexFuturChange];
- spawners[indexFuturChange]["isActive"] = not spawners[indexFuturChange]["isActive"];
- redstoneUpdate(spawners);
- modem.transmit(1, 3, spawners);
- elseif(message:find("spawnerOff")) then
- for _,spawner in pairs(spawners) do
- spawner["isActive"] = false;
- end
- redstone.setBundledOutput("right", 131070);
- redstone.setBundledOutput("back", 131070);
- modem.transmit(1, 3, spawners);
- else
- print("ici error");
- print(message);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement