playMaker

Author Topic: text guide: using Playmaker with Quantum Console  (Read 1543 times)

Twood

  • Junior Playmaker
  • **
  • Posts: 65
text guide: using Playmaker with Quantum Console
« on: December 20, 2021, 10:16:47 PM »
Quantum Console is a fun Unity store asset I picked up on sale recently. It basically gives you one of the old Quake/Skyrim style ~ consoles for your game where you can just type in your command, and you know how that works already I'm sure. It supports autocompletion and parameters too which means fully adjustable cheats and game hacks for testing your game, which is pretty fun. link if you're looking for more info: https://assetstore.unity.com/packages/tools/utilities/quantum-console-128881

So I made examples of the scripts you can use to use Playmaker driven cheats or tests or whatever in your Quantum Console for myself. Maybe somebody else will get some enjoyment out of it so I'll explain it here, and you won't even need any coding knowledge.


Step 1.  Will always be make a new C++ script. The naming convention for new scripts is LikeThisWith capital letters punctuating words, so use that style in the name or you could have problems.

Step 2. Drag your new script on to an object that will have your Playmaker FSM that you want to be used for this. They should both be on the same object.

Step 3. Open the script. It will launch your editor and here you want to add two lines to the top. Underneath using UnityEngine; add these:

Code: [Select]
using QFSW.QC;
using HutongGames.PlayMaker;

Step 4. Now inside the main class curly bracket, under class, insert this:

Code: [Select]
[Command("Eventx", "this sends an event to local playmaker component")]


    void EventX()
    {
        PlayMakerFSM myFsm = GetComponent<PlayMakerFSM>();
        myFsm.SendEvent("Eventx");
    }

Step 5. You're already done with one example! What it does is establish a new command for the console that will be typed out in-game as: Eventx. So you would type Eventx, or just start typing it and press tab in the console and press enter, and it runs the rest of the code. What does it do? It looks at your FSM on this object and starts the event there called "Eventx". So you could use this to transition to whatever you want in an FSM by changing the name after SendEvent. To be clear the command name and event name don't have to be the same, they just happen to be here.

Step 6. We can add as many commands as we want to the same script if we want, so we'll add this one here too. After the last code, try adding this:

Code: [Select]
[Command("Enable", "this activates playmakerFSM component that is deactivated at start")]


    void StartMyFsm()
    {
        this.GetComponent<PlayMakerFSM>().enabled = true;
    }

This code simply turns the FSM component on. You could use this to have FSMs that are deactivated by default, then just run them from the start when they get enabled by a console command.

Step 7. Ok last example. This one shows how to have a console command that allows you to enter variable changes with the command. So you could make a cheat that changes a bunch of player vars and in the console it would be as simple as typing: player 5 10 20  with the numbers representing different stats. QC has a place to describe what the stats are, so this could be quite useful to design testing stuff for your game.

This is the last example:

Code: [Select]
[Command("varchange", "changing playmaker vars with parameters")]

private void VarChange([CommandParameterDescription("attack power")]float a, [CommandParameterDescription("defense power")]float b)
    {
        PlayMakerFSM myFsm = GetComponent<PlayMakerFSM>();

        // loading the playmaker variables

        FsmFloat floatVariable1 = myFsm.FsmVariables.GetFsmFloat("attackpower");
        FsmFloat floatVariable2 = myFsm.FsmVariables.GetFsmFloat("defensepower");

        // setting the console values to the new playmaker values

        floatVariable1.Value = a;
        floatVariable2.Value = b;
    }

All it's doing is establishing two parameters in float a and float b that we are going to use with console command 'varchange'. And what it does is search for playmaker float variables called in this case "attackpower" and "defensepower" and sets them on the playmaker FSM to the new values you put in console.

And that's about it! That should be the majority of what you need to run your playmaker fsms out of Quantum Console.

There is I believe a way to reference playmaker stuff outside the host game object, but honestly I couldn't get that working right as it works a little differently in QC. If anyone does know how that works let me know just for curiosity sake, though it's not really needed for just making some console stuff. Also if you have any questions about the examples let me know.
« Last Edit: December 21, 2021, 01:17:06 AM by Twood »