1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/utils/utils.lua

37 lines
757 B
Lua
Raw Normal View History

2018-04-06 21:58:50 +02:00
local Event = require "utils.event"
2018-06-02 18:16:04 +02:00
local Module = {}
2017-06-13 13:16:07 +02:00
2018-06-02 18:16:04 +02:00
Module.distance = function(pos1, pos2)
2017-06-13 13:16:07 +02:00
local dx = pos2.x - pos1.x
local dy = pos2.y - pos1.y
2018-06-02 18:16:04 +02:00
return math.sqrt(dx * dx + dy * dy)
2017-06-13 13:16:07 +02:00
end
-- rounds number (num) to certain number of decimal places (idp)
2018-06-02 18:16:04 +02:00
math.round = function(num, idp)
2017-06-13 13:16:07 +02:00
local mult = 10 ^ (idp or 0)
return math.floor(num * mult + 0.5) / mult
end
2018-06-02 18:16:04 +02:00
Module.print_except = function(msg, player)
for _,p in pairs(game.players) do
if p.connected and p ~= player then
p.print(msg)
end
end
end
2018-06-02 18:16:04 +02:00
Module.print_admins = function(msg)
for _,p in pairs(game.players) do
if p.connected and p.admin then
p.print(msg)
end
end
end
2018-06-02 18:16:04 +02:00
Module.get_actor = function()
if game.player then return game.player.name end
return "<server>"
end