BadgeService

Artık kullanılmayanları göster

*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.

Oluşturulamaz
Hizmet

BaşarımServisi sınıfı, başarımlarla ilgili bilgi ve işlevsellik sağlar.Rozetler, bir oyuncunun başarılarını ve etkinliktanıtmak için platform genelinde kullanılır.Bir oyuncuya bir rozet verildiğinde, envanterlerine eklenir ve profil sayfasında gösterilir.

Kod Örnekleri

The following example creates an awardBadge() function that handles potential errors that may occur when awarding a badge. Using properties of the badge fetched via BadgeService:GetBadgeInfoAsync(), it confirms that the badge can be awarded and does so using BadgeService:AwardBadge().

Awarding a Badge

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

The following script waits for any player to enter the game and checks if they own a specific badge. This is useful for creating a restricted area with collision filtering or teleportation that only works if a player owns a special badge.

Checking Earned Badges

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- Change this to your badge ID
local function onPlayerAdded(player)
-- Check if the player has the badge
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has badge!")
return
end
if hasBadge then
-- Handle player's badge ownership as needed
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

This script checks which badges a user owns when they join the experience.

Checking Earned Badges in Batches

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- Change this to a list of your badge IDs
local function onPlayerAdded(player)
-- Check if the player has any of the badges
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player", player.Name, "has badges:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "does not have any of the badges")
else
print(player.Name, "has the following badges:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

This sample prints badge information fetched via BadgeService:GetBadgeInfoAsync().

Getting Badge Info

local BadgeService = game:GetService("BadgeService")
-- Fetch badge information
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID
end)
-- Output the information
if success then
print("Badge:", result.Name)
print("Enabled:", result.IsEnabled)
print("Description:", result.Description)
print("Icon:", "rbxassetid://" .. result.IconImageId)
else
warn("Error while fetching badge info:", result)
end

Özet

Yöntemler

Özellikler

Yöntemler

AwardBadge

Bekletir

Bir rozet verir Player kötü bir rozet ile UserId ve rozet kimliği.Oran sınırı: Her dakika 50 + 35 * [kullanıcı sayısı] .Başarıyla bir rozet ödülü vermek için:

  • Oyuncu şu anda oyuna bağlı olmalıdır.
  • Oyuncunun zaten rozeti olmamalı (bir oyuncunun verilen bir rozeti profilinden silip tekrar rozet alabileceğini unutmayın).
  • Rozet bir sunucu tarafından Script veya bir ModuleScript sonunda bir Script tarafından gerekli olacak şekilde verilmelidir, bir LocalScript 'dan değil.
  • Rozet, rozetle ilişkili oyunun bir parçası olan bir yerde verilmelidir.
  • Rozetin etkinleştirilmesi gerekir; bunu IsEnabled özelliği ile rozetin alındığı BadgeService:GetBadgeInfoAsync() üzerinden kontrol edin.

Ayrıca bakın:

Parametreler

userId: number

Badge'in verileceği kullanıcının Player.UserId 'si.

Varsayılan değer: ""
badgeId: number

Verilecek rozetin kimliği.

Varsayılan değer: ""

Dönüşler

true eğer başarıyla rozet verildiyse booleen ifadesi.

Kod Örnekleri

The following example creates an awardBadge() function that handles potential errors that may occur when awarding a badge. Using properties of the badge fetched via BadgeService:GetBadgeInfoAsync(), it confirms that the badge can be awarded and does so using BadgeService:AwardBadge().

Awarding a Badge

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

CheckUserBadgesAsync

Bekletir

Bir listeyi rozet kimliklerine karşı kontrol eder ve UserId bir liste oyuncunun sahip olduğu rozet kimliklerini döndürür.

Bu yöntem, 10 rozete kadar toplu görüşmeleri destekler. Tek rozet görüşmeleri için BadgeService:UserHasBadgeAsync() kullanın.

Oran sınırı: Her saniye 10 + 5 * [oyuncu sayısı] her sunucuda .

Herhangi bir deneyim için herhangi bir rozet seti sorgulanabilir, kim rozetleri oluşturdu veya hangi deneyimler için olduğu önemli değildir.Herhangi biri UserId , bir Script 'de kullanılabilir, ancak bir LocalScript 'de yalnızca yerel kullanıcının istemcisi tarafından çalıştırılan UserId kullanılabilir.

Parametreler

userId: number

Belirtilen rozetlerin sahipliğini kontrol etmek için oyuncunun UserId 'si.

Varsayılan değer: ""
badgeIds: Array

Sahipliği doğrulamak için rozetlerin ID listesi. Maksimum 10 uzunluk.

Varsayılan değer: ""

Dönüşler

Verdiğiniz kullanıcının sahip olduğu rozet kimliklerinin listesi, verilen rozet kimliklerinden dışarıda.Verilen rozetlerden hiçbiri verilen kullanıcıya ait değilse boş.Giriş listesi ile aynı sırada olacağı garanti edilmez.

Kod Örnekleri

This script checks which badges a user owns when they join the experience.

Checking Earned Badges in Batches

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- Change this to a list of your badge IDs
local function onPlayerAdded(player)
-- Check if the player has any of the badges
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player", player.Name, "has badges:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "does not have any of the badges")
else
print(player.Name, "has the following badges:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

GetBadgeInfoAsync

Bekletir

Bu işlev, kimliğine verilen bir rozet hakkında bilgi alır.Roblox web sitesinden bilgileri yükleme biraz sürer; tekrarlanan çağrılar kısa bir süre için önbelleğe alınır.Aşağıdaki alanlarla bir sözlük döndürür:


<th>Tür</th>
<th>Açıklama</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>Adı</b></td>
<td>dizi</td>
<td>Rozetin adı.</td>
</tr>
<tr>
<td><b>Açıklama</b></td>
<td>dizi</td>
<td>Rozetin rozet.</td>
</tr>
<tr>
<td><b>İkonGörüntüId</b></td>
<td>int64</td>
<td>Rozet için görüntünün varlık kimliği.</td>
</tr>
<tr>
<td><b>Etkinleştirildi</b></td>
<td>bool
i̇çindekiler
nasıl yapılır
bool
i̇çindekiler
nasıl yapılır</td>
<td>Rozetin verilebilir olup olmadığını gösterir.</td>
</tr>
</tbody>
Anahtar

Ayrıca bakın:

Parametreler

badgeId: number

Bilgilerin alınması gereken rozetin rozet kimliği.

Varsayılan değer: ""

Dönüşler

Belirtilen rozet hakkında bilgi sözlüğü.

Kod Örnekleri

This sample prints badge information fetched via BadgeService:GetBadgeInfoAsync().

Getting Badge Info

local BadgeService = game:GetService("BadgeService")
-- Fetch badge information
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID
end)
-- Output the information
if success then
print("Badge:", result.Name)
print("Enabled:", result.IsEnabled)
print("Description:", result.Description)
print("Icon:", "rbxassetid://" .. result.IconImageId)
else
warn("Error while fetching badge info:", result)
end

UserHasBadgeAsync

Bekletir

Bir bir rozete sahip olup olmadığını ve rozetin ID'sini kontrol eder ve döndürür ve kötü bir rozete sahip olup olmadığını.Oran sınırı: Her dakika 50 + 35 * [oyuncu sayısı] .Fonksiyonu sunucudan bir Script veya ModuleScript sonunda bir Script tarafından gerekli olan çağırabilirsiniz ve soru çalıştırılması için sunucudaki kullanıcının mevcut olması gerekir.Yöntemi bir LocalScript 'dan istemci çağırdığınızda, yalnızca yerel kullanıcının istemcisi kodu çalıştıran kullanıcı için çalışır.

Herhangi bir oyun için herhangi bir rozet sorgulanabilir, rozeti kim oluşturdu veya hangi deneyim için kullanıldığı önemli değil.

Ayrıca bakın:

Parametreler

userId: number

Belirtilen rozetin sahipliğini kontrol etmek için oyuncunun Player.UserId 'si.

Varsayılan değer: ""
badgeId: number

Sahipliği kontrol edilecek rozetin rozet kimliği.

Varsayılan değer: ""

Dönüşler

Belirtilen kullanıcının belirtilen rozeti var olup olmadığını gösterir.

Kod Örnekleri

The following script waits for any player to enter the game and checks if they own a specific badge. This is useful for creating a restricted area with collision filtering or teleportation that only works if a player owns a special badge.

Checking Earned Badges

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- Change this to your badge ID
local function onPlayerAdded(player)
-- Check if the player has the badge
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player has badge!")
return
end
if hasBadge then
-- Handle player's badge ownership as needed
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

Etkinlikler