SocialService

แสดงที่เลิกใช้งานแล้ว

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

ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

บริการโซเชียล ช่วยให้การทำงานทางสังคมที่มีผลกระทบต่อความสัมพันธ์ที่ทำบนแพลตฟอร์ม Robloxการใช้งานหลักคือการแสดง แจ้งเตือนการเชิญ และสมุดโทรศัพท์ให้กับผู้เล่นเพื่อให้พวกเขาสามารถส่งคำขอเชิญไปยังเพื่อนของพวกเขาผ่าน PromptGameInvite() และ PromptPhoneBook() ตามลำดับคุณสามารถใช้สัญญาณเมื่อมีคำขอดังกล่าวได้

สรุป

วิธีการ

  • GetPlayersByPartyId(partyId : string):Instances

    คืนตารางของวัตถุทั้งหมดที่เชื่อมต่ออยู่ในปัจจุบัน Player ที่มีคุณสมบัติ Player.PartyId ตรงกับที่ส่ง partyId

  • ซ่อนมุมมองตนเองของผู้เล่นที่เรียก

  • PromptGameInvite(player : Instance,experienceInviteOptions : Instance):()

    แจ้งให้ผู้ใช้ให้ Player กับหน้าจอเชิญ

  • PromptPhoneBook(player : Instance,tag : string):()

    ส่งคำถามให้กับ Player ที่กำหนดด้วยสมุดโทรศัพท์

  • ShowSelfView(selfViewPosition : Enum.SelfViewPosition):()

    แสดงมุมมองตนเองของผู้เล่นที่เรียก

  • ผลตอบแทน

    บ่งบอกว่าให้ Player ที่กำหนดสามารถเชิญผู้เล่นคนอื่นเข้าสู่การโทรได้หรือไม่

  • ผลตอบแทน

    บ่งบอกว่าให้ Player ที่กำหนดสามารถเชิญผู้เล่นคนอื่นได้หรือไม่

  • ผลตอบแทน

    ส่งสถานะ RSVP ของผู้เล่นท้องถิ่นสำหรับอีเวนต์ที่กำหนดให้

  • ผลตอบแทน

    คืนค่าเป็นคอลเลกชันของสารานุกรมที่มีข้อมูลสำหรับสมาชิกทั้งหมดของกลุ่มที่กำหนดที่อยู่ในประสบการณ์ในปัจจุบัน

  • ผลตอบแทน

    ส่งคำแนะนำให้กับท้องถิ่น Player ด้วยคำแนะนำในการเปลี่ยนสถานะ RSVP เป็นอีเวนต์ที่กำหนด

อีเวนต์

Callbacks

  • OnCallInviteInvoked(tag : string,callParticipantIds : Array):Instance

    การโทรกลับเมื่อมีการวางสายจากสมุดโทรศัพท์

คุณสมบัติ

วิธีการ

GetPlayersByPartyId

Instances

คืนตารางของวัตถุทั้งหมดที่เชื่อมต่ออยู่ในปัจจุบัน Player ที่มีคุณสมบัติ Player.PartyId ตรงกับที่ให้ไว้ partyIdวิธีนี้มีพฤติกรรมคล้ายกับ Players:GetPlayers() แต่กรองผลลัพธ์เพื่อรวมเฉพาะผู้เล่นที่เป็นส่วนหนึ่งของปาร์ตี้ที่ระบุเท่านั้น

โปรดทราบว่าบริการนี้ไม่ทำงานในระหว่างการทดสอบเล่นใน Roblox Studio; เพื่อทดสอบด้านของประสบการณ์ของคุณโดยใช้มันคุณต้องเผยแพร่ประสบการณ์และเล่นในแอปพลิเคชัน Roblox

พารามิเตอร์

partyId: string
ค่าเริ่มต้น: ""

ส่งค่ากลับ

Instances

ตารางของวัตถุ Player ที่มีคุณสมบัติ Player.PartyId ตรงกับที่ส่ง partyId

ตัวอย่างโค้ด

