Forum rules - please read before posting.

Feature request: Check presence for inactive players

edited June 2020 in Engine development

Hi!

Correct me if I'm wrong but there is currently no action that can check if an inactive player is present in the scene other than using Check presence and referencing the object via ConstantID.

I'd suggest adding a select player dropdown (the same as in for example ActionSpeech) to that same action so checking for inactive players would be so much easier!

I can imagine that with the improved (and amazing) player workflow this would be a really great addition! :smile:

Edit: Just remembered it's possible to check current scene of a player via Scene: Check, but a scene name must be entered.

Comments

  • Agreed that this would be useful.

    I'll consider how this might be added officially, but here's a custom Action that would do this in the meantime:

    using UnityEngine;
    using System.Collections.Generic;
    
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionPlayerSceneCheck : ActionCheck
        {
    
            public int playerID = -1;
            public int playerParameterID = -1;
    
            private int runtimePlayerID;
    
    
            public ActionPlayerSceneCheck ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Scene;
                title = "Check player is in current";
            }
    
    
            public override void AssignValues (List<ActionParameter> parameters)
            {
                runtimePlayerID = AssignInteger (parameters, playerParameterID, playerID);
            }
    
    
            public override bool CheckCondition ()
            {
                int actualSceneNumber = 0;
    
                if (KickStarter.settingsManager == null || KickStarter.settingsManager.playerSwitching == PlayerSwitching.DoNotAllow)
                {
                    runtimePlayerID = -1;
                }
    
                if (runtimePlayerID >= 0)
                {
                    PlayerData playerData = KickStarter.saveSystem.GetPlayerData (runtimePlayerID);
                    if (playerData != null)
                    {
                        return SceneChanger.CurrentSceneIndex == playerData.currentScene;
                    }
                    else
                    {
                        LogWarning ("Could not find scene data for Player ID = " + playerID);
                    }
                }
    
                return false;
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI (List<ActionParameter> parameters)
            {
                if (KickStarter.settingsManager != null && KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
                {
                    playerParameterID = ChooseParameterGUI ("Player:", parameters, playerParameterID, ParameterType.Integer);
                    if (playerParameterID < 0)
                    {
                        playerID = ChoosePlayerGUI (playerID, true);
                    }
                }
            }
    
            #endif
    
        }
    
    }
    
  • Awesome, thanks!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.