GroupService
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
GroupService, geliştiricilerin bir Roblox grubu hakkında bilgi almasına izin veren bir hizmettir.
Grubun adı, açıklaması, sahibi, rolleri ve sembolü dahil olmak üzere gruptemel bilgileri GroupService:GetGroupInfoAsync() kullanılarak alınabilir.Bir grupmüttefikleri ve düşmanlarının listeleri GroupService:GetAlliesAsync() ve GroupService:GetEnemiesAsync() kullanılarak alınabilir.
GroupService, bir oyuncunun bir grupüyesi olduğu bir listeyi almak için de kullanılabilir GroupService:GetGroupsAsync() .Not, bir oyuncunun bir grubun içinde olup olmadığını doğrulmak isteyen geliştiricilerin Player:IsInGroup() fonksiyonunu kullanmak yerine GroupService:GetGroupsAsync() kullanması gerekir.
Hizmetin bir dizi yararlı uygulaması vardır, örneğin bir oyuncunun oyuna katıldığında bir müttefik veya düşman olup olmadığını tespit etmek gibi.
Kod Örnekleri
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
Özet
Özellikler
Yöntemler
Belirtilen tüm grup müttefikleriyle ilgili bilgileri içeren bir StandardPages nesne döndürür.
Belirtilen tüm grup düşmanlarıyla ilgili bilgileri içeren bir StandardPages nesne döndürür.
Verilen grupilgili bilgileri içeren bir tablo döndürür.
Verilen oyuncunun üyesi olduğu tüm gruplarla ilgili bilgileri içeren bir tablo listesi döndürür.
Özellikler
Yöntemler
GetAlliesAsync
Belirtilen tüm grup müttefikleriyle ilgili bilgileri içeren bir StandardPages nesne döndürür.
Bu sayfalar bir grup kimlik listesi içermez, ancak yerine bir grup bilgi tablosu listesi düzenlenir, GroupService:GetGroupInfoAsync() tarafından döndürülen biçimin aynısını yansıtır.Bu tabloların yapısını aşağıda görün.
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}}}
Not, bu işlev bir dize yerine bir StandardPages nesne döndürdüğünden, geliştiriciler kullanım kolaylığı için onu bir dizeye dönüştürmek isteyebilir (örnekler bakın).
Bu işlev, bir oyuncunun müttefik bir grupüyesi olup olmadığını tespit etme dahil olmak üzere bir dizi yararlı uygulamaya sahiptir.
Düşmanlar için, GroupService:GetEnemiesAsync() kullanın.
Parametreler
grupkimliği.
Dönüşler
Kod Örnekleri
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
Belirtilen tüm grup düşmanlarıyla ilgili bilgileri içeren bir StandardPages nesne döndürür.
Bu sayfalar bir grup kimlik listesi içermez, ancak yerine bir grup bilgi tablosu listesi düzenlenir, GroupService:GetGroupInfoAsync() tarafından döndürülen biçimin aynısını yansıtır.Bu tabloların yapısını aşağıda görün.
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}}}
Not, bu işlev bir dize yerine bir StandardPages nesne döndürdüğünden, geliştiriciler kullanım kolaylığı için onu bir dizeye dönüştürmek isteyebilir (örnekler bakın).
Bu işlevin birçok yararlı uygulaması vardır, bir oyuncunun bir düşman grupüyesi olup olmadığını tespit etmek de dahil.
Müttefikler için, GroupService:GetAlliesAsync() kullanın.
Parametreler
grupkimliği.
Dönüşler
Kod Örnekleri
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
Verilen grupilgili bilgileri içeren bir tablo döndürür.
Döndürülen tablo, GroupService:GetAlliesAsync() ve GroupService:GetEnemiesAsync() olarak döndürülen formatla aynıdır. Bu format aşağıda görülebilir.
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}}}
Not, bir grubun sahibi yoksa Sahip alanı nil olarak ayarlanacaktır.
Bu işlev, bir grupta görüntülenmesi için en son açıklama ve logoyu yükleme dahil olmak üzere bir dizi yararlı uygulamaya sahiptir.
Parametreler
Grupun grup kimliği.
Dönüşler
gruphakkında bilgi sözlüğü.
Kod Örnekleri
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
Uyarı: Geri döndürülen tablodaki IsInClan özelliği daima yanlış döndürecek ve geriye dönük uyumluluk için var olacak.Klanlar özelliği 2016'da Roblox platformundan günbatımı oldu.
Bu işlev, belli bir Player üyesi olduğu tüm gruplarla ilgili bilgiler içeren bir tablo listesi döndürür.
Döndürülen liste, oyuncunun üyesi olduğu her grup için bir giriş içerecektir. Bu girişler aşağıdaki alanlara sahip tablolardır.
<th>Açıklama</th></tr></thead><tbody><tr><td><b>Adı</b></td><td>grupadı</td></tr><tr><td><b>Id</b></td><td>Grup kimliği</td></tr><tr><td><b>Sembol URL'si</b></td><td>grupküçük resmine bağlanan bir varlık URL'si (örneğin: http://www.roblox.com/asset/?id=276165514)</td></tr><tr><td><b>SembolID</b></td><td>Sembolün ID'si, EmblemUrl'de kullanılan aynı şey</td></tr><tr><td><b>Rütbe</b></td><td>Oyuncunun sahip olduğu rütbeId (örneğin: sahibi için 255)</td></tr><tr><td><b>Rolü</b></td><td>oyuncugruptaki adı (örneğin: Grup Sahibi)</td></tr><tr><td><b>IsPrimary Özel mi?</b></td><td>Bunun oyuncunun ana grupolup olmadığını gösteren bir boolean değeri</td></tr><tr><td><b>IsInClanYorumlarYorumlarYorumlarIsInClan</b></td><td>Oyuncunun bu grupklanında olup olmadığını gösteren bir mantık değeri</td></tr></tbody>
Adı |
---|
Not GroupService:GetAlliesAsync() ve GroupService:GetEnemiesAsync() 'den farklı olarak, GetGroupsAsync bir StandardPages nesnesi yerine bir tablo döndürür.
Parametreler
Kullanıcının Player.UserId 'si.
Dönüşler
Kod Örnekleri
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