codeAPI Reference
s&box LimitsSystem: Spawn and tool limits
LimitsSystem GameObjectSystem API Reference
LimitsSystem enforces configurable limits on spawning and tool usage. Maintains a per-player tracked object list populated from post-events. Limit checks iterate only the player's objects, not the entire scene.
Type Signature
CSHARP
public sealed class LimitsSystem : GameObjectSystem<LimitsSystem>, Global.ISpawnEvents, IToolActionEvents
{
[ConVar("sb.limit.props")] public static int MaxPropsPerPlayer { get; set; } = -1;
[ConVar("sb.limit.explosives")] public static int MaxExplosivesPerPlayer { get; set; } = -1;
[ConVar("sb.limit.balloons")] public static int MaxBalloons { get; set; } = -1;
[ConVar("sb.limit.constraints")] public static int MaxConstraints { get; set; } = -1;
[ConVar("sb.limit.emitters")] public static int MaxEmitters { get; set; } = -1;
[ConVar("sb.limit.thrusters")] public static int MaxThrusters { get; set; } = -1;
[ConVar("sb.limit.hoverballs")] public static int MaxHoverballs { get; set; } = -1;
[ConVar("sb.limit.wheels")] public static int MaxWheels { get; set; } = -1;
}Static Properties (ConVars)
- int MaxPropsPerPlayer = -1 - Maximum props per player (-1 = unlimited, 0 = none allowed)
- int MaxExplosivesPerPlayer = -1 - Maximum explosive props per player
- int MaxBalloons = -1 - Maximum balloons per player
- int MaxConstraints = -1 - Maximum constraints per player
- int MaxEmitters = -1 - Maximum emitters per player
- int MaxThrusters = -1 - Maximum thrusters per player
- int MaxHoverballs = -1 - Maximum hoverballs per player
- int MaxWheels = -1 - Maximum wheels per player
Global.ISpawnEvents Implementation
- OnSpawn(SpawnData e) - Pre-checks limits before spawning. Cancels spawn if limit exceeded. Special handling for DuplicatorSpawner batch pre-check.
- OnPostSpawn(PostSpawnData e) - Tracks spawned objects for the player.
IToolActionEvents Implementation
- OnToolAction(ActionData e) - Pre-checks tool limits before action. Cancels if limit exceeded.
- OnPostToolAction(PostActionData e) - Tracks objects created by tool actions.
Behavior
- Tracks objects per player using SteamId keys
- Prunes destroyed objects during count checks
- Duplicator: batch pre-check rejects entire dupe if it would exceed limits
- Notifies players via Notices when limits are reached
- -1 means unlimited, 0 means none allowed
Usage
CSHARP
// Set limits via console
ConsoleSystem.Run("sb.limit.props 100");
ConsoleSystem.Run("sb.limit.balloons 50");
// LimitsSystem automatically enforces theseNotes
- Implements both ISpawnEvents and IToolActionEvents for comprehensive coverage
- Uses per-player tracking for efficient limit checks
- Handles explosive props specially via Model.Data.Explosive
- Constraint tools checked via "constraint" tag
Was this helpful?