與好友一起重生

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

在遊戲過程中找到朋友可能會很具挑戰性。SpawnWithFriends 開發者模組 自動將重生的玩家移動到遊戲中某位朋友的附近。此模組還可以配置為按命令傳送玩家,而不是自動傳送。

模組使用

安裝

在體驗中使用 SpawnWithFriends 模組:

  1. 從 Studio 的 視窗 菜單或 首頁 標籤工具列,打開 工具箱,並選擇 創作者商店 標籤。

  2. 確保選擇了 模型 排序,然後點擊 查看所有 按鈕以查看 類別

  3. 找到並點擊 磚。

  4. 找到 與好友一起重生 模組並點擊它,或將其拖放到 3D 視圖中。

  5. 檢視器 窗口中,將整個 SpawnWithFriends 模型移動到 ReplicatedStorage。在運行該體驗後,模組將開始運行。

受限重生區域

此模組可能會導致玩家重生在受限區域,如 VIP 房間、僅限進入的空間等。為了防止玩家傳送到這些區域:

  1. 使用不可見的 Anchored 塊填滿受限區域。確保所有塊的 CanCollideCanTouchCanQuery 都已 禁用

    填滿整個監獄房間的區塊,以防止玩家重生進入內部
  2. 使用每個區塊屬性的 標籤 區域,應用標籤 RestrictedSpawnArea 以便 CollectionService 能檢測到它們。

  3. 將以下代碼粘貼到 ServerScriptService 中的一個 Script 中。

    Script

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local CollectionService = game:GetService("CollectionService")
    local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)
    local function validator(playerToTeleport, destinationPlayer, teleportationPoint)
    -- 遍歷所有標記的部分
    for _, area in CollectionService:GetTagged("RestrictedSpawnArea") do
    local relativePosition = area.CFrame:PointToObjectSpace(teleportationPoint.Position)
    local size = area.Size
    local inXBounds = relativePosition.X < size.X / 2 and relativePosition.X > -size.X / 2
    local inZBounds = relativePosition.Z < size.Z / 2 and relativePosition.Z > -size.Z / 2
    if inXBounds and inZBounds then
    return false -- 重生目的地在受限區域內;中止傳送
    end
    end
    return true -- 重生目的地不與任何受限區域重疊;進行傳送
    end
    SpawnWithFriends.setTeleportationValidator(validator)

API 參考

功能

configure

configure(config: table)

通過 config 表中的以下鍵/值來覆蓋默認配置選項。此函數只能從 Script 中調用。

描述默認值
teleportToFriendOnRespawn如果設置為 false,則只有通過 teleportToRandomFriend 來手動傳送到好友。true
teleportDistance玩家之間應該相距的重生距離,以 studs 為單位。5
maxCharacterVelocity移動速度快於此值的角色將不會被選為傳送候選者,例如那些在移動的載具中。48
bypassFriendshipCheck如果設置為 true,所有 玩家都將成為傳送候選者,而不僅僅是好友。false
showLogs是否顯示日誌消息在輸出中。false
Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)
SpawnWithFriends.configure({
teleportToFriendOnRespawn = true,
teleportDistance = 5,
maxCharacterVelocity = 48,
bypassFriendshipCheck = false,
showLogs = false
})

teleportToRandomFriend

teleportToRandomFriend(playerToTeleport: Player): boolean

手動觸發將玩家傳送到他們的一位好友。返回一個布林值,指示傳送是否成功;傳送失敗可能是因為伺服器中沒有好友或無法找到無障礙的傳送點。此函數只能從 Script 中調用。

setTeleportationValidator

setTeleportationValidator(validator: function)

允許您通過連接驗證器回調功能來執行自定義的傳送前檢查。回調接受三個參數:

參數描述
playerToTeleport被傳送的 Player 的引用。
destinationPlayer傳送到的目標 Player 的引用。
teleportationPointCFrame,指向 playerToTeleport 將傳送到的位置。

此函數及其回調只能在 Script 中使用,回調返回一個布林值,指示是否應進行傳送。例如,以下驗證器函數中的 return 邏輯確保重生玩家和目的地玩家在同一隊伍中。

Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnWithFriends = require(ReplicatedStorage.SpawnWithFriends)
-- 只有在同一隊伍時才傳送玩家
local function validator(playerToTeleport, destinationPlayer, teleportationPoint)
return playerToTeleport.Team == destinationPlayer.Team
end
SpawnWithFriends.setTeleportationValidator(validator)
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。