사용자 지정 텍스트 채팅 명령

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

TextChatService에는 다른 플레이어를 음소거하고 아바타 감정 표현을 사용하는 등 일반적인 목적을 위한 내장 채팅 명령이 있습니다.Studio의 CreateDefaultCommands 창에서 true 설정하여 활성화할 수 있습니다.

또한 TextChatCommand를 사용하여 사용자 지정 명령을 추가할 수 있습니다.채팅 입력 바에서 정의된 명령을 보내는 사용자는 TextChatCommand.Triggered에 의해 정의된 콜백을 트리거하여 사용자 지정 작업을 수행합니다.

다음 예제에서는 플레이어가 /super 또는 /mini를 입력할 때 캐릭터의 크기를 늘리거나 줄일 수 있는 채팅 명령을 만드는 방법을 보여줍니다.

  1. 내부에 TextChatCommand 인스턴스를 추가하십시오 TextChatService .

  2. 이름을 크기 명령 으로 바꿉니다.

  3. 속성 PrimaryAlias/super 로 설정하고 속성 SecondaryAlias/mini 로 설정합니다.

  4. 다음 Script 를 내부에 ServerScriptService 에 삽입하여 문자 크기를 조정하는 채팅 명령의 콜백을 정의합니다:

    스크립트

    local TextChatService = game:GetService("TextChatService")
    local Players = game:GetService("Players")
    local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")
    sizeCommand.Triggered:Connect(function(textSource, message)
    local scaleMult = 1
    local messageWords = string.split(message, " ")
    if messageWords[1] == "/super" then
    scaleMult = 2
    elseif messageWords[1] == "/mini" then
    scaleMult = 0.5
    end
    local player = Players:GetPlayerByUserId(textSource.UserId)
    if player then
    local character = player.Character
    if character then
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
    for _, child in humanoid:GetChildren() do
    if child:IsA("NumberValue") then
    child.Value *= scaleMult
    end
    end
    end
    end
    end
    end)