Example #1
0
    /*   CONSOLE COMMANDS GO HERE */

    void AllCommands(string command, string[] parameters)
    {
        // Kill the player
        if (command == "kill" || command == "die")
        {
            playerEntity.ReduceHealth(999999);
            ConsoleFeedback("Player killed", true);
        }

        // Heal the player
        else if (command == "heal")
        {
            // Heal to full health
            if (parameters.Length == 1)
            {
                playerEntity.IncreaseHealth(99999);
                ConsoleFeedback("Player healed to full health", true);
            }

            // Heal to defined amount
            else
            {
                // Make sure that the parameter is a number
                if (isInt(parameters [1]))
                {
                    playerEntity.IncreaseHealth(int.Parse(parameters [1]));
                    ConsoleFeedback("Player healed by " + parameters [1], true);
                }
                else
                {
                    ConsoleFeedback("Unable to heal by non-numerical value", false);
                }
            }
        }

        // Change the time scale
        else if (command == "timescale")
        {
            if (parameters.Length == 1)
            {
                ConsoleFeedback("Time scale must take a parameter", false);
            }
            else
            {
                if (isInt(parameters [1]))
                {
                    Time.timeScale = int.Parse(parameters [1]);
                    ConsoleFeedback("Timescale set to " + parameters [1], true);
                }
                else
                {
                    ConsoleFeedback("Cannot change time scale by non-numerical value", false);
                }
            }
        }

        // Player invincibility
        else if (command == "invincible")
        {
            if (parameters.Length == 1)
            {
                ConsoleFeedback("Command requires a second parameter (on/off)", false);
            }
            else
            {
                if (parameters [1] == "on")
                {
                    playerEntity.invincible = true;
                    ConsoleFeedback("Player is now invincible", true);
                }
                else if (parameters [1] == "off")
                {
                    playerEntity.invincible = false;
                    ConsoleFeedback("Player is no longer invincible", true);
                }
                else
                {
                    ConsoleFeedback("Command requires second parameter to be either (on/off)", false);
                }
            }
        }

        // Wipe the inventory
        else if (command == "clearinventory")
        {
            // Wipe the player's inventory
            player.GetComponent <Inventory> ().ClearInventory();
            ConsoleFeedback("Player inventory has been cleared", true);
        }

        // Reset story progress
        else if (command == "resetstory")
        {
            if (parameters.Length == 1)
            {
                checkpointManager.ResetProgress();
                ConsoleFeedback("Story has been reset", true);
            }
        }

        // Noclip
        else if (command == "noclip")
        {
            if (parameters.Length == 2)
            {
                if (parameters [1] == "on")
                {
                    player.GetComponent <Player> ().Noclip        = true;
                    player.GetComponent <NavMeshAgent> ().enabled = false;
                    player.transform.Find("Body_Parts").GetComponent <BoxCollider> ().enabled = false;
                    ConsoleFeedback("Noclip enabled", true);
                }
                else
                {
                    player.GetComponent <Player> ().Noclip        = false;
                    player.GetComponent <NavMeshAgent> ().enabled = true;
                    player.transform.Find("Body_Parts").GetComponent <BoxCollider> ().enabled = true;
                    ConsoleFeedback("Noclip disabled", true);
                }
            }
            else
            {
                ConsoleFeedback("Command takes two parameters: /noclip on/off", false);
            }
        }

        // Killall
        else if (command == "killall")
        {
            storyManager.KillAllEnemies(true, true);
            ConsoleFeedback("Killed all enemies", true);
        }

        // Loadscene
        else if (command == "loadscene")
        {
            if (parameters.Length == 2)
            {
                if (isInt(parameters [1]))
                {
                    SceneManager.LoadScene(int.Parse(parameters [1]));
                }
            }
            else
            {
                ConsoleFeedback("Command takes two parameters: /loadscene <index>", false);
            }
        }

        // Give a pickup
        else if (command == "give")
        {
            if (parameters.Length == 2)
            {
                GameObject obj;
                if (isInt(parameters [1]))
                {
                    // passed in the ID
                    obj = GameObject.Find("Database").transform.Find("Pickups").GetComponent <DatabasePickups> ().GetPickupByID(int.Parse(parameters [1]));
                }
                else
                {
                    // passed in the name
                    obj = GameObject.Find("Database").transform.Find("Pickups").GetComponent <DatabasePickups> ().GetPickup(parameters[1]);
                }

                if (obj != null)
                {
                    GameObject newObj = Instantiate(obj);
                    newObj.name = obj.name;
                    player.GetComponent <Inventory> ().AddItemToInventory(newObj);
                    ConsoleFeedback("Player successfully given item", true);
                    CloseConsole();
                }
                else
                {
                    ConsoleFeedback("Item " + parameters [1] + " not found", false);
                }
            }
            else
            {
                ConsoleFeedback("Command takes two parameters: /give <item name/item id>", false);
            }
        }

        // Command is not found
        else
        {
            ConsoleFeedback("Command not found", false);
        }
    }