คําสั่งแชทข้อความที่กําหนดเอง

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

TextChatService มีคำสั่งแชทที่ติดตั้งไว้สำหรับวัตถุประสงค์ทั่วไป เช่น การปิดเสียงผู้เล่นคนอื่นและการใช้อีโมทของอวาตาร์คุณสามารถเปิดใช้งานได้โดยการตั้งค่า CreateDefaultCommands เป็น true ในหน้าต่างคุณสมบัติของ Studio **** คุณยังสามารถเพิ่มคำสั่งที่กําหนดเองโดยใช้ TextChatCommand ได้ผู้ใช้ส่งคำสั่งที่กำหนดไว้ในแถบการใส่ข้อความแชทกระตุ้นการเรียกกลับที่กำหนดโดย TextChatCommand.Triggered เพื่อดําเนินการด้วยการกำหนดเองแบบกำหนดเองของคุณ

ตัวอย่างต่อไปนี้แสดงวิธีการสร้างคำสั่งแชทที่ช่วยให้ผู้เล่นเพิ่มหรือลดขนาดตัวละครของพวกเขาเมื่อพวกเขาป้อน /super หรือ /mini

  1. เพิ่มตัวอย่าง TextChatCommand ภายใน TextChatService

  2. เปลี่ยนชื่อเป็น SizeCommand

  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)