codeAPI Reference
s&box IToolgunEvent: Toolgun selection interception
IToolgunEvent Interface API Reference
IToolgunEvent is an interface for Components that want to intercept toolgun selection attempts. Implement to allow or reject toolgun interactions.
Type Signature
CSHARP
public interface IToolgunEvent : ISceneEvent<IToolgunEvent>
{
public class SelectEvent
{
public Connection User { get; init; }
public bool Cancelled { get; set; }
}
void OnToolgunSelect(SelectEvent e);
}Event Data
SelectEvent
- Connection User { get; init; } - The connection attempting to use a tool on this object.
- bool Cancelled { get; set; } - Set to true to reject the toolgun selection.
Methods
OnToolgunSelect(SelectEvent e)
Called when a player attempts to select this object with the toolgun. Set SelectEvent.Cancelled to true to reject the selection.Usage
CSHARP
public class MyProtectedProp : Component, IToolgunEvent
{
public void OnToolgunSelect(IToolgunEvent.SelectEvent e)
{
// Only allow the owner to use tools
var ownable = GetComponent<Ownable>();
if (ownable?.Owner != e.User)
{
e.Cancelled = true;
}
}
}Notes
- Implements ISceneEvent for scene-wide event broadcasting
- Used by Ownable component for prop protection
- Cancelled property prevents the toolgun selection
- User is the Connection attempting the toolgun interaction
- Event is broadcast to all IToolgunEvent components on the GameObject
- Works with all toolgun modes (weld, balloon, thruster, etc.)
Was this helpful?