codeAPI Reference
s&box IPhysgunEvent: Physgun grab interception
IPhysgunEvent Interface API Reference
IPhysgunEvent is an interface for Components that want to intercept physgun grab attempts. Implement to allow or reject physgun interactions.
Type Signature
CSHARP
public interface IPhysgunEvent : ISceneEvent<IPhysgunEvent>
{
public class GrabEvent
{
public Connection Grabber { get; init; }
public bool Cancelled { get; set; }
}
void OnPhysgunGrab(GrabEvent e);
}Event Data
GrabEvent
- Connection Grabber { get; init; } - The connection attempting to grab this object.
- bool Cancelled { get; set; } - Set to true to cancel the grab.
Methods
OnPhysgunGrab(GrabEvent e)
Called when a player attempts to grab this object with the physgun. Set GrabEvent.Cancelled to true to reject the grab.Usage
CSHARP
public class MyProtectedProp : Component, IPhysgunEvent
{
public void OnPhysgunGrab(IPhysgunEvent.GrabEvent e)
{
// Only allow the owner to grab
var ownable = GetComponent<Ownable>();
if (ownable?.Owner != e.Grabber)
{
e.Cancelled = true;
}
}
}Notes
- Implements ISceneEvent for scene-wide event broadcasting
- Used by Ownable component for prop protection
- Cancelled property prevents the grab from succeeding
- Grabber is the Connection attempting the grab
- Event is broadcast to all IPhysgunEvent components on the GameObject
Was this helpful?