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)
|
2017-11-09 21:28:56 +02:00
|
|
|
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)
|
2017-11-09 21:28:56 +02:00
|
|
|
for _,p in pairs(game.players) do
|
|
|
|
if p.connected and p.admin then
|
|
|
|
p.print(msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-02 17:17:54 +02:00
|
|
|
|
2018-06-02 18:16:04 +02:00
|
|
|
Module.get_actor = function()
|
2018-06-02 17:17:54 +02:00
|
|
|
if game.player then return game.player.name end
|
|
|
|
return "<server>"
|
|
|
|
end
|
2018-06-03 14:24:33 +02:00
|
|
|
|
|
|
|
Module.cast_bool = function(var)
|
2018-06-04 12:40:31 +02:00
|
|
|
if var then return true else return false end
|
2018-06-03 14:24:33 +02:00
|
|
|
end
|
|
|
|
|
2018-06-05 01:34:58 +02:00
|
|
|
Module.find_entities_by_last_user = function(player, surface, filters)
|
|
|
|
if type(player) == "string" or not player then
|
|
|
|
error("bad argument #1 to '" .. debug.getinfo(1, "n").name .. "' (number or LuaPlayer expected, got ".. type(player) .. ")", 1)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if type(surface) ~= "table" and type(surface) ~= "number" then
|
|
|
|
error("bad argument #2 to '" .. debug.getinfo(1, "n").name .. "' (number or LuaSurface expected, got ".. type(surface) .. ")", 1)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local entities = {}
|
|
|
|
local surface = surface
|
|
|
|
local player = player
|
|
|
|
local filters = filters or {}
|
|
|
|
if type(surface) == "number" then surface = game.surfaces[surface] end
|
|
|
|
if type(player) == "number" then player = game.players[player] end
|
|
|
|
filters.force = player.force.name
|
|
|
|
for _,e in pairs(surface.find_entities_filtered(filters)) do
|
|
|
|
if e.last_user == player then
|
|
|
|
table.insert(entities, e)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return entities
|
2018-06-05 18:00:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
Module.ternary = function(c, t, f)
|
|
|
|
if c then return t else return f end
|
|
|
|
end
|
2018-06-03 14:24:33 +02:00
|
|
|
return Module
|