question

electricytart avatar image
electricytart asked

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

That's all I need

,
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Made Wang avatar image
Made Wang answered

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);
        }
    }
}
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

electricytart avatar image electricytart commented ·

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
}
0 Likes 0 ·
Made Wang avatar image Made Wang electricytart commented ·

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.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.