친구와 함께 스폰하기

체험 내에서 친구를 찾는 것이 어려울 때가 있습니다. SpawnWithFriends 개발자 모듈은 스폰하는 플레이어를 체험 내에 존재하는 친구들 중 한 명의 근처로 자동으로 이동해 줍니다. 이 모듈은 자동이 아니라 명령에 따라 플레이어를 텔레포트하도록 구성할 수도 있습니다.

모듈 사용

설치

체험에서 SpawnWithFriends 모듈을 사용하는 방법

  1. 보기 탭에서 도구 상자를 열고 마켓플레이스 탭을 선택합니다.

    Studio의 도구상자 토글 버튼
  2. 모델 정렬이 선택되었는지 확인한 다음 카테고리에서 모두 보기 버튼을 클릭합니다.

  3. DEV MODULES 타일을 찾아 클릭합니다.

  4. 친구들과 스폰 모듈을 찾아 클릭하거나 3D 보기로 끌어다 놓습니다.

  5. 탐색기 창에서 전체 SpawnWithFriends 모델을 ServerScriptService로 이동합니다. 체험을 실행하면 모듈이 다양한 서비스에 배포되고 실행되기 시작합니다.

스폰 제한 구역

이 모듈에서는 플레이어가 VIP 룸, 액세스 전용 공간 등의 제한된 구역에서 스폰하는 일이 발생할 수 있습니다. 플레이어가 이러한 구역으로 텔레포트하는 것을 방지하는 방법은 다음과 같습니다.

  1. 제한된 구역을 보이지 않는 Anchored 블록으로 채웁니다. 모든 블록에 대해 CanCollide, CanTouchCanQuery비활성화해야 합니다.
플레이어들이 안에서 스폰하지 못하도록 교도소 전체를 채운 블록
  1. 보기 탭에서 액세스할 수 있는 태그 편집기를 사용하여 각 블록에 RestrictedSpawnArea 태그를 적용함으로써 CollectionService가 탐지할 수 있게 합니다.

  2. ServerScriptService 안의 Script에 다음과 같은 코드를 붙여 넣습니다.

    Script

    local 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 parts
    for _, area in ipairs(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 -- Spawn destination is within restricted area; abort teleportation
    end
    end
    return true -- Spawn destination doesn't overlap any restricted area; proceed with teleportation
    end
    SpawnWithFriends.setTeleportationValidator(validator)

API 참조

함수

구성

configure(config:table):nil

config 테이블의 다음 키/값을 통해 기본 구성 옵션을 무효화합니다. 해당 함수는 Script에서만 호출할 수 있습니다.

설명기본
teleportToFriendOnRespawnfalse로 설정될 경우, 친구로 텔레포트하는 것은 teleportToRandomFriend를 통해 수동으로만 가능합니다.true
teleportDistance플레이어가 서로 스폰하는 거리를 스터드로 측정합니다.5
maxCharacterVelocity이 값보다 빨리 움직이는 캐릭터는 텔레포트 후보로 선택되지 않습니다(예: 움직이는 차량에 타고 있는 캐릭터).48
bypassFriendshipChecktrue로 설정될 경우, 친구들뿐만 아니라 모든 플레이어가 텔레포트의 후보가 됩니다.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

검사기 콜백 함수를 연결하여 텔레포트 전에 사용자 지정 검사를 수행할 수 있게 해줍니다. 콜백은 다음의 세 가지 매개변수를 수신합니다.

매개변수설명
playerToTeleport텔레포트되고 있는 Player에 대한 정보입니다.
destinationPlayerplayerToTeleport가 텔레포트되고 있는 대상 Player에 대한 정보입니다.
teleportationPointplayerToTeleport가 텔레포트하는 CFrame입니다.

이 함수와 해당 콜백은 Script에서만 사용할 수 있으며 콜백은 텔레포트를 진행해야 하는지 여부를 나타내는 부울 값을 반환합니다. 예를 들어, 다음과 같은 validator 함수의 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)