Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /c surface = game.player.surface;
- counts = {};
- for _, ore in pairs(surface.find_entities_filtered({type="resource"})) do
- if counts[ore.name] == nil then
- counts[ore.name] = 0;
- end
- counts[ore.name] = counts[ore.name] + ore.amount
- end
- for name, cnt in pairs(counts) do
- len = string.len (string.match (cnt, "%d+"));
- if (len >= 1) and (len <= 3) then
- divideBy = 1
- elseif (len >= 4) and (len <= 6) then
- divideBy = 1E3
- numberSize = "K"
- elseif (len >= 7) and (len <= 9) then
- divideBy = 1E6
- numberSize = "M"
- elseif (len >= 10) and (len <= 12) then
- divideBy = 1E9
- numberSize = "B"
- elseif (len >= 13) and (len <= 15) then
- divideBy = 1E12
- numberSize = "T"
- else
- return "number error: " .. str
- end
- str = string.gsub(string.format("%.1f", tonumber(cnt)/divideBy), "%.0", "") .. numberSize;
- game.player.print(surface.name..": ")
- game.player.print(name..": "..str)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement