Advertisement
Cpw1

Factorio Sum Resources

Nov 11th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. /c surface = game.player.surface;
  2. counts = {};
  3. for _, ore in pairs(surface.find_entities_filtered({type="resource"})) do
  4.     if counts[ore.name] == nil then
  5.       counts[ore.name] = 0;
  6.     end
  7.     counts[ore.name] = counts[ore.name] + ore.amount
  8. end
  9. for name, cnt in pairs(counts) do
  10.  
  11.   len = string.len (string.match (cnt, "%d+"));
  12.   if (len >= 1) and (len <= 3) then
  13.     divideBy = 1
  14.   elseif (len >= 4) and (len <= 6) then
  15.     divideBy = 1E3
  16.     numberSize = "K"
  17.   elseif (len >= 7) and (len <= 9) then
  18.     divideBy = 1E6
  19.     numberSize = "M"
  20.   elseif (len >= 10) and (len <= 12) then
  21.     divideBy = 1E9
  22.     numberSize = "B"
  23.   elseif (len >= 13) and (len <= 15) then
  24.     divideBy = 1E12
  25.     numberSize = "T"
  26.   else
  27.     return "number error: " .. str
  28.   end
  29.   str = string.gsub(string.format("%.1f", tonumber(cnt)/divideBy), "%.0", "") .. numberSize;
  30.   game.player.print(surface.name..": ")
  31.   game.player.print(name..": "..str)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement