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.

Group Ally/Enemy Checker

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

요약

메서드

속성

메서드

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()를 사용하십시오.

매개 변수

groupId: number

그룹의 ID.

기본값: ""

반환

코드 샘플

GroupService:GetAlliesAsync

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.

Group Ally/Enemy Checker

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()를 사용하십시오.

매개 변수

groupId: number

그룹의 ID.

기본값: ""

반환

코드 샘플

GroupService:GetEnemiesAsync

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.

Group Ally/Enemy Checker

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

Variant
생성

지정된 그룹에 대한 정보가 포함된 테이블을 반환합니다.

반환된 테이블은 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로 설정됩니다.

이 함수에는 그룹 기반에서 표시하기 위해 최신 설명과 로고를 로드하는 것을 포함하여 유용한 응용 프로그램의 수가 많습니다.

매개 변수

groupId: number

그룹의 그룹 ID.

기본값: ""

반환

Variant

그룹에 대한 정보의 사전.

코드 샘플

GroupService:GetGroupInfoAsync

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.

Load Group 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 속성은 항상 false 를 반환하고 이전 버전과의 호환성을 위해 존재합니다.클랜 기능은 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>상징 주소 EmblemUrl</b></td>
<td>그룹의 썸네일에 연결하는 자산 URL(예: http://www.roblox.com/asset/?id=276165514)</td>
</tr>
<tr>
<td><b>상징 ID</b></td>
<td>엠블럼의 아이디, EmblemUrl에서 사용되는 것과 동일</td>
</tr>
<tr>
<td><b>순위</b></td>
<td>플레이어가 가진 순위 ID(예: 소유자에게는 255)</td>
</tr>
<tr>
<td><b>역할</b></td>
<td>플레이어의 그룹 등급 이름(예: 그룹 소유자)</td>
</tr>
<tr>
<td><b>기본 제공 IsPrimary</b></td>
<td>플레이어의 주 그룹인지 여부를 나타내는 부울입니다.</td>
</tr>
<tr>
<td><b>클랜 속에 있는지 IsInClan</b></td>
<td>플레이어가 이 그룹의 클랜에 있는지를 나타내는 부울입니다</td>
</tr>
</tbody>
이름

GroupService:GetAlliesAsync()GroupService:GetEnemiesAsync() 와 달리, GetGroupsAsync는 테이블을 반환하지 않고 StandardPages 개체를 반환합니다.

매개 변수

userId: number

사용자의 Player.UserId입니다.

기본값: ""

반환

그룹에 대한 정보가 포함된 배열의 사전은 Player 그룹의 멤버입니다.

코드 샘플

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().

Getting the Groups that a User is A Member Of

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

이벤트