GroupService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
グループサービスは、開発者がゲーム内で Roblox グループに関する情報を取得できるサービスです。
グループの基本情報、名前、説詳細、所有者、役割、エンブレムは、GroupService:GetGroupInfoAsync() を使用して取得できます。グループの同盟国と敵のリストは、GroupService:GetAlliesAsync() と GroupService:GetEnemiesAsync() を使用して取得できます。
GroupService は、GroupService:GetGroupsAsync() を使用して、プレイヤーがメンバーであるグループのリストを取得することもできます。注: プレイヤーがグループに属しているかどうかを確認したい開発者は、Player:IsInGroup() 機能ではなく GroupService:GetGroupsAsync() 機能を使用する必要があります。
サービスには、ゲームに参加するとプレイヤーが同盟国か敵かを検出するなどの便利なアプリケーションが複数あります。
コードサンプル
This code sample demonstrates how GroupService and Player:IsInGroup() can be used to determine whether a player is a member of a group, or any of its allies or enemies.
Note as GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync() use StandardPages objects a utility function is used to convert them to allies.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- define group id here
local GROUP_ID = 271454
-- utility function for dealing with pages
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- get lists of allies and enemies
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- convert to array
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- check to see if the player is in the group
if player:IsInGroup(GROUP_ID) then
print(player.Name .. " is a member!")
else
local isAlly, isEnemy = false, false
-- check to see if the player is in any ally groups
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isAlly = true
break
end
end
-- check to see if the player is in any enemy groups
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " is an ally!")
elseif isEnemy and not isAlly then
print(player.Name .. " is an enemy!")
elseif isEnemy and isAlly then
print(player.Name .. " is both an ally and an enemy!")
else
print(player.Name .. " is neither an ally or an enemy!")
end
end
end
-- listen for new players being added
Players.PlayerAdded:Connect(playerAdded)
-- handle players already in game
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end
概要
方法
指定されたすべてのグループの仲間に関する情報を含む StandardPages オブジェクトを返します。
指定されたグループのすべての敵に関する情報を含む StandardPages オブジェクトを返します。
指定されたグループに関する情報を含むテーブルを返します。
特定のプレイヤーがメンバーであるグループに関する情報を含むテーブルのリストを返します。
プロパティ
方法
GetAlliesAsync
指定されたすべてのグループの仲間に関する情報を含む StandardPages オブジェクトを返します。
このページにはグループ ID のリストは含まれていませんが、GroupService:GetGroupInfoAsync() によって返されたフォーマットを反映するグループ情報テーブルのリストが含まれています。これらのテーブルの構造は以下を参照してください。
group = {Name = "Knights of the Seventh Sanctum",Id = 377251,Owner = {Name = "Vilicus",Id = 23415609},EmblemUrl = "http://www.roblox.com/asset/?id=60428602",Description = "We fight alongside the balance to make sure no one becomes to powerful",Roles = {[1] = {Name = "Apprentice",Rank = 1},[2] = {Name = "Warrior",Rank = 2},[3] = {Name = "Earth Walker",Rank = 255}}}
この関数は配列ではなく StandardPages オブジェクトを返すため、開発者は使いやすさのためにそれを配列に変換したいかもしれません (例を参照)。
この機能には、プレイヤーが同盟グループのメンバーかどうかを検出するなど、便利なアプリケーションが複数あります。
敵に対しては、GroupService:GetEnemiesAsync() を使用します。
パラメータ
グループの ID。
戻り値
コードサンプル
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- creates a table of all of the allies of a given group
local allies = {}
local pages = GroupService:GetAlliesAsync(GROUP_ID)
while true do
for _, group in pairs(pages:GetCurrentPage()) do
table.insert(allies, group)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
function onPlayerAdded(player)
for _, group in pairs(allies) do
if player:IsInGroup(group.Id) then
print("Player is an ally!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- handle players who joined while the allies list was still loading
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
This code sample demonstrates how GroupService and Player:IsInGroup() can be used to determine whether a player is a member of a group, or any of its allies or enemies.
Note as GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync() use StandardPages objects a utility function is used to convert them to allies.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- define group id here
local GROUP_ID = 271454
-- utility function for dealing with pages
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- get lists of allies and enemies
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- convert to array
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- check to see if the player is in the group
if player:IsInGroup(GROUP_ID) then
print(player.Name .. " is a member!")
else
local isAlly, isEnemy = false, false
-- check to see if the player is in any ally groups
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isAlly = true
break
end
end
-- check to see if the player is in any enemy groups
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " is an ally!")
elseif isEnemy and not isAlly then
print(player.Name .. " is an enemy!")
elseif isEnemy and isAlly then
print(player.Name .. " is both an ally and an enemy!")
else
print(player.Name .. " is neither an ally or an enemy!")
end
end
end
-- listen for new players being added
Players.PlayerAdded:Connect(playerAdded)
-- handle players already in game
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end
GetEnemiesAsync
指定されたグループのすべての敵に関する情報を含む StandardPages オブジェクトを返します。
このページにはグループ ID のリストは含まれていませんが、GroupService:GetGroupInfoAsync() によって返されたフォーマットを反映するグループ情報テーブルのリストが含まれています。これらのテーブルの構造は以下を参照してください。
group = {Name = "Knights of the Seventh Sanctum",Id = 377251,Owner = {Name = "Vilicus",Id = 23415609},EmblemUrl = "http://www.roblox.com/asset/?id=60428602",Description = "We fight alongside the balance to make sure no one becomes to powerful",Roles = {[1] = {Name = "Apprentice",Rank = 1},[2] = {Name = "Warrior",Rank = 2},[3] = {Name = "Earth Walker",Rank = 255}}}
この関数は配列ではなく StandardPages オブジェクトを返すため、開発者は使いやすさのためにそれを配列に変換したいかもしれません (例を参照)。
この機能には、プレイヤーが敵グループのメンバーかどうかを検出するなど、便利なアプリケーションが複数あります。
同盟国の場合は、GroupService:GetAlliesAsync() を使用します。
パラメータ
グループの ID。
戻り値
コードサンプル
local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 57
-- creates a list of all of the enemies of a given group
local enemies = {}
local pages = GroupService:GetEnemiesAsync(GROUP_ID)
while true do
for _, group in pairs(pages:GetCurrentPage()) do
table.insert(enemies, group)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
function onPlayerAdded(player)
for _, enemyGroup in pairs(enemies) do
if player:IsInGroup(enemyGroup.Id) then
print("Player is an enemy!")
break
end
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
-- handle players who joined while the enemies list was still loading
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
This code sample demonstrates how GroupService and Player:IsInGroup() can be used to determine whether a player is a member of a group, or any of its allies or enemies.
Note as GroupService:GetAlliesAsync() and GroupService:GetEnemiesAsync() use StandardPages objects a utility function is used to convert them to allies.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
-- define group id here
local GROUP_ID = 271454
-- utility function for dealing with pages
local function pagesToArray(pages)
local array = {}
while true do
for _, v in ipairs(pages:GetCurrentPage()) do
table.insert(array, v)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return array
end
-- get lists of allies and enemies
local alliesPages = GroupService:GetAlliesAsync(GROUP_ID)
local enemiesPages = GroupService:GetEnemiesAsync(GROUP_ID)
-- convert to array
local allies = pagesToArray(alliesPages)
local enemies = pagesToArray(enemiesPages)
local function playerAdded(player)
-- check to see if the player is in the group
if player:IsInGroup(GROUP_ID) then
print(player.Name .. " is a member!")
else
local isAlly, isEnemy = false, false
-- check to see if the player is in any ally groups
for _, groupInfo in ipairs(allies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isAlly = true
break
end
end
-- check to see if the player is in any enemy groups
for _, groupInfo in ipairs(enemies) do
local groupId = groupInfo.Id
if player:IsInGroup(groupId) then
isEnemy = true
break
end
end
if isAlly and not isEnemy then
print(player.Name .. " is an ally!")
elseif isEnemy and not isAlly then
print(player.Name .. " is an enemy!")
elseif isEnemy and isAlly then
print(player.Name .. " is both an ally and an enemy!")
else
print(player.Name .. " is neither an ally or an enemy!")
end
end
end
-- listen for new players being added
Players.PlayerAdded:Connect(playerAdded)
-- handle players already in game
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end
GetGroupInfoAsync
指定されたグループに関する情報を含むテーブルを返します。
返されたテーブルは、GroupService:GetAlliesAsync() および GroupService:GetEnemiesAsync() で返された形式と同じです。この形式は以下で見ることができます。
group = {Name = "Knights of the Seventh Sanctum",Id = 377251,Owner = {Name = "Vilicus",Id = 23415609},EmblemUrl = "http://www.roblox.com/asset/?id=60428602",Description = "We fight alongside the balance to make sure no one becomes to powerful",Roles = {[1] = {Name = "Apprentice",Rank = 1},[2] = {Name = "Warrior",Rank = 2},[3] = {Name = "Earth Walker",Rank = 255}}}
注: グループにオーナーがいない場合、オーナーフィールドは nil に設定されます。
この機能には、グループの最新の説明とロゴをグループベースに表示するための有用なアプリケーションが複数あります。
パラメータ
グループのグループ ID。
戻り値
グループに関する情報の辞書。
コードサンプル
local GroupService = game:GetService("GroupService")
local GROUP_ID = 377251
local group = GroupService:GetGroupInfoAsync(GROUP_ID)
print(group.Name .. " has the following roles:")
for _, role in ipairs(group.Roles) do
print("Rank " .. role.Rank .. ": " .. role.Name)
end
The code in this sample spawns a Part in the Workspace that includes a texture of the given group's emblem.
local GroupService = game:GetService("GroupService")
local function getEmblemAsync(groupId)
local groupInfo = GroupService:GetGroupInfoAsync(groupId)
return groupInfo.EmblemUrl
end
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Size = Vector3.new(5, 5, 1)
part.Position = Vector3.new(0, 5, 0)
local decal = Instance.new("Decal")
decal.Parent = part
part.Parent = workspace
decal.Texture = getEmblemAsync(377251)
GetGroupsAsync
警告: 返されたテーブルの IsInClan プロパティは常に 偽り を返し、バックワード互換性のために存在します。クラン機能は、2016年に Roblox プラットフォームからサンセットしました。
この関数は、指定の Player がメンバーであるすべてのグループに関する情報を含むテーブルのリストを返します。
返されたリストには、プレイヤーがメンバーであるグループのエントリが含まれます。これらのエントリは次のフィールドを持つテーブルです。
<th>説明</th></tr></thead><tbody><tr><td><b>名前</b></td><td>グループの名前</td></tr><tr><td><b>Id</b></td><td>グループ ID</td></tr><tr><td><b>エンブレムURL</b></td><td>グループのサムネイルにリンクするアセット URL (例: http://www.roblox.com/asset/?id=276165514)</td></tr><tr><td><b>エンブレムID</b></td><td>エンブレムのアセットID、EmblemUrl で使用されるものと同じ</td></tr><tr><td><b>ランク</b></td><td>プレイヤーが持っているランクID (例: 所有者の場合 255)</td></tr><tr><td><b>役割</b></td><td>プレイヤーのグループランク名 (例: グループ所有者)</td></tr><tr><td><b>は主ですか</b></td><td>これがプレイヤーの主要グループかどうかを示すブールン値</td></tr><tr><td><b>IsInクラン</b></td><td>プレイヤーがこのグループのクランにいるかどうかを示すブールン値</td></tr></tbody>
名前 |
---|
注:GroupService:GetAlliesAsync() と GroupService:GetEnemiesAsync() とは異なり、GetGroupsAsync は StandardPages オブジェクトではなく、テーブルを返します。
パラメータ
ユーザーの Player.UserId 。
戻り値
コードサンプル
This code sample will print information on all of the groups a player is a member of when they join the game, using GroupService:GetGroupsAsync().
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local function playerAdded(player)
-- load a list of info on all groups the player is a member of
local groups = GroupService:GetGroupsAsync(player.UserId)
for _, groupInfo in pairs(groups) do
for key, value in pairs(groupInfo) do
print(key .. ": " .. tostring(value))
end
print("--")
end
end
Players.PlayerAdded:Connect(playerAdded)
-- go through existing players
for _, player in pairs(Players:GetPlayers()) do
playerAdded(player)
end