TeleportOptions

显示已弃用

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

该类是可选参数到 TeleportService:TeleportAsync() 函数,允许开发人员为传送调用提供参数。

此类中的某些参数不兼容互相,传到 TeleportService:TeleportAsync() 时会导致错误:

  • 保留服务器访问代码 + 服务器实例ID
  • 应保留服务器 + ServerInstanceId
  • 应保留服务器 + 保留服务器访问代码

了解有关如何在服务器之间传送玩家的更多信息,请参阅传送到地方之间

概要

属性

方法

属性

ReservedServerAccessCode

读取并联

该属性表示用户(们)应该传送到的保留服务器的保留服务器访问代码。

了解有关如何在服务器之间传送玩家的更多信息,请参阅传送到地方之间

ServerInstanceId

读取并联

该属性表示用户(s)应该传送到服务器实例的DataModel.JobId

了解有关如何在服务器之间传送玩家的更多信息,请参阅传送到地方之间

ShouldReserveServer

读取并联

该属性表示是否应该创建新的保留服务器来进行传送呼叫。当设置为真时,将创建一个保留服务器,玩家(们)将被传送到新服务器。

如果设置为 false,玩家(s)将被传送到指定的公共服务器TeleportOptions.ServerInstanceId,如果提供。当 TeleportOptions.ServerInstanceId 为空或未找到匹配的服务器时,会创建一个新的公共服务器来传送玩家(们)。

了解有关如何在服务器之间传送玩家的更多信息,请参阅传送到地方之间

方法

GetTeleportData

Variant

该函数返回由 TeleportOptions 存储在 TeleportOptions:SetTeleportData() 实例中的传送数据。

一旦玩家进行了传送,传送数据可以使用 Player:GetJoinData()TeleportService:GetLocalPlayerTeleportData() 函数进行检索。

了解有关如何在服务器之间传送玩家的更多信息,请参阅传送到地方之间


返回

Variant

SetTeleportData

()

这是传递数据到目的场景的设置函数。在目的场景,这些数据可以使用 Player:GetJoinData()TeleportService:GetLocalPlayerTeleportData() 来检索。

例如,以下代码片段将发送 DataModel.PlaceIdDataModel.JobId 在一个字典中传递传送数据在 TeleportOptions 实例上使用 TeleportOptions:SetTeleportData() :


-- 服务器
local teleportOptions = Instance.new("TeleportOptions")
local teleportData = {
placeId = game.PlaceId,
jobId = game.JobId
}
teleportOptions:SetTeleportData(teleportData)
TeleportService:TeleportAsync(game.PlaceId, {player}, teleportOptions)

此数据然后可以使用获取本地玩家传送数据()函数在到达时恢复如下:


-- 客户
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()
if teleportData then
local placeId = teleportData.placeId
local jobId = teleportData.JobId
end

如果在传送函数中没有设置teleportData,这个 GetLocalPlayerTeleportData()将返回nil

了解有关如何发送和接收用户数据以及传送的更多信息,请参阅在地点之间传送

参数

teleportData: Variant

数据将传送到目的场景。

默认值:""

返回

()

活动