Export realtime game statistics to disk in JSON and other formats.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

-- ___ _ _ _
-- / __| |_ __ _| |_ ___ _ _(_)___
-- \__ \ _/ _` | _/ _ \ '_| / _ \
-- |___/\__\__,_|\__\___/_| |_\___/
--
-- Defines in-game console commands
-- used to control the metrics list
-- and test new metrics.
commands.add_command("stat", "Used to control metrics in Statorio mod\n[add|list|del] ", function(param)
player = game.players[param.player_index]
if not player then return end
if not player.admin then
player.print("Statorio commands are only available to admins")
return
end
argsArr = split(param.parameter, " ")
if argsArr[1] == "list" or argsArr[1] == "show" then
if table_size(global.statorio.metrics) > 0 then
for index, val in pairs(global.statorio.metrics) do
player.print("["..index.."] "..val)
end
else
player.print("No metrics to show")
end
elseif argsArr[1] == "add" then
if not argsArr[2] then
player.print("Adding requires a metric")
return
end
table.insert(global.statorio.metrics, argsArr[2])
player.print("Added metric ["..table_size(global.statorio.metrics).."]")
elseif argsArr[1] == "del" or argsArr[1] == "rm" then
if not argsArr[2] then
player.print("Deleting requires the index number of a metric from the list command")
return
end
table.remove(global.statorio.metrics, argsArr[2])
player.print("Removed metric ["..argsArr[2].."]")
elseif argsArr[1] == "test" then
if not argsArr[2] then
player.print("Testing requires a metric")
return
end
if not Fetcher.traverseApiForValues(argsArr[2], function(name, val)
player.print(name..": "..safeString(val))
end)
then
player.print("Error - please check API reference")
end
else
player.print("Try list, add, del or test. For example:\n/stat list")
player.print("For more information see https://mods.factorio.com/mod/statorio")
end
end)