Classe motore
SocialService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Metodi
CanSendCallInviteAsync(player: Instance):boolean |
CanSendGameInviteAsync(player: Instance,recipientId: User):boolean |
GetEventRsvpStatusAsync(eventId: string):Enum.RsvpStatus |
GetExperienceEventAsync(eventId: string):ExperienceEvent? |
GetPartyAsync(partyId: string):{any} |
GetPlayersByPartyId(partyId: string):{Player} |
GetUpcomingExperienceEventsAsync():{ExperienceEvent} |
HideSelfView():() |
PromptFeedbackSubmissionAsync(options: Dictionary?):() |
PromptGameInvite(player: Instance,experienceInviteOptions: Instance):() |
PromptLinkSharing(player: Player,options: Dictionary):Tuple |
PromptLinkSharingAsync(player: Player,options: Dictionary):Tuple |
PromptPhoneBook(player: Instance,tag: string):() |
PromptRsvpToEventAsync(eventId: string):Enum.RsvpStatus |
ShowSelfView(selfViewPosition: Enum.SelfViewPosition):() |
Eventi
CallInviteStateChanged(player: Instance,inviteState: Enum.InviteState):RBXScriptSignal |
GameInvitePromptClosed(player: Instance,recipientIds: {any}):RBXScriptSignal |
PhoneBookPromptClosed(player: Instance):RBXScriptSignal |
ShareSheetClosed(player: Player):RBXScriptSignal |
Richiami
OnCallInviteInvoked(tag: string,callParticipantIds: {any}):Instance |
Riferimento API
Metodi
CanSendCallInviteAsync
Parametri
Restituzioni
Campioni di codice
ServizioSociale:PromptTelefono()
local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Funzione per controllare se il giocatore può inviare un invito a chiamare
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)
endCanSendGameInviteAsync
Restituzioni
Campioni di codice
Invio di un Invito
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Funzione per controllare se il giocatore può inviare un invito
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)
endGetEventRsvpStatusAsync
Parametri
Restituzioni
Campioni di codice
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
-- Impossibile recuperare lo stato RSVP; non abilitare nessuno dei prompt di prossimità
warn("Impossibile ottenere lo stato RSVP:", 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)GetExperienceEventAsync
Parametri
Restituzioni
ExperienceEvent?
Campioni di codice
SocialService:GetUpcomingExperienceEventsAsync()
local SocialService = game:GetService("SocialService")
-- Scoprire il prossimo evento attivo/imminente e invitare il giocatore a confermare la partecipazione
local function promptNextUpcomingEvent()
local success, eventsOrError = pcall(function()
return SocialService:GetUpcomingExperienceEventsAsync()
end)
if not success then
warn("Errore nel caricamento degli eventi imminenti:", eventsOrError)
return
end
local upcomingEvents = eventsOrError
local selectedEvent
for _, event in ipairs(upcomingEvents) do
if not event.HasStarted and not event.HasEnded then
selectedEvent = event
break
end
end
if selectedEvent then
local success, result = pcall(function()
return SocialService:PromptRsvpToEventAsync(selectedEvent.Id)
end)
if not success then
warn("Errore nell'invito alla conferma:", result)
end
else
warn("Nessun evento futuro disponibile per l'invito.")
return
end
end
promptNextUpcomingEvent()GetPartyAsync
Parametri
Restituzioni
Campioni di codice
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("Il giocatore non è in una festa")
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("Impossibile recuperare i dati della festa")
end
end)GetPlayersByPartyId
Parametri
Restituzioni
{Player}
Campioni di codice
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("Membro della festa: " .. partyMember.Name)
end
else
warn("Il giocatore non è in una festa")
end
end)Ribilanciamento Squadre con Integrazione Party
local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local redTeam = Instance.new("Team")
redTeam.Name = "Squadra Rossa"
redTeam.TeamColor = BrickColor.Red()
redTeam.AutoAssignable = false
redTeam.Parent = Teams
local blueTeam = Instance.new("Team")
blueTeam.Name = "Squadra Blu"
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
-- Chiama questa funzione per riequilibrare le squadre
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:LoadCharacterAsync()
end
end
Players.PlayerAdded:Connect(function(player)
assignPlayerToTeam(player)
player:LoadCharacterAsync()
player:GetPropertyChangedSignal("PartyId"):Connect(function()
if player.PartyId ~= "" then
assignPlayerToTeam(player)
end
end)
end)GetUpcomingExperienceEventsAsync
SocialService:GetUpcomingExperienceEventsAsync():{ExperienceEvent}
Restituzioni
{ExperienceEvent}
Campioni di codice
SocialService:GetUpcomingExperienceEventsAsync()
local SocialService = game:GetService("SocialService")
-- Scoprire il prossimo evento attivo/imminente e invitare il giocatore a confermare la partecipazione
local function promptNextUpcomingEvent()
local success, eventsOrError = pcall(function()
return SocialService:GetUpcomingExperienceEventsAsync()
end)
if not success then
warn("Errore nel caricamento degli eventi imminenti:", eventsOrError)
return
end
local upcomingEvents = eventsOrError
local selectedEvent
for _, event in ipairs(upcomingEvents) do
if not event.HasStarted and not event.HasEnded then
selectedEvent = event
break
end
end
if selectedEvent then
local success, result = pcall(function()
return SocialService:PromptRsvpToEventAsync(selectedEvent.Id)
end)
if not success then
warn("Errore nell'invito alla conferma:", result)
end
else
warn("Nessun evento futuro disponibile per l'invito.")
return
end
end
promptNextUpcomingEvent()HideSelfView
SocialService:HideSelfView():()
Restituzioni
()
PromptFeedbackSubmissionAsync
Parametri
Restituzioni
()
Campioni di codice
SocialService:PromptFeedbackSubmissionAsync()
local SocialService = game:GetService("SocialService")
-- Funzione per richiedere feedback
local function promptForFeedback()
local success, errorMessage = pcall(function()
SocialService:PromptFeedbackSubmissionAsync()
end)
if success then
print("Richiesta di feedback completata")
else
warn("Impossibile richiedere feedback:", errorMessage)
end
end
-- Richiedi feedback quando il giocatore raggiunge un traguardo
local function onMilestoneReached()
promptForFeedback()
end
-- Esempio di utilizzo: Collega a un evento di gioco
game.ReplicatedStorage.MilestoneReached.OnClientEvent:Connect(onMilestoneReached)SocialService:PromptFeedbackSubmissionAsync() — Supporto ai Giocatori
local SocialService = game:GetService("SocialService")
local function promptPlayerSupport()
local success, errorMessage = pcall(function()
SocialService:PromptFeedbackSubmissionAsync({
FeedbackType = Enum.FeedbackType.PlayerSupport,
})
end)
if success then
print("Invito al supporto per i giocatori completato")
else
warn("Impossibile invitare al supporto per i giocatori:", errorMessage)
end
end
-- Esempio di utilizzo: Collegare a un pulsante di aiuto in un ScreenGui
local helpButton = script.Parent:WaitForChild("HelpButton")
helpButton.Activated:Connect(function()
task.spawn(promptPlayerSupport)
end)PromptGameInvite
Restituzioni
()
Campioni di codice
Invio di un Invito
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- Funzione per controllare se il giocatore può inviare un invito
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)
endPromptLinkSharing
PromptLinkSharingAsync
Parametri
| Valore predefinito: "nil" |
Restituzioni
PromptPhoneBook
Restituzioni
()
Campioni di codice
ServizioSociale:PromptTelefono()
local Players = game:GetService("Players")
local SocialService = game:GetService("SocialService")
local player = Players.LocalPlayer
local button = script.Parent
button.Visible = false
-- Funzione per controllare se il giocatore può inviare un invito a chiamare
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)
endPromptRsvpToEventAsync
Parametri
Restituzioni
Campioni di codice
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
-- Impossibile recuperare lo stato RSVP; non abilitare nessuno dei prompt di prossimità
warn("Impossibile ottenere lo stato RSVP:", 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)ShowSelfView
Parametri
| Valore predefinito: "LastPosition" |
Restituzioni
()
Eventi
CallInviteStateChanged
Parametri
Campioni di codice
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
-- Se si sta chiamando o se la rubrica è aperta
if isCalling or isPhonebookOpen then
button.Visible = false
else
button.Visible = true
end
end)GameInvitePromptClosed
PhoneBookPromptClosed
Richiami
OnCallInviteInvoked
Restituzioni
Campioni di codice
SocialService.InvitoChiamataInCorso
local SocialService = game:GetService("SocialService")
local TeleportService = game:GetService("TeleportService")
SocialService.OnCallInviteInvoked = function()
local placeId = 0123456789 -- Questo è l'ID del luogo in cui desideri far partecipare i partecipanti alla chiamata
local accessCode = TeleportService:ReserveServerAsync(placeId)
return { ReservedServerAccessCode = accessCode, PlaceId = placeId }
end