The following example listens for when a player joins the experience. If the player is part of a party, it uses SocialService:GetPlayersByPartyId() to retrieve all players in the same party who are currently connected to the server. It then outputs the name of each party member.

SocialService:GetPlayersByPartyId()

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local partyId = player.PartyId
if partyId ~= "" then
local partyPlayers: { Player } = SocialService:GetPlayersByPartyId(partyId)
for _, partyMember in partyPlayers do
print("Party Member: " .. partyMember.Name)
end
else
warn("Player is not in a party")
end
end)

This code sample demonstrates how to assign players to Teams based on their Player.PartyId using the SocialService:GetPlayersByPartyId() method. When a player joins the experience, the script checks whether they're part of a party. If so, it attempts to assign them to the same team as other party members. If no match is found or the player isn't in a party, they're placed on the team with fewer members to maintain balance.

Team Rebalance with Party Integration

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local redTeam = Instance.new("Team")
redTeam.Name = "Red Team"
redTeam.TeamColor = BrickColor.Red()
redTeam.AutoAssignable = false
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.Name = "Blue Team"
blueTeam.TeamColor = BrickColor.Blue()
blueTeam.AutoAssignable = false
blueTeam.Parent = Teams
local function assignPlayerToTeam(player)
local partyId = player.PartyId
if partyId == "" then
assignBalancedTeam(player)
return
end
local teams = { redTeam, blueTeam }
local matchingTeam = nil
local partyPlayers = SocialService:GetPlayersByPartyId(partyId)
for _, partyPlayer in partyPlayers do
if partyPlayer ~= player and table.find(teams, partyPlayer.Team) then
matchingTeam = partyPlayer.Team
break
end
end
if matchingTeam then
player.Team = matchingTeam
player.TeamColor = matchingTeam.TeamColor
else
assignBalancedTeam(player)
end
end
function assignBalancedTeam(player)
local redCount = #redTeam:GetPlayers()
local blueCount = #blueTeam:GetPlayers()
local chosenTeam = redCount <= blueCount and redTeam or blueTeam
player.Team = chosenTeam
player.TeamColor = chosenTeam.TeamColor
end
local function groupPlayersByParty()
local seenPartyIds = {}
local groupedPlayers = {}
for _, player in Players:GetPlayers() do
if player.PartyId == "" then
table.insert(groupedPlayers, { player })
elseif not table.find(seenPartyIds, player.PartyId) then
table.insert(seenPartyIds, player.PartyId)
local partyPlayers = SocialService:GetPlayersByPartyId(player.PartyId)
table.insert(groupedPlayers, partyPlayers)
end
end
return groupedPlayers
end
-- Call this function to rebalance teams
local function rebalanceTeams()
local groups = groupPlayersByParty()
table.sort(groups, function(a, b)
return #a > #b
end)
for _, player in Players:GetPlayers() do
player.Team = nil
end
for _, group in groups do
local redCount = #redTeam:GetPlayers()
local blueCount = #blueTeam:GetPlayers()
local bestTeam
if redCount <= blueCount then
bestTeam = redTeam
else
bestTeam = blueTeam
end
for _, player in group do
player.Team = bestTeam
player.TeamColor = bestTeam.TeamColor
end
end
for _, player in Players:GetPlayers() do
player:LoadCharacter()
end
end
Players.PlayerAdded:Connect(function(player)
assignPlayerToTeam(player)
player:LoadCharacter()
player:GetPropertyChangedSignal("PartyId"):Connect(function()
if player.PartyId ~= "" then
assignPlayerToTeam(player)
end
end)
end)

HideSelfView

()

ซ่อนมุมมองตัวเองของผู้เล่นที่เรียก หากวิธีนี้ถูกเรียกในขณะที่มุมมองตัวเองถูกซ่อนไว้แล้ว มันจะไม่ทำอะไรเลย


ส่งค่ากลับ

()

PromptGameInvite

()

