--local movingActive = 673 -- this value is actually not random, but carefully calculated , src value: 0,1484375 local miningActive = 100 function init() if not global.Superhot then global.Superhot = {} end if not global.Superhot.playermovement then global.Superhot.playermovement = {} end end function getDist(mov) return math.sqrt((mov[1] * mov[1]) + (mov[2] * mov[2])) end -- caps the speed using a logarithmic function, is undefined for x <= 0! function movementcap(x) return (75.88 * math.log(x)) + 244 end script.on_event({defines.events.on_tick}, function (e) init() -- init variables TODO: do somewhere else! local activeMax = 0 local lastplayer -- just for DEBUG for index,player in pairs(game.connected_players) do --loop through all online players on the server lastplayer = player if player.valid and player.connected and player.character then local active = 0 -- is mining? if player.mining_state.mining then active = miningActive end --is moving local newpos = player.position local oldpos = global.Superhot.playermovement[player.index] local mov = {0,0} if oldpos ~= nil then mov = {oldpos.x - newpos.x, oldpos.y - newpos.y} local dist = getDist(mov) if dist > 0 then active = active + movementcap(dist) end end --update movement global.Superhot.playermovement[player.index] = newpos --update max if active > activeMax then activeMax = active end end end local goal = activeMax/100.0 local diff = goal - game.speed -- make acceleration smoother if diff > 0.2 or diff < -0.2 then diff = diff / 2.0 end goal = game.speed + diff --clip to upper and lower bound if goal < 0.1 then goal = 0.1 elseif goal > 10 then goal = 10 end --actually set it game.speed = goal end ) -- spped modifyer: game.speed=1 -- freeze time: game.player.surface.freeze_daytime=true -- defines.events.on_pre_player_mined_item