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:
commit
4084b6ab1f
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user