PromptGameInvite() แสดงคำเชิญชวนให้กับผู้เล่นท้องถิ่นผ่านทางซึ่งพวกเขาสามารถเชิญเพื่อนของพวกเขาไปยังประสบการณ์ปัจจุบันได้ก่อนที่จะเรียกวิธีนี้คุณควรใช้ CanSendGameInviteAsync() เพื่อตรวจสอบว่าผู้เล่นสามารถส่งคำเชิญได้หรือไม่เนื่องจากความสามารถนี้อาจแตกต่างกันไปขึ้นอยู่กับแพลตฟอร์มหรือผู้เล่น

ดู คำเชิญชวนผู้เล่น สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับการดำเนินการคำเชิญชวน, การปรับแต่งคำเชิญชวนและการแจ้งเตือน และการใช้ข้อมูลเปิดตัว

พารามิเตอร์

player: Instance

The Player เพื่อยืนยันด้วยป๊อปอัพการเชิญ

ค่าเริ่มต้น: ""
experienceInviteOptions: Instance

วัตถุทางเลือก ExperienceInviteOptions สำหรับการปรับแต่งแจ้งเตือน

ค่าเริ่มต้น: "nil"

ส่งค่ากลับ

()

ตัวอย่างโค้ด

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

PromptPhoneBook

()

ส่งคำถามให้กับ Player ที่กำหนดด้วยสมุดโทรศัพท์หากผู้เล่นเลือกที่จะโทรหาใครสักคน กิจกรรม CallInviteStateChanged จะเกิดขึ้นคุณควรใช้ CanSendCallInviteAsync() ก่อนที่จะโทร PromptPhoneBook() เนื่องจากความสามารถในการดูรายชื่อโทรศัพท์อาจแตกต่างกันไปขึ้นอยู่กับผู้เล่น

หากผู้เล่นไม่สามารถเปิดหนังสือโทรศัพท์ได้ จะมีการแสดงข้อความแจ้งข้อผิดพลาด

ดู Roblox Connect สำหรับการใช้งานตัวอย่างของวิธีนี้

พารามิเตอร์

player: Instance

ผู้เล่นที่จะแจ้งกับหนังสือโทรศัพท์

ค่าเริ่มต้น: ""
tag: string

สตริงเพื่อช่วยแยกแยะระหว่างจุดเข้า "หนังสือโทรศัพท์" หรือคล้ายกันตัวอย่างเช่น คุณสามารถส่งสตริงที่กำหนดว่าภูมิภาคของประสบการณ์ที่ตัวเล่นเรียกอยู่ในปัจจุบันอยู่ในภูมิภาคใด

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

ShowSelfView

()

แสดงมุมมองตัวเองของผู้เล่นที่เรียก หากวิธีนี้ถูกเรียกในขณะที่มุมมองตัวเองมีอยู่แล้ว มันจะไม่ทำอะไรเลย

พารามิเตอร์

selfViewPosition: Enum.SelfViewPosition

ตำแหน่งที่จะวางมุมมองตนเอง

ค่าเริ่มต้น: "LastPosition"

ส่งค่ากลับ

()

CanSendCallInviteAsync

ผลตอบแทน

ส่งคืน true หากการให้ Player สามารถส่งคำเชิญโทรไปยังเพื่อนได้คุณควรใช้ผลของวิธีนี้เสมอก่อนที่จะโทร PromptPhoneBook() เนื่องจากความสามารถในการเปิดสมุดโทรศัพท์อาจแตกต่างกันไปขึ้นอยู่กับผู้เล่น

ดู Roblox Connect สำหรับการใช้งานตัวอย่างของวิธีนี้

พารามิเตอร์

player: Instance

ตัวอย่าง Player ของผู้เล่นอาจส่งคำเชิญโทรได้

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ว่าผู้เล่นที่ระบุสามารถส่งคำเชิญโทรได้หรือไม่

ตัวอย่างโค้ด

The following code sample, placed within a child LocalScript of a GuiButton, uses CanSendCallInviteAsync() to confirm that the player can make a call. If so, it connects PromptPhoneBook() to the button's Activated event.

SocialService:PromptPhoneBook()

local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Function to check whether the player can send a call invite
local function canSendCallingInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendCallInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canCall = canSendCallingInvite(player)
if canCall then
button.Visible = true
button.Activated:Connect(function()
SocialService:PromptPhoneBook(player, "")
end)
end

CanSendGameInviteAsync

ผลตอบแทน

CanSendGameInviteAsync() ส่งคืน true หากการให้ Player สามารถเชิญผู้เล่นคนอื่นเข้าสู่ประสบการณ์ปัจจุบันได้คุณควรใช้ผลของวิธีนี้เสมอก่อนที่จะเรียก PromptGameInvite() เนื่องจากความสามารถในการเชิญผู้เล่นอาจแตกต่างกันไปขึ้นอยู่กับแพลตฟอร์มหรือผู้เล่น

ดู คําเชิญผู้เล่น สําหรับรายละเอียดเพิ่มเติมเกี่ยวกับการดําเนินการคําเชิญผู้เล่นการปรับแต่งคําเชิญและการแจ้งเตือน และการใช้ข้อมูลเปิดตัว

พารามิเตอร์

player: Instance

ตัวอย่าง Player ของผู้เล่นที่อาจส่งคำเชิญ

ค่าเริ่มต้น: ""
recipientId: number

ตัวเลือก Player.UserId ของผู้รับที่อาจจะเป็นไปได้ **** ใช้เพื่อตรวจสอบว่าผู้ส่งสามารถเชิญผู้รับเฉพาะรายนั้นได้หรือไม่

ค่าเริ่มต้น: 0

ส่งค่ากลับ

ว่าผู้เล่นที่ระบุสามารถส่งคำเชิญได้หรือไม่

ตัวอย่างโค้ด

The following code sample uses CanSendGameInviteAsync() to confirm whether the local Player can send an invite. If true, it then prompts the invite using PromptGameInvite().

Sending an Invite

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Function to check whether the player can send an invite
local function canSendGameInvite(sendingPlayer)
local success, canSend = pcall(function()
return SocialService:CanSendGameInviteAsync(sendingPlayer)
end)
return success and canSend
end
local canInvite = canSendGameInvite(player)
if canInvite then
SocialService:PromptGameInvite(player)
end

GetEventRsvpStatusAsync

ผลตอบแทน

ส่งสถานะ RSVP ของผู้เล่นท้องถิ่นสำหรับอีเวนต์ที่กำหนดให้อีเวนต์ต้องอยู่ในประสบการณ์ปัจจุบันและไม่ควรเริ่มแล้วหากอีเวนต์เริ่มแล้ว วิธีนี้จะส่งคืนข้อผิดพลาด

โปรดทราบว่าคุณสามารถใช้ PromptRsvpToEventAsync() เพื่อขอให้ผู้เล่นเปลี่ยนสถานะ RSVP สำหรับอีเวนต์

พารามิเตอร์

eventId: string

รหัสอีเวนต์ของอีเวนต์ที่จะขอให้ผู้เล่นเปลี่ยนสถานะ RSVP ของพวกเขานี่ต้องเป็นรหัสอีเวนต์ที่ถูกต้องที่มีอยู่ในประสบการณ์ปัจจุบัน แสดงเป็นข้อความ (ไม่ใช่ตัวเลข)

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ส่งคืน Enum.RsvpStatus บ่งบอกสถานะ RSVP ปัจจุบันของผู้เล่นสำหรับอีเวนต์หากผู้เล่นไม่ได้ RSVP กับอีเวนต์ จะส่งคืน Enum.RsvpStatus.None

ตัวอย่างโค้ด

The following example checks if a player is RSVP'd to an event; if not, it gives them the option to RSVP. If the player is already RSVP'd, it gives them the option to cancel their RSVP.

The following Script assumes that RunContext is set to Enum.RunContext.Client and that two sibling ProximityPrompts are in place: one for following the event and one for unfollowing the event. The prompts are enabled or disabled based on the player's RSVP status.

SocialService:PromptRsvpToEventAsync()

