diff --git a/mods/CORE/mcl_commands/init.lua b/mods/CORE/mcl_commands/init.lua index 04c249c528..db6a49cb35 100644 --- a/mods/CORE/mcl_commands/init.lua +++ b/mods/CORE/mcl_commands/init.lua @@ -99,6 +99,15 @@ mcl_commands.types = { return S("Player doesn't exist.") end end}, + target = {"([A-Za-z0-9-_]+)", + function(res, pointer) + --if minetest.player_exists(res[pointer]) then + if res[pointer] then + return nil, res[pointer], pointer+1 + else + return S("Player doesn't exist.") + end + end}, json = {"(.+)", --FIXME function(res, pointer) local parsed = parse_json(res[pointer]) @@ -360,4 +369,41 @@ function mcl_commands.rename_chatcommand(newname, cmd, bypass) else minetest.log("action", "[mcl_commands] ["..cmd.."] command not renamed to ["..newname.."]") end +end + +function mcl_commands.get_target_selector(target, pos, name) + if minetest.player_exists(target) then + return minetest.get_player_by_name(target) + elseif target == "@a" then + return nil, minetest.get_connected_players() + elseif target == "@r" then + local connected = minetest.get_connected_players() + return nil, connected[math.random(1, #connected)] + elseif target == "@s" then + if name then + local player = minetest.get_player_by_name(name) + end + if player then + return nil, player + else + return S("Not a valid player") + end + elseif target == "@p" then + local smallest = math.huge + local nearest + for _,player in pairs(minetest.get_connected_players()) do + local distance = vector.distance(pos, player:get_pos()) + if distance < min_distance then + min_distance = distance + nearest = player + end + end + if nearest then + return nil, nearest + else + return S("No player online") + end + elseif target == "@e" then + return minetest.luaentities --TODO: add filtering of not valid entities. + end end \ No newline at end of file