Skip to content

Instantly share code, notes, and snippets.

@baerchen201
Last active July 4, 2025 06:08
Show Gist options
  • Select an option

  • Save baerchen201/2d1f8e9363c13de1c565ad09651fba5d to your computer and use it in GitHub Desktop.

Select an option

Save baerchen201/2d1f8e9363c13de1c565ad09651fba5d to your computer and use it in GitHub Desktop.
baer1.ChatCommandAPI example
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;
}
}
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