local SocialService = game:GetService("SocialService")
local EVENT_ID = "YOUR_EVENT_ID"
local followPrompt : ProximityPrompt = script.Parent.FollowProximityPrompt
local unFollowPrompt : ProximityPrompt = script.Parent.UnfollowProximityPrompt
local function updatePrompt(rsvpStatus : Enum.RsvpStatus)
if rsvpStatus == Enum.RsvpStatus.Going then
unFollowPrompt.Enabled = true
followPrompt.Enabled = false
else
unFollowPrompt.Enabled = false
followPrompt.Enabled = true
end
end
local success, currentRsvpStatus = pcall(function()
return SocialService:GetEventRsvpStatusAsync(EVENT_ID)
end)
if not success then
-- Could not retrieve RSVP status; don't enable either proximity prompt
warn("Failed to get RSVP status:", currentRsvpStatus)
return
end
print("CurrentRsvpStatus:", currentRsvpStatus)
updatePrompt(currentRsvpStatus)
unFollowPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)
followPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)

GetPartyAsync

ผลตอบแทน

ส่งคืนคอลเลกชันของสารานุกรมที่มีข้อมูลสำหรับสมาชิกทั้งหมดที่เกี่ยวข้องกับ partyId ที่กำหนดรายการที่ส่งคืนสะท้อนสถานะปัจจุบันของปาร์ตี้ในทุกอินสแตนซ์เซิร์ฟเวอร์ที่ใช้งานอยู่ภายในประสบการณ์และจัดเรียงตามเวลาที่สมาชิกปาร์ตี้แต่ละคนยอมรับคำเชิญปาร์ตี้ซึ่งหมายความว่าองค์ประกอบแรกในคลังเป็นองค์ประกอบที่เก่าแก่ที่สุดและองค์ประกอบล่าสุดเป็นองค์ประกอบล่าสุด

วิธีนี้มีประโยชน์สำหรับการดึงข้อมูลล่าสุดเกี่ยวกับสมาชิกในปาร์ตี้ทั้งหมดที่อยู่ในประสบการณ์และผ่านเซิร์ฟเวอร์ต่างๆ เพื่อเปิดใช้งานพฤติกรรมกลุ่มที่ประสานกันเช่นเทเลพอร์ต การจับคู่ หรือโลจิสติกการเล่นเกมของปาร์ตี้ที่ขึ้นอยู่กับกลุ่ม

แต่ละสารานุกรมในคอลเลกชันที่ส่งคืนมีฟิลด์ต่อไปนี้:


<th>ประเภทค่า</th>
<th>คําอธิบาย</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>รหัสผู้ใช้</code></th>
<td>จํานวน</td>
<td>คุณสมบัติ <code>Class.Player.UserId</code> ของผู้เล่น</td>
</tr>
<tr>
<th><code>รหัสสถานที่</code></th>
<td>จํานวน</td>
<td>คลาส <code>Class.DataModel.PlaceId</code> ของสถานที่ที่สมาชิกปาร์ตี้อยู่ในปัจจุบัน</td>
</tr>
<tr>
<th><code>รหัสงาน</code></th>
<td>สตริง</td>
<td>คลาส <code>Class.DataModel.JobId</code> ของตัวอย่างเซิร์ฟเวอร์ที่ผู้ใช้ปัจจุบันอาศัยอยู่</td>
</tr>
<tr>
<th><code>ไอดีเซิร์ฟเวอร์เอกชน</code></th>
<td>สตริง</td>
<td>หากจำเป็น คลาส <code>Class.DataModel.PrivateServerId</code> เมื่อสมาชิกปาร์ตี้อยู่ในเซิร์ฟเวอร์ส่วนตัวหรือสำรอง</td>
</tr>
<tr>
<th><code>รหัสการเข้าถึงเซิร์ฟเวอร์สำรอง</code></th>
<td>สตริง</td>
<td>หากเป็นไปได้ รหัสการเข้าถึงสำหรับเซิร์ฟเวอร์สำรองที่ผู้ใช้อาศัยอยู่ในปัจจุบันมีประโยชน์สำหรับการเทเลพอร์ตสมาชิกปาร์ตี้ไปยังกันโดยใช้ <code>Class.TeleportService:TeleportAsync()</code></td>
</tr>
</tbody>
กุญแจ

