PolicyService 幫助您查詢基於年齡範圍、位置和平台類輸入的全球玩家政策遵守情況的信息。
概要
方法
決定使用者是否能在體驗內看到品牌項目資產。
根據地理定位、年齡群組和平台返回關於玩家的政策資訊。
屬性
方法
CanViewBrandProjectAsync
決定使用者是否能在體驗內看到品牌項目資產。這個方法讓你與品牌合作,只向品牌相容的觀眾顯示商業資產。
若要使用 CanViewBrandProjectAsync,您必須使用 Roblox 提供的品牌項目 ID。若要請求品牌項目 ID,請 聯繫我們。
您必須在服務器端的腳本上呼叫此方法並將其包裝在 pcall() 中。
參數
你正在嘗試將品牌項目展示給的 Player 對象。
由 Roblox 提供的品牌項目 ID 代表與品牌項目相關的所有資產。
返回
品牌項目是否可以顯示給特定使用者。
範例程式碼
You must call CanViewBrandProjectAsync from the server-side and then fire an event on the client. Calling this method from the client-side returns an error.
-- In ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PolicyService = game:GetService("PolicyService")
-- Pre-created RemoteEvent in ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local brandedAsset = ReplicatedStorage:WaitForChild("BrandedAsset")
local defaultAsset = Instance.new("Part")
Players.PlayerAdded:Connect(function(player)
-- PolicyService:CanViewBrandProjectAsync can only be called from the Server
local success, canView = pcall(function()
return PolicyService:CanViewBrandProjectAsync(player, "BRP-0123456789")
end)
if success and canView then
RemoteEvent:FireClient(player, brandedAsset)
else
RemoteEvent:FireClient(player, defaultAsset)
end
end)
-- In StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Pre-created RemoteEvent in ReplicatedStorage
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
RemoteEvent.OnClientEvent:Connect(function(partToLoad)
local clonedPart = partToLoad:Clone()
clonedPart.Parent = workspace
end)
GetPolicyInfoForPlayerAsync
根據地理定位、年齡群組和平台返回關於玩家的政策信息。返回的字典結構如下:
<th>類型</th><th>需要為</th><th>說明</th></tr></thead><tbody><tr><td><code>允許廣告</code></td><td>Boolean 值</td><td>包含 <a href="/production/monetization/immersive-ads">沉浸廣告</a> 的任何體驗。</td><td>當 <code>真實</code> 時,玩家可能會在體驗中看到沉浸式廣告。</td></tr><tr><td><code>付費隨機項目受限</code></td><td>Boolean 值</td><td>任何擁有付費隨機物品的體驗。</td><td>當 <code>真實</code> 時,玩家無法 <b>與付費隨機物品生成器互動</b>,例如通過使用 Robux 購買經驗貨幣或直接與 Robux 交互。</td></tr><tr><td><code>允許外部鏈接參考</code></td><td>阵列</td><td>任何引用外部鏈接的體驗。</td><td>一個列表外部鏈接參考,例如社交媒體鏈接、處理或圖像,玩家可以查看。可能的值包括 <code>"Discord"</code>、<code>"Facebook"</code>、<code>"Twitch"</code>、<code>"YouTube"</code>、<code>"X"</code>、<code>"GitHub"</code> 和 <code>"Guilded"</code>。</td></tr><tr><td><code>是否允許共享內容</code></td><td>Boolean 值</td><td>任何允許用戶在平台上分享內容的體驗。</td><td>當 <code>真實</code> 時,玩家可以使用開啟外部共享流程的 API 分享內容,例如 <code>Class.CaptureService:PromptShareCapture()|PromptShareCapture()</code> 。</td></tr><tr><td><code>可購買訂閱的是否資格</code></td><td>Boolean 值</td><td>任何想要出售訂閱的經驗。</td><td>當 <code>true</code> 時,玩家可以在體驗中購買訂閱。</td></tr><tr><td><code>付費項目交易允許</code></td><td>Boolean 值</td><td>任何允許用戶購買並與其他玩家交易虛擬物品的體驗。</td><td>當 <code>true</code> 時,玩家可以用體驗貨幣或 Robux 購買的虛擬物品進行交易。</td></tr><tr><td><code>受中國政策影響</code></td><td>Boolean 值</td><td>任何在中國可用的體驗。</td><td>當 <code>真實</code> 時,體驗應強制執行更改規格。請參閱 <a href="https://devforum.roblox.com/t/new-programs-available-roblox-china-licensed-to-operate/1023361">此論壇貼文</a> 獲得更多信息。</td></tr></tbody>
名稱 |
---|
例外
與任何异步呼叫一樣,此方法需要被包裝在 pcall() 並且正確處理錯誤。完整的可能錯誤訊息及其原因清單是:
<th>原因</th></tr></thead><tbody><tr><td>實例不是玩家</td><td>玩家 <code>參數</code> 不是 <code>Class.Player</code> 實個體、實例。</td></tr><tr><td>找不到玩家</td><td><code>Class.Players</code> 對象缺少內部錯誤。</td></tr><tr><td>此方法無法在客戶端呼叫非本地玩家</td><td>此方法無法在客戶端呼叫非本地 <code>Class.Player</code> 。</td></tr><tr><td>GetPolicyInfoForPlayerAsync 被呼叫了太多次</td><td>內部錯誤,<code>GetPolicyInfoForPlayerAsync()</code>被稱為超過100次(當前設設定)之前,HTTP回應將返回。</td></tr></tbody>
訊息 |
---|
也可以參考 LocalizationService:GetCountryRegionForPlayerAsync() ,它會根據玩家的客戶端 IP 地理定位返回國家/地區代碼字串。
參數
返回
包含請求玩家政策資訊的辭典;參見上面的辭典結構。
範例程式碼
This code sample gets policy information for the local player and warns if they cannot interact with paid random item generators.
local PolicyService = game:GetService("PolicyService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local success, result = pcall(function()
return PolicyService:GetPolicyInfoForPlayerAsync(player)
end)
if not success then
warn("PolicyService error: " .. result)
elseif result.ArePaidRandomItemsRestricted then
warn("Player cannot interact with paid random item generators")
end