codeAPI Reference

s&box IToolActionEvents: Tool action event interface

calendar_today May 12, 2026 schedule ~1 min read person patrickjr verified 50

IToolActionEvents API Reference

IToolActionEvents is a scene-wide interface for listening to toolgun actions before and after they execute.

Type Signature

CSHARP
public interface IToolActionEvents : ISceneEvent<IToolActionEvents>

ActionData Class

Passed to OnToolAction. Set Cancelled to true to prevent the action.

CSHARP
public class ActionData
{
    public ToolMode Tool { get; init; }        // The tool mode executing
    public ToolInput Input { get; init; }      // Which input (Primary/Secondary/Reload)
    public PlayerData Player { get; init; }    // The player performing the action
    public bool Cancelled { get; set; }        // Set to true to cancel
}

PostActionData Class

Passed to OnPostToolAction after successful execution.

CSHARP
public class PostActionData : ActionData
{
    public List<GameObject> CreatedObjects { get; init; }  // Objects created by this action
}

Methods

Usage Example

Implement on a Component to enforce limits or react to tool usage:

CSHARP
public class LimitsSystem : GameObjectSystem<LimitsSystem>, IToolActionEvents
{
    void IToolActionEvents.OnToolAction(ActionData e)
    {
        // Check tool type and player limits
        if (e.Tool is Balloon && GetBalloonCount(e.Player) >= MaxBalloons)
        {
            e.Cancelled = true;
        }
    }
    
    void IToolActionEvents.OnPostToolAction(PostActionData e)
    {
        // Track created objects for limit enforcement
        foreach (var obj in e.CreatedObjects)
        {
            TrackObject(e.Player, obj);
        }
    }
}

Notes

  • Use e.Tool is Balloon or e.Tool is Weld to check for specific tool types.
  • ToolInput enum values: Primary, Secondary, Reload.
  • Implement on GameObjectSystem or Component - must be in the scene to receive events.
Was this helpful?