โปรดทราบว่าบริการนี้ไม่ทำงานในระหว่างการทดสอบเล่นใน Roblox Studio; เพื่อทดสอบด้านของประสบการณ์ของคุณโดยใช้มันคุณต้องเผยแพร่ประสบการณ์และเล่นในแอปพลิเคชัน Roblox

พารามิเตอร์

partyId: string
ค่าเริ่มต้น: ""

ส่งค่ากลับ

ชุดของสารานุกรมที่แทนตัวแทนสมาชิกของปาร์ตี้ที่กำหนดที่อยู่ในประสบการณ์ในปัจจุบัน

ตัวอย่างโค้ด

The following example checks if a player is in a party when they join. If so, it retrieves the latest party data using SocialService:GetPartyAsync() and outputs the details of each party member.

SocialService:GetPartyAsync()

local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local partyId = player.PartyId
if partyId == "" then
warn("Player is not in a party")
return
end
local success, partyData = pcall(function()
return SocialService:GetPartyAsync(partyId)
end)
if success and partyData then
for _, partyMemberData in partyData do
print(
partyMemberData.UserId,
partyMemberData.PlaceId,
partyMemberData.JobId,
partyMemberData.PrivateServerId,
partyMemberData.ReservedServerAccessCode
)
end
else
warn("Failed to retrieve party data")
end
end)

PromptRsvpToEventAsync

ผลตอบแทน

PromptRsvpToEventAsync() แสดงคำเตือนให้กับผู้เล่นท้องถิ่นผ่านทางซึ่งพวกเขาสามารถเปลี่ยนสถานะ RSVP ไปยังอีเวนต์ที่กำหนดได้

อีเวนต์ต้องอยู่ในประสบการณ์ปัจจุบันและไม่ควรเริ่มแล้ว หากอีเวนต์เริ่มแล้ว วิธีนี้จะส่งคืนข้อผิดพลาด

โปรดทราบว่าคุณสามารถใช้ GetEventRsvpStatusAsync() เพื่อตรวจสอบสถานะ RSVP ปัจจุบันของผู้เล่นก่อนที่จะเรียกใช้วิธีนี้

พารามิเตอร์

eventId: string

รหัสอีเวนต์ของอีเวนต์ที่จะขอให้ผู้เล่นเปลี่ยนสถานะ RSVP ของพวกเขานี่ต้องเป็นรหัสอีเวนต์ที่ถูกต้องที่มีอยู่ในประสบการณ์ปัจจุบัน แสดงเป็นข้อความ (ไม่ใช่ตัวเลข)

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ส่งคืน Enum.RsvpStatus ระบุสถานะ RSVP ใหม่ของผู้เล่นหลังจากที่แจ้งเตือนถูกปิดหากผู้เล่นปิดการแจ้งเตือนโดยไม่เปลี่ยนสถานะ RSVP ของพวกเขาแล้ว จะส่งคืน Enum.RsvpStatus.None หรือสถานะเก่า Enum.RsvpStatus หากพวกเขาได้เลือกสถานะแล้ว

ตัวอย่างโค้ด

The following example checks if a player is RSVP'd to an event; if not, it gives them the option to RSVP. If the player is already RSVP'd, it gives them the option to cancel their RSVP.

The following Script assumes that RunContext is set to Enum.RunContext.Client and that two sibling ProximityPrompts are in place: one for following the event and one for unfollowing the event. The prompts are enabled or disabled based on the player's RSVP status.

SocialService:PromptRsvpToEventAsync()

local SocialService = game:GetService("SocialService")
local EVENT_ID = "YOUR_EVENT_ID"
local followPrompt : ProximityPrompt = script.Parent.FollowProximityPrompt
local unFollowPrompt : ProximityPrompt = script.Parent.UnfollowProximityPrompt
local function updatePrompt(rsvpStatus : Enum.RsvpStatus)
if rsvpStatus == Enum.RsvpStatus.Going then
unFollowPrompt.Enabled = true
followPrompt.Enabled = false
else
unFollowPrompt.Enabled = false
followPrompt.Enabled = true
end
end
local success, currentRsvpStatus = pcall(function()
return SocialService:GetEventRsvpStatusAsync(EVENT_ID)
end)
if not success then
-- Could not retrieve RSVP status; don't enable either proximity prompt
warn("Failed to get RSVP status:", currentRsvpStatus)
return
end
print("CurrentRsvpStatus:", currentRsvpStatus)
updatePrompt(currentRsvpStatus)
unFollowPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)
followPrompt.Triggered:Connect(function(player)
local rsvpStatus = SocialService:PromptRsvpToEventAsync(EVENT_ID)
updatePrompt(rsvpStatus)
end)

อีเวนต์

CallInviteStateChanged

อีเวนต์นี้จะเกิดขึ้นเมื่อสถานะการเชิญสายของผู้เล่นเปลี่ยนแปลง

พารามิเตอร์

player: Instance

ตัวอย่าง Player ของผู้เล่นที่มีสถานะเปลี่ยนการเรียกเรียกเปลี่ยน

inviteState: Enum.InviteState

สถานะการเชิญโทรใหม่


ตัวอย่างโค้ด

SocialService.CallInviteStateChanged

local SocialService = game:GetService("SocialService")
local button = script.Parent
local isPhonebookOpen = false
SocialService.CallInviteStateChanged:Connect(function(_, inviteState)
local isCalling = inviteState == Enum.InviteState.Placed
if isCalling or isPhonebookOpen then
button.Visible = false
else
button.Visible = true
end
end)

GameInvitePromptClosed

อีเวนต์นี้จะเกิดขึ้นเมื่อผู้เล่นปิดการแจ้งเตือนการเชิญ

พารามิเตอร์

player: Instance

ตัวอย่าง Player ของผู้เล่นที่ปิดการแจ้งเตือน

recipientIds: Array

ไม่ได้เติมแล้ว; เป็น阵列ว่างเปล่า


PhoneBookPromptClosed

เกิดไฟไหม้เมื่อผู้เล่นปิดการแจ้งเตือนในสมุดโทรศัพท์

พารามิเตอร์

player: Instance

ตัวอย่าง Player ของผู้เล่นที่ปิดหนังสือโทรศัพท์


Callbacks

OnCallInviteInvoked

การโทรกลับเพื่อดำเนินการเมื่อมีการวางสายจากสมุดโทรศัพท์พารามิเตอร์ tag สามารถใช้เพื่อแยกแยะระหว่าง "จุดเข้า" ที่แตกต่างกันหรือคล้ายกันตามที่อธิบายไว้ใน PromptPhoneBook()สามารถตั้งค่าคอลเลกชันกลับเพียงครั้งเดียว

พารามิเตอร์

tag: string

สตริงเพื่อช่วยแยกแยะระหว่างจุดเข้าสู่รายชื่อโทรศัพท์ที่แตกต่างกัน

callParticipantIds: Array

รายการที่มีผู้เล่นทั้งหมดที่มีส่วนร่วมในการโทร ผู้โทรจะเป็นผู้เล่นแรกในรายการเสมอ


ส่งค่ากลับ

ตารางรวมถึงแป้น PlaceId และ ReservedServerAccessCode ที่มีค่าเป็น DataModel.PlaceId และรหัสการเข้าถึงเซิร์ฟเวอร์ที่ส่งคืนโดย TeleportService:ReserveServer() ตามลำดับ

ตัวอย่างโค้ด

SocialService.OnCallInviteInvoked

local SocialService = game:GetService("SocialService")
local TeleportService = game:GetService("TeleportService")
SocialService.OnCallInviteInvoked = function()
local placeId = 0123456789 -- This is the place ID of the desired place to drop call participants into
local accessCode = TeleportService:ReserveServer(placeId)
return { ReservedServerAccessCode = accessCode, PlaceId = placeId }
end