开发者产品

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

一个 开发者产品 是用户可以购买多次的物品或能力,例如体验货币、弹药或药水。

创建开发者产品

要创建开发者产品:

  1. 前往 创作 并选择一个体验。
  2. 前往 货币化 > 开发者产品 .
  3. 点击 创建开发者产品
  4. 上传一个图像以显示为产品标志。确保图像不超过 512x512 像素,不包含圆圈边界之外的重要细节,并且处于 .jpg.png.bmp 格式中。
  5. 输入产品的名称和描述。
  6. 将产品价格设置为 Robux。最低价格为 1 Robux,最高价格为 10 亿 Robux。
  7. 点击 创建开发者产品

获取开发者产品 ID

要使用脚本,您需要一个开发者产品 ID。要获取产品 ID:

  1. 前往 货币化 > 开发者产品

  2. 将鼠标悬停在产品缩略图上,单击 按钮,然后从上下文菜单中选择 复制资产 ID

出售开发者产品

在出售开发者产品之前,请确保您正确处理销售收据并向用户授予购买的产品。要这样做,你必须:

  • 使用 ProcessReceipt API 检查购买收据。ProcessReceipt 自动阅读并确认用户在体验之外购买了产品。
  • 验证每个收据的 User ID , Developer Product ID , 收据状态。
  • 如果收据的状态为 打开 ,授予用户他们购买的开发者物品。
  • 用一条消息回应 ProcessReceipt API,确认收到并验证购买的物品已被授予。

你可以以两种方式出售开发者产品:

在你的体验中

要在体验中实现并出售开发者产品,请调用 MarketplaceService 函数。

使用 GetProductInfo 来检索开发者产品的信息,例如名称和价格,然后向用户显示该产品。你可以在体验市场内出售产品,例如。对于开发者产品,第二个参数必须为 Enum.InfoType.Product


local MarketplaceService = game:GetService("MarketplaceService")
-- 将占位符 ID 替换为开发者产品 ID
local productId = 000000
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
end)
if success and productInfo then
-- 显示产品信息
-- 将打印声明替换为用户界面代码来显示产品
print("Developer Product Name: " .. productInfo.Name)
print("Price in Robux: " .. productInfo.PriceInRobux)
print("Description: " .. productInfo.Description)
end

使用 GetDeveloperProductsAsync 来检索与您体验相关的所有开发产品。该函数返回一个 Pages 对象,您可以检查和过滤以构建物品,例如体验商店或产品列表图形用户界面。


local MarketplaceService = game:GetService("MarketplaceService")
local success, developerProducts = pcall(function()
return MarketplaceService:GetDeveloperProductsAsync()
end)
if success and developerProducts then
local firstPage = developerProducts:GetCurrentPage()
for _, developerProduct in firstPage do
-- 将打印声明替换为用户界面代码来显示产品
print(field .. ": " .. value)
end
end

使用 PromptProductPurchase 来提示体验内的产品购买。当用户执行按钮按钮或与供应商 NPC 交谈等操作时,您可以调用此函数。


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- 将占位符 ID 替换为开发者产品 ID
local productId = 000000
local function promptProductPurchase()
local success, errorMessage = pcall(function()
MarketplaceService:PromptProductPurchase(player, productId)
end)
if success then
print("Purchase prompt shown successfully")
end
end

您还可以在 LocalScript 内结合功能。例如,您可以创建一个像按钮或供应商 NPC 一样的 UI 元素,然后使用 GetProductInfo() 将现有开发者产品连接到该元素,检查产品是否待促销,然后使用 PromptProductPurchase() 每当用户单击它时提示购买。


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local button = script.Parent
-- 将占位符 ID 替换为开发者产品 ID
local productId = 000000
-- 当用户单击 UI 按钮时获取产品信息
button.MouseButton1Click:Connect(function()
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
end)
if success and productInfo then
-- 检查产品是否待促销
if productInfo.IsForSale then
print("This is for sale")
-- 提示产品购买
MarketplaceService:PromptProductPurchase(player, productId)
else
-- 通知产品不促销中
print("This product is not currently for sale.")
end
else
print("Error retrieving product info: " .. tostring(productInfo))
end
end)

