Last active
July 4, 2025 06:08
-
-
Save baerchen201/2d1f8e9363c13de1c565ad09651fba5d to your computer and use it in GitHub Desktop.
baer1.ChatCommandAPI example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Linq; | |
| using ChatCommandAPI; | |
| using UnityEngine; | |
| public class CountCommand : Command | |
| { | |
| public override string Name => "CountItems"; | |
| public override string[] Commands => ["count", Name]; | |
| public override string Description => "Counts all items on the map"; | |
| public override bool Invoke(string[] args, Dictionary<string, string> kwargs, out string error) | |
| { | |
| error = null!; | |
| int count = Object | |
| .FindObjectsOfType<GrabbableObject>() | |
| .Count(i => | |
| i is { itemProperties.isScrap: true, isInShipRoom: false, isInElevator: false } | |
| ); | |
| ChatCommandAPI.ChatCommandAPI.Print( | |
| $"There {(count == 1 ? "is" : "are")} {count} object{(count == 1 ? "" : "s")} outside the ship" | |
| ); | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Linq; | |
| using ChatCommandAPI; | |
| using GameNetcodeStuff; | |
| using UnityEngine; | |
| public class CountServerCommand : ServerCommand | |
| { | |
| public override string Name => "CountItems"; | |
| public override string[] Commands => ["count", Name]; | |
| public override string Description => "Counts all items on the map"; | |
| public override bool Invoke( | |
| ref PlayerControllerB? caller, | |
| string[] args, | |
| Dictionary<string, string> kwargs, | |
| out string error | |
| ) | |
| { | |
| error = "caller is null"; | |
| if (caller == null) | |
| return false; | |
| int count = Object | |
| .FindObjectsOfType<GrabbableObject>() | |
| .Count(i => | |
| i is { itemProperties.isScrap: true, isInShipRoom: false, isInElevator: false } | |
| ); | |
| ChatCommandAPI.ChatCommandAPI.Print( | |
| caller, | |
| $"There {(count == 1 ? "is" : "are")} {count} object{(count == 1 ? "" : "s")} outside the ship" | |
| ); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment