在體驗中找到朋友可能很挑戰。與朋友生成 開發者模組 會自動將生成玩家移到體驗中的朋友之一附近。此模組也可以配置為在指令下傳送玩家,而不是自動傳送。
模組使用
安裝
要在體驗中使用 SpawnWithFriends 模組:
確保 模型 排序已選擇,然後單擊 查看全部 按鈕以獲得 類別 。
找到並點擊 開發模組 磚塊。
尋找 與好友生成 模組,然後單擊它或拖放到 3D 視檢視中。
在 導航器 窗口中,將整個 SpawnWithFriends 模型移至 ServerScriptService 。執行體驗時,模組會分配到各種服務並開始運行。
受限生成區域
此模組可能會導致玩家在 VIP 房間、僅限空間等受限區域生成。為了防止玩家傳送到這些區域:
用隱形 Anchored 方塊填滿受限區域。請確保 CanCollide , CanTouch 和 CanQuery 對所有區塊都被禁用 **** 。
阻止將整個監獄房填滿以防止玩家在內部生成 使用每個方磚塊的 標籤 部分或 Studio 的 標籤編輯器 應用標籤 RestrictedSpawnArea 以便 CollectionService 偵測到它們。
將以下代碼貼到 Script 內的 ServerScriptService 中。
腳本local ReplicatedStorage = game:GetService("ReplicatedStorage")local CollectionService = game:GetService("CollectionService")local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))local function validator(playerToTeleport, destinationPlayer, teleportationPoint)-- 逐次通過所有標記的零件for _, area in CollectionService:GetTagged("RestrictedSpawnArea") dolocal relativePosition = area.CFrame:PointToObjectSpace(teleportationPoint.Position)local size = area.Sizelocal inXBounds = relativePosition.X < size.X / 2 and relativePosition.X > -size.X / 2local inZBounds = relativePosition.Z < size.Z / 2 and relativePosition.Z > -size.Z / 2if inXBounds and inZBounds thenreturn false -- 重生目的地在限制區內;取消傳送endendreturn true -- 重生目的地不重疊任何受限區域;繼續進行傳送endSpawnWithFriends.setTeleportationValidator(validator)
API 參考
功能
設定
設定(config: table )
通過以下鍵/值在 config 表中覆蓋預設配置選項的默認選項。此功能只能從 Script 中呼叫。
關鍵 | 說明 | 預設 |
---|---|---|
teleportToFriendOnRespawn | 如果設為 false,傳送給朋友只能透過 teleportToRandomFriend 手動進行。 | 真的 |
teleportDistance | 玩家之間的生成距離,以厘米為單位。 | 5 |
maxCharacterVelocity | 快於此值的角色不會被選為傳送候選人,例如移動車輛中的角色。 | 48 |
bypassFriendshipCheck | 如果設為真實, 所有 玩家都將是傳送候選人,不僅限於朋友。 | 否 |
showLogs | 是否在輸出中顯示日誌訊息。 | 否 |
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))SpawnWithFriends.configure({teleportToFriendOnRespawn = true,teleportDistance = 5,maxCharacterVelocity = 48,bypassFriendshipCheck = false,showLogs = false})
傳送到隨機朋友
傳送到隨機朋友(playerToTeleport: Player ): boolean
手動觸發將玩家傳送到體驗中的朋友之一。返回是否成功傳送的 boolean;傳送失敗可能是因為伺服器上缺少朋友或無法找到不受干擾的傳送點。此功能只能從 Script 中呼叫。
設定傳送驗證器
設置傳送驗證器(驗證器: function )
允許您通過連接有效的驗證回呼函來執行自定義預傳送檢查。回呼函接收三個參數:
參數 | 說明 |
---|---|
playerToTeleport | 參考正在傳送的 Player 。 |
destinationPlayer | 參考被傳送到的目標 Player ,該 playerToTeleport 正在傳送到。 |
teleportationPoint | CFrame 在那裡 playerToTeleport 正在傳送到。 |
此功能和其回呼只能在 Script 中使用,回呼返回是否應該進行傳送的 boolean 值。例如,下列驗證函數中的 return 邏輯確保生成玩家和目的地玩家都在同一團隊中。
腳本
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))
-- 只有當玩家在同一團隊時才會傳送他們
local function validator(playerToTeleport, destinationPlayer, teleportationPoint)
return playerToTeleport.Team == destinationPlayer.Team
end
SpawnWithFriends.setTeleportationValidator(validator)