local keepOnline = 23 local maxChange = 2 local minOnline = 2 local maxOnline = 35 function onThink(interval, lastExecution, thinkInterval) if(getStorage(1666) ~= -1) then keepOnline = getStorage(1666) doSetStorage(1666, -1) print("Changed bots number to: " .. keepOnline) end if(getStorage(1667) ~= -1) then minOnline = getStorage(1667) doSetStorage(1667, -1) print("Changed min bots number to: " .. minOnline) end if(getStorage(1668) ~= -1) then maxOnline = getStorage(1668) doSetStorage(1668, -1) print("Changed max bots number to: " .. maxOnline) end if(math.random(1,4) == 2) then keepOnline = math.min(maxOnline, math.max(keepOnline+math.random(-1,1), minOnline)) end local online = getPlayersOnline() local botsOnline = {} local botsOffline = {} local playersOnline = {} for _, cid in pairs(online) do doPlayerFeed(cid, 9999) if(isBot(cid) and isBotActive(cid)) then table.insert(botsOnline, cid) elseif(not isBot(cid)) then table.insert(playersOnline, cid) else table.insert(botsOffline, cid) end end print("BOTS: " .. #botsOnline .. " (" .. keepOnline .. "), P: " .. #playersOnline) if(#playersOnline+#botsOnline > keepOnline) then if(#botsOnline > 0) then local toRemove = math.min(maxChange, #playersOnline+#botsOnline-keepOnline) for i = 1, toRemove do for i, bot in pairs(botsOnline) do if(getTileInfo(getThingPosition(bot)).protection) then setBotActive(bot, false) table.remove(botsOnline, i) break end end end end elseif(#playersOnline+#botsOnline < keepOnline) then for i = 1, maxChange do if(#playersOnline+#botsOnline+i <= keepOnline) then local bot = botsOffline[math.random(1,#botsOffline)] setBotActive(bot, true) end end end return true end function setBotDelayed(name) setBot(getPlayerByName(name), 1) setBotActive(getPlayerByName(name), false) end function onStartup() for i=1,200 do loadPlayer(getBotNameByID(i)) addEvent(setBotDelayed, 1000, getBotNameByID(i)) end return true end