Forum rules - please read before posting.

Button Mash Randomizer

Hello everyone,
I was wondering if there was a way to randomize the Interaction button that the user must press in a QTE event (for the moment I'm thinking only about the Button Mash, but the same principle could be applied to any QTE). Until now I've tried fiddling with the SetInteractionParameters class, in which I wanted to set via script the value passed to the parameter, but I can't understand where this value is saved. Can somebody help me?

Thanks
Willy

Comments

  • edited January 2021

    Overriding the "Input button name" field with a String parameter is the way to go.

    For it to be random, though, you're going to need to rely on a custom script to set the parameter value. The basic principle is that you hook into the OnBeginActionList custom event, and update the ActionList's parameter value before the Action itself is run.

    Something like this should do it:

    using UnityEngine;
    using AC;
    
    public class SetRandomStringParameter : MonoBehaviour
    {
    
        public ActionList actionList;
        public int parameterID;
        public string[] inputs;
    
        private void OnEnable () { EventManager.OnBeginActionList += OnBeginActionList; }
        private void OnDisable () { EventManager.OnBeginActionList -= OnBeginActionList; }
    
        private void OnBeginActionList (ActionList _actionList, ActionListAsset _actionListAsset, int startingIndex, bool isSkipping)
        {
            if (actionList && _actionList == actionList)
            {
                ActionParameter parameter = _actionList.GetParameter (parameterID);
    
                if (parameter != null && parameter.parameterType == ParameterType.String)
                {
                    int randomIndex = Random.Range (0, inputs.Length);
                    string randomInput = inputs[randomIndex];
                    parameter.stringValue = randomInput;
                }
            }
        }
    
    }
    
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.