Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by ElectricYTArt · Jun 20 at 12:59 AM ·

Does anyone have a script that will ban a player on trigger then load a scene?

That's all I need

,
Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Made Wang · Jun 20 at 09:41 AM

Do you want to ban the player on the client side and then load the scene? You can call BanUsers on the client side via Azure Function Cloud Script and then load the scene in the callback. Referring to the example below, I am testing on Unity. If my understanding is wrong, please explain your needs in detail.

public void BanPlayer()
{
    PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest
    {
        FunctionName = "Test",
        GeneratePlayStreamEvent = true
    },
    (result) =>
    {
        SceneManager.LoadScene("Test");
    },
    (error) =>
    {
        Debug.LogError(error.GenerateErrorReport());
    });
}
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PlayFab;
using PlayFab.Samples;
using System.Collections;
using System.Collections.Generic;
using PlayFab.ServerModels;

namespace Company.Function
{

    public static class Test
    {
        [FunctionName("Test")]
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            var request =new BanUsersRequest{
                Bans=new List<BanRequest>(){
                    new BanRequest{
                        PlayFabId=context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                        DurationInHours=24,
                        Reason="test"
                    }
                }
            };
            var setting=new PlayFabApiSettings{
                TitleId=context.TitleAuthenticationContext.Id,
                DeveloperSecretKey=" "
            };
            var serverApi=new PlayFabServerInstanceAPI(setting);
            return await serverApi.BanUsersAsync(request);
        }
    }
}
Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ElectricYTArt · Jun 21 at 06:37 PM 0
Share

Do you have a script that's a bit like this?

Sorry for being a bit annoying. I just started trying to code with PlayFab.

void OnTriggerEnter(Collider other)
{

	//ban player in trigger
}
avatar image Made Wang ElectricYTArt · Jun 22 at 09:08 AM 0
Share

You just need to call BanPlayer() above in OnTriggerEnter().

If you are new to Azure Function Cloud Script, you can refer to PlayFab CloudScript using Azure Functions Quickstart Guide - PlayFab | Microsoft Docs to get started.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    13 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges