体験内でフレンドを見つけるのは難しいかもしれません。 SpawnWithFriends 開発者モジュール、スポーンしているプレイヤーをバーチャル空間内にいる友達のうちの 1 人の近くに自動的に動かします。 このモジュールでは、コマンドで自動的にではなく、プレイヤーをテレポートするように設定することもできます。
モジュールの使用法
インストール
バーチャル空間内でSpawnWithFriendsモジュールを使用するには、次の手順に従います。
表示タブから、ツールボックスを開き、マーケットプレイスタブを選択します。
モデルのソートが選択されていることを確認し、カテゴリのすべてのボタンを表示をクリックします。
DEV モジュールタイルを見つけてクリックします。
フレンドとのスポーンモジュールを見つけてクリックするか、3D ビューにドラッグ&ドロップします。
エクスプローラウィンドウで、SpawnWithFriendsモデル全体をServerScriptServiceに移動します。 バーチャル空間を実行すると、モジュールはそれ自体をさまざまなサービスに配布し、実行を開始します。
制限されたスポーン領域
このモジュールでは、VIP ルーム、アクセス専用スペースなどの制限されたエリアでプレイヤーがスポーンすることがあります。 プレイヤーがこれらのエリアにテレポートすることを防ぐには、次の手順に従います。
表示タブからアクセスできるタグ編集を使用して、そのタグを各ブロックRestrictedSpawnAreaに適用して、CollectionServiceがそれらを検出するようにします。
以下のコードをServerScriptService内のScriptに貼り付けます。
Scriptlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local CollectionService = game:GetService("CollectionService")local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))local function validator(playerToTeleport, destinationPlayer, teleportationPoint)-- Iterate through all tagged partsfor _, area in ipairs(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 -- Spawn destination is within restricted area; abort teleportationendendreturn true -- Spawn destination doesn't overlap any restricted area; proceed with teleportationendSpawnWithFriends.setTeleportationValidator(validator)
API リファレンス
関数
設定
configure(config:table):nil
デフォルト設定オプションは、configテーブル内の以下のキー/値を使用して上書きします。 この関数は、Scriptからのみ呼び出すことができます。
キー | 概要 | デフォルト |
---|---|---|
teleportToFriendOnRespawn | falseに設定されている場合、フレンドへのテレポートは、teleportToRandomFriendを介して手動でのみ行われます。 | true |
teleportDistance | プレイヤーが互いにスポーンする距離をスタッドで測定します。 | 5 |
maxCharacterVelocity | この値よりも速く移動するキャラクターは、例えば、移動中の車へのテレポートでは選択できません。 | 48 |
bypassFriendshipCheck | trueに設定されている場合、**すべてのプレイヤーがフレンドだけでなく、テレポートの候補になります。 | false |
showLogs | 出力にログメッセージを表示するかどうか。 | false |
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))SpawnWithFriends.configure({teleportToFriendOnRespawn = true,teleportDistance = 5,maxCharacterVelocity = 48,bypassFriendshipCheck = false,showLogs = false})
teleportToRandomFriend
teleportToRandomFriend(playerToTeleport:Player):boolean
バーチャル空間内にいる友達の一人のところへプレイヤーのテレポートを手動でトリガーします。 テレポートの失敗は、サーバーにフレンドがいない、または障害のないテレポートポイントを見つけることができないことによって引き起こされる可能性があります。 この関数は、Scriptからのみ呼び出すことができます。
setTeleportationValidator
setTeleportationValidator(validator:function):nil
バリデータのコールバック関数をフックアップして、カスタムテレポートの事前チェックを行えます。 コールバックは 3 つのパラメータを受け取ります。
パラメータ | 概要 |
---|---|
playerToTeleport | テレポートされているPlayerへの参照。 |
destinationPlayer | playerToTeleportがテレポートされているターゲットPlayerへの参照。 |
teleportationPoint | CFrame、これはplayerToTeleportがテレポートしている場所。 |
この関数とそのコールバックは、Script内でのみ使用でき、コールバックは、テレポートが進むべきかどうかを示すブール値を返します。 例えば、以下のバリデータ関数内のreturnロジックでは、スポーンプレイヤーと宛先プレイヤーが同じチームであることを保証します。
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnWithFriends = require(ReplicatedStorage:WaitForChild("SpawnWithFriends"))
-- Teleports players only if they are on the same team
local function validator(playerToTeleport, destinationPlayer, teleportationPoint)
return playerToTeleport.Team == destinationPlayer.Team
end
SpawnWithFriends.setTeleportationValidator(validator)