GroupService

Pokaż przestarzałe

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.

Brak możliwości tworzenia
Usługa
Bez replikacji

GroupService to usługa, która pozwala programistom pobierać informacje o grupie Roblox z wewnątrz gry.

Podstawowe informacje o grupa, w tym jej nazwa, opis, właściciel, role i emblemat można pobrać za pomocą GroupService:GetGroupInfoAsync() .Listy sojuszników i wrogów grupamożna pobrać za pomocą GroupService:GetAlliesAsync() i GroupService:GetEnemiesAsync().

Usługa grupowa może być również używana do pobrania listy grupa, z których gracz jest członkiem, za pomocą GroupService:GetGroupsAsync().Zauważ, że programiści, którzy chcą sprawdzić, czy gracz jest w grupie, powinni używać funkcji Player:IsInGroup() zamiast GroupService:GetGroupsAsync().

Usługa ma wiele przydatnych aplikacji, takich jak wykrywanie, czy gracz jest sojusznikiem czy wrogiem po dołączeniu do gry.

Przykłady kodu

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

Podsumowanie

Metody

Właściwości

Metody

GetAlliesAsync

Wynik

Zwraca obiekt StandardPages zawierający informacje o sojusznikach wszystkich określonych grupa.

Te strony nie zawierają listy identyfikatorów grup, ale zamiast tego listy informacji o grupach, odzwierciedlające format tej, która została zwrócona przez GroupService:GetGroupInfoAsync().Zobacz poniżej strukturę tych tabel.


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
}
}
}

Pamiętaj, że funkcja ta zwraca obiekt StandardPages zamiast matrycy, a programiści mogą chcieć go przekonwertować na matrycę dla łatwości użycia (patrz przykłady).

Funkcja ta ma wiele przydatnych aplikacji, w tym wykrywanie, czy gracz jest członkiem sojuszniczej grupa.

Dla wrogów użyj GroupService:GetEnemiesAsync().

Parametry

groupId: number

Identyfikator grupa.

Wartość domyślna: ""

Zwroty

Przykłady kodu

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

Wynik

Zwraca obiekt StandardPages zawierający informacje o wszystkich wrogach określonej grupa.

Te strony nie zawierają listy identyfikatorów grup, ale zamiast tego listy informacji o grupach, odzwierciedlające format tej, która została zwrócona przez GroupService:GetGroupInfoAsync().Zobacz poniżej strukturę tych tabel.


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
}
}
}

Pamiętaj, że funkcja ta zwraca obiekt StandardPages zamiast matrycy, a programiści mogą chcieć go przekonwertować na matrycę dla łatwości użycia (patrz przykłady).

Funkcja ta ma wiele przydatnych aplikacji, w tym wykrywanie, czy gracz jest członkiem wrożej grupa.

Dla sojuszników użyj GroupService:GetAlliesAsync().

Parametry

groupId: number

Identyfikator grupa.

Wartość domyślna: ""

Zwroty

Przykłady kodu

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
Wynik

Zwraca tabelę zawierającą informacje o podanej grupa.

Zwrócony jest taki sam format, jak ten, który został zwrócony w GroupService:GetAlliesAsync() i GroupService:GetEnemiesAsync(). Taki format można zobaczyć poniżej.


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
}
}
}

Uwaga, jeśli grupa nie ma właściciela, pole Właściciel zostanie ustawione na nil.

Funkcja ta ma wiele przydatnych aplikacji, w tym ładowanie najnowszego opisu i logo grupy do wyświetlenia w bazie grupy.

Parametry

groupId: number

ID grupy grupa.

Wartość domyślna: ""

Zwroty

Variant

Słownik informacji o grupa.

Przykłady kodu

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

Wynik

Ostrzeżenie: Właściwość IsInClan w zwróconej tabeli zawsze zwróci fałsz i istnieje dla kompatybilności wstecznej.Funkcja klanów zniknęła z platformy Roblox w 2016 r.

Funkcja ta zwraca listę tabel zawierającą informacje o wszystkich grupach, z którymi dany Player jest członkiem.

Zwrócona lista będzie zawierać wpis dla każdej grupy, z której gracz jest członkiem. Te wpisy są tablicami z następującymi polami.


<th>Opis</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>Nazwa</b></td>
<td>Nazwa grupa</td>
</tr>
<tr>
<td><b>Id</b></td>
<td>ID grupy</td>
</tr>
<tr>
<td><b>Adres URL symbolu</b></td>
<td>Link URL do zdjęcia miniaturki grupa(na przykład: http://www.roblox.com/asset/?id=276165514)</td>
</tr>
<tr>
<td><b>Identyfikator emblemów</b></td>
<td>Identyfikator zasobu emblematu, taki sam, który jest używany w EmblemUrl</td>
</tr>
<tr>
<td><b>Pozycja</b></td>
<td>Ranga, jaką ma gracz (na przykład: 255 dla właściciela)</td>
</tr>
<tr>
<td><b>Rolą</b></td>
<td>Nazwa grupy gracza (na przykład: Właściciel grupy)</td>
</tr>
<tr>
<td><b>Czy jest główny</b></td>
<td>Boolean wskazujący, czy jest to główna grupa gracza</td>
</tr>
<tr>
<td><b>Jest w klanie</b></td>
<td>Boolean wskazujący, czy gracz jest w grupatej grupy</td>
</tr>
</tbody>
Nazwa

Uwaga w przeciwieństwie do GroupService:GetAlliesAsync() i GroupService:GetEnemiesAsync(), GetGroupsAsync zwraca tabelę, a nie obiekt StandardPages.

Parametry

userId: number

The Player.UserId użytkownika.

Wartość domyślna: ""

Zwroty

Zbiór słowników zawierających informacje o grupa, której Player jest członkiem.

Przykłady kodu

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

Zdarzenia