GroupService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
GroupService è un servizio che consente agli sviluppatori di recuperare informazioni su un gruppo Roblox da dentro un Gioco.
Le informazioni di base sul Gruppo, incluso il suo nome, la Descrizione, il proprietario, i ruoli e l'emblema possono essere recuperate utilizzando GroupService:GetGroupInfoAsync() .Le liste degli alleati e dei nemici di un Gruppopossono essere recuperate utilizzando GroupService:GetAlliesAsync() e GroupService:GetEnemiesAsync() .
GroupService può essere utilizzato anche per recuperare un elenco dei Gruppodi cui un giocatore è membro, utilizzando GroupService:GetGroupsAsync() .Nota, gli sviluppatori che desiderano verificare se un giocatore è in un gruppo dovrebbero utilizzare la funzione Player:IsInGroup() piuttosto che GroupService:GetGroupsAsync().
Il servizio ha una serie di applicazioni utili, come il rilevamento se un giocatore è alleato o nemico dopo aver aderito al Gioco.
Campioni di codice
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
Sommario
Proprietà
Metodi
Restituisce un oggetto StandardPages comprensivo di informazioni su tutti gli alleati del Gruppospecificato.
Restituisce un oggetto StandardPages comprensivo di informazioni su tutti i nemici del Gruppospecificato.
Restituisce una tabella che contiene informazioni sul Gruppodato.
Restituisce una lista di tabelle che contengono informazioni su tutti i gruppi di cui un dato giocatore è membro.
Proprietà
Metodi
GetAlliesAsync
Restituisce un oggetto StandardPages comprensivo di informazioni su tutti gli alleati del Gruppospecificato.
Queste pagine non includono una lista di ID di gruppo ma invece una lista di tabelle di informazioni di gruppo, che riflettono il formato di quelle restituite da GroupService:GetGroupInfoAsync() .Vedi qui sotto per la struttura di queste tabelle.
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}}}
Nota, poiché questa funzione restituisce un oggetto StandardPages piuttosto che un vettore, gli sviluppatori potrebbero volerlo convertire in un array per facilità d'uso (vedi esempi).
Questa funzione ha una serie di applicazioni utili, tra cui il rilevamento se un giocatore è un membro di un Gruppoalleato.
Per i nemici, usa GroupService:GetEnemiesAsync() .
Parametri
L'ID del Gruppo.
Restituzioni
Campioni di codice
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
Restituisce un oggetto StandardPages comprensivo di informazioni su tutti i nemici del Gruppospecificato.
Queste pagine non includono una lista di ID di gruppo ma invece una lista di tabelle di informazioni di gruppo, che riflettono il formato di quelle restituite da GroupService:GetGroupInfoAsync() .Vedi qui sotto per la struttura di queste tabelle.
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}}}
Nota, poiché questa funzione restituisce un oggetto StandardPages piuttosto che un vettore, gli sviluppatori potrebbero volerlo convertire in un array per facilità d'uso (vedi esempi).
Questa funzione ha una serie di applicazioni utili, tra cui il rilevamento se un giocatore è un membro di un Grupponemico.
Per gli alleati, usa GroupService:GetAlliesAsync() .
Parametri
L'ID del Gruppo.
Restituzioni
Campioni di codice
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
Restituisce una tabella che contiene informazioni sul Gruppodato.
La tabella restituita è lo stesso formato di quello restituito in GroupService:GetAlliesAsync() e GroupService:GetEnemiesAsync() . Questo formato può essere visto qui sotto.
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}}}
Nota, se un gruppo non ha un proprietario il campo Proprietario verrà impostato su nil .
Questa funzione ha una serie di applicazioni utili, tra cui il caricamento dell'ultima descrizione e del logo di un gruppo per la visualizzazione in una base di gruppo.
Parametri
L'ID gruppo del Gruppo.
Restituzioni
Un dizionario di informazioni sul Gruppo.
Campioni di codice
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
Avviso: La proprietà IsInClan nella tabella restituita restituirà sempre false e esisterà per la compatibilità retrospettiva.La funzione dei clan è stata tramontata dalla piattaforma Roblox nel 2016.
Questa funzione restituisce un elenco di tabelle che contengono informazioni su tutti i gruppi di cui un dato Player è membro.
L'elenco restituito includerà un'entrata per ogni gruppo al quale il giocatore è membro. Queste entrate sono tabelle con i seguenti campi.
<th>Descrizione</th></tr></thead><tbody><tr><td><b>Nome</b></td><td>Il nome del Gruppo</td></tr><tr><td><b>Id</b></td><td>L'ID gruppo</td></tr><tr><td><b>Url dell'emblema</b></td><td>Un link a un URL di risorse che conduce alla miniatura del Gruppo(ad esempio: http://www.roblox.com/asset/?id=276165514)</td></tr><tr><td><b>EmblemId</b></td><td>L'assetId dell'emblema, lo stesso che viene utilizzato nell'EmblemUrl</td></tr><tr><td><b>Classifica</b></td><td>Il rankId che il giocatore ha (ad esempio: 255 per il proprietario)</td></tr><tr><td><b>Ruolo</b></td><td>Il nome del grouprank del Giocatore(ad esempio: Proprietario del gruppo)</td></tr><tr><td><b>È primario</b></td><td>Un booleano che indica se questo è il Gruppoprincipale del Giocatore</td></tr><tr><td><b>Esiste in clan</b></td><td>Un booleano che indica se il giocatore è nel clan di questo Gruppo</td></tr></tbody>
Nome |
---|
Nota a differenza di GroupService:GetAlliesAsync() e GroupService:GetEnemiesAsync(), GetGroupsAsync restituisce una tabella piuttosto che un oggetto StandardPages.
Parametri
Il Player.UserId dell'utente.
Restituzioni
Campioni di codice
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