在你的体验之外

要启用开发者产品在您的体验之外购买,您必须使用 ProcessReceipt API。在用户在体验详情页面的 商店 选项卡进行购买后,您必须使用 ProcessReceipt 来确认他们的购买并在他们进入体验后授予他们物品。

测试模式

测试模式 功能可以帮助你验证你的购买流程,通过模拟开发者产品在你的体验之外购买来验证。你应该使用测试模式来确保在启用外部开发者产品销售之前,你已经正确实现了 ProcessReceipt

你在测试模式下放置的开发者产品只能由你和你的群组成员查看。它们对用户不可见。

要测试您的实现:

  1. 创作者中心 ,转到 货币化 > 开发者产品
  2. 点击 菜单,然后选择 外部购买设置
  3. 外部购买设置 页面,单击 启用测试模式
  4. 一旦测试模式启用,返回到 开发者产品 页面,选择一个产品进行测试。
  5. 基本设置 页面中,选择 允许外部购买 复选框并保存您的更改。
  6. 前往体验详情页面的 商店 选项卡,购买你提供出待售的产品。
  7. 进入体验并确认你收到了你购买的产品。ProcessReceipt的收据状态应更新为 关闭

在您测试实现后,Roblox 验证测试已成功完成,并允许您完全激活功能以在体验之外出售开发者产品。

有关ProcessReceipt和其实现的更多信息,请参阅ProcessReceipt

启用外部销售

要启用外部销售:

  1. 前往 外部购买设置 页面。
  2. 打开 外部购买
  3. 返回到 开发者产品 页面,选择你想在体验之外销售的产品。
  4. 基本设置 页面中,选择 允许外部购买 复选框并保存您的更改。
  5. 确认产品现在可以在体验详情页面的 商店 选项卡购买。

要禁用开发者产品的外部销售,请在 开发者产品 页面选择产品,并清除 允许外部购买 复选框。

限制

  • 在测试模式下出售的物品需要实际 Robux 费用。我们建议测试低成本开发者产品。
  • 测试模式下的物品只能由你或你的群组成员看到。
  • 要外部出售,您的开发者产品 必须 拥有缩略图。
  • 你不应该在体验之外出售以下内容:
    • 支付随机物品
    • 限于特定数量、时间、场景点或用户设置和角色的物品

处理开发者产品购买

用户购买开发者产品后,您必须处理并记录交易。要做到这一点,请使用 Script 内的 ServerScriptService 使用 ProcessReceipt 函数。

有关ProcessReceipt和其实现的更多信息,请参阅ProcessReceipt


local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
-- 例如:产品 ID 123123 将用户带回至满血状态
productFunctions[123123] = function(receipt, player)
local character = player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = humanoid.MaxHealth
-- 表示购买成功
return true
end
end
-- 例如:产品 ID 456456 给用户奖励 100 枚金币
productFunctions[456456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local gold = leaderstats and leaderstats:FindFirstChild("Gold")
if gold then
gold.Value += 100
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- 获取与开发者产品ID关联的处理器函数,并尝试运行它
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- 用户已收到他们的物品
-- 返回“购买已授权”以确认交易
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- 用户的物品无法获得奖励
-- 返回“尚未处理”,并在下次用户加入体验时再次尝试
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- 设置回调
-- 这只能由一个服务器端脚本一次完成
MarketplaceService.ProcessReceipt = processReceipt

开发者产品分析

使用开发者产品分析来分析个人产品的成功,识别趋势,并预测未来的潜在收益。

通过分析,你可以:

  • 查看您在指定时间段内的顶级开发产品。
  • 在时间序列图上展示最多八个最畅销的物品来分析整体销售和净收入。
  • 监控您的目录并按销售额和净收入排序项目。

要访问开发者产品分析:

  1. 前往 创作 并选择一个体验。
  2. 前往 货币化 > 开发者产品 .
  3. 选择 分析 标签。