在体验中找到朋友可能很挑战。The SpawnWithFriends 开发者模块 自动将生成玩家移到体验中现有的朋友之一附近。该模块还可以配置为在命令下传送玩家,而不是自动传送。
模块使用
安装
要在体验中使用 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 参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)