1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Merge pull request #708 from plague006/get_player_from_any

Add get_player_from_any
This commit is contained in:
Matthew 2019-01-28 19:38:49 -05:00 committed by GitHub
commit 4084b6ab1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,6 +45,25 @@ function Game.get_player_by_index(index)
end
end
--- Returns a valid LuaPlayer if given a number, string, or LuaPlayer. Returns nil otherwise.
-- obj <number|string|LuaPlayer>
function Game.get_player_from_any(obj)
local o_type = type(obj)
local p
if type == 'number' then
p = Game.get_player_by_index(obj)
elseif o_type == 'string' then
p = game.players[obj]
elseif o_type == 'table' and obj.valid and obj.is_player() then
return obj
end
if p and p.valid then
return p
end
end
--- Prints to player or console.
function Game.player_print(str)
if game.player then
game.player.print(str)