codeAPI Reference
s&box BasePickup: Pickup item base
BasePickup Abstract Class API Reference
BasePickup is an abstract Component for items that can be picked up by players. Implements ITriggerListener and ICollisionListener for pickup detection.
Type Signature
CSHARP
public abstract class BasePickup : Component, Component.ITriggerListener, Component.ICollisionListener
{
[RequireComponent] public Collider Collider { get; set; }
[Property] public SoundEvent PickupSound { get; set; }
public virtual bool CanPickup(Player player, PlayerInventory inventory);
protected virtual bool OnPickup(Player player, PlayerInventory inventory);
[Rpc.Broadcast] protected void PlayPickupEffects(Player player);
}Methods
CanPickup(Player player, PlayerInventory inventory)
Returns true if the player can pick up this item. Override for custom pickup conditions.OnPickup(Player player, PlayerInventory inventory)
Gives the player the effect of this pickup. Return true to consume the object.PlayPickupEffects(Player player)
Broadcast RPC that plays the pickup sound. Sound is 2D (no spatial blend) for the local player.ITriggerListener Implementation
- OnTriggerEnter(GameObject other) - Host-only. Checks for Player and PlayerInventory, calls CanPickup and OnPickup, plays effects, destroys GameObject.
ICollisionListener Implementation
- OnCollisionStart(Collision collision) - Host-only. Same logic as trigger but checks collision.Other.GameObject.Root.
Usage
CSHARP
public class AmmoPickup : BasePickup
{
protected override bool OnPickup(Player player, PlayerInventory inventory)
{
inventory.GiveAmmo("pistol", 30);
return true;
}
}Notes
- Host-only pickup logic
- Requires Collider component
- Pickup sound is 2D for local player
- GameObject is destroyed on successful pickup
Was this helpful?