codeAPI Reference

Player Event Interfaces (Local and Global)

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

Local.IPlayerEvents and Global.IPlayerEvents

Event interfaces for player lifecycle, damage, inventory, and camera events. Local fires to player hierarchy only; Global broadcasts to entire scene.

Local.IPlayerEvents (Player Hierarchy Only)

CSHARP
public static partial class Local
{
    public interface IPlayerEvents : ISceneEvent<IPlayerEvents>
    {
        void OnSpawned() { }
        void OnDied(PlayerDiedParams args) { }
        void OnDamage(PlayerDamageParams args) { }
        void OnJump() { }
        void OnLand(float distance, Vector3 velocity) { }
        void OnSuicide() { }
        void OnPickup(PlayerPickupEvent e) { }
        void OnDrop(PlayerPickupEvent e) { }
        void OnSwitchWeapon(PlayerSwitchWeaponEvent e) { }
        void OnRemoveWeapon(PlayerRemoveWeaponEvent e) { }
        void OnMoveSlot(PlayerMoveSlotEvent e) { }
        void OnDamaging(PlayerDamageEvent e) { }
        void OnKill(PlayerKillEvent e) { }
        void OnCameraMove(ref Angles angles) { }
        void OnCameraSetup(CameraComponent camera) { }
        void OnCameraPostSetup(CameraComponent camera) { }
    }
}

Global.IPlayerEvents (Scene-wide Broadcast)

CSHARP
public static partial class Global
{
    public interface IPlayerEvents : ISceneEvent<IPlayerEvents>
    {
        void OnPlayerSpawned(Player player) { }
        void OnPlayerDied(Player player, PlayerDiedParams args) { }
        void OnPlayerDamage(Player player, PlayerDamageParams args) { }
        void OnPlayerJumped(Player player) { }
        void OnPlayerLanded(Player player, float distance, Vector3 velocity) { }
        void OnPlayerSuicide(Player player) { }
        void OnPlayerPickup(PlayerPickupEvent e) { }
        void OnPlayerDrop(PlayerDropEvent e) { }
        void OnPlayerSwitchWeapon(PlayerSwitchWeaponEvent e) { }
        void OnPlayerRemoveWeapon(PlayerRemoveWeaponEvent e) { }
        void OnPlayerMoveSlot(PlayerMoveSlotEvent e) { }
        void OnPlayerDamaging(PlayerDamageEvent e) { }
        void OnPlayerRespawning(PlayerRespawnEvent e) { }
        void OnPlayerKill(PlayerKillEvent e) { }
    }
}

Event Data Classes

CSHARP
public class PlayerPickupEvent
{
    public Player Player { get; init; }
    public BaseCarryable Weapon { get; init; }
    public int Slot { get; init; }
    public bool Cancelled { get; set; }
}

public class PlayerDropEvent
{
    public Player Player { get; init; }
    public BaseCarryable Weapon { get; init; }
    public bool Cancelled { get; set; }
}

public class PlayerSwitchWeaponEvent
{
    public Player Player { get; init; }
    public BaseCarryable From { get; init; }
    public BaseCarryable To { get; init; }
    public bool Cancelled { get; set; }
}

public class PlayerDamageEvent
{
    public Player Player { get; init; }
    public DamageInfo DamageInfo { get; init; }
    public float Damage { get; set; }
    public bool Cancelled { get; set; }
}

public class PlayerRespawnEvent
{
    public PlayerData PlayerData { get; init; }
    public Transform SpawnLocation { get; set; }
}

Firing Events

CSHARP
// Local - fires to player hierarchy only
Local.IPlayerEvents.PostToGameObject(Player.GameObject, e => e.OnPickup(pickupEvent));

// Global - broadcasts to entire scene
Global.IPlayerEvents.Post(e => e.OnPlayerPickup(pickupEvent));

// Cancellable events check after firing
if (pickupEvent.Cancelled)
{
    item.DestroyGameObject();
    return;
}

Usage Example

CSHARP
public class WeaponRestriction : Component, Global.IPlayerEvents
{
    void Global.IPlayerEvents.OnPlayerPickup(PlayerPickupEvent e)
    {
        if (e.Weapon is BaseWeapon weapon && weapon.Value > 100)
        {
            e.Cancelled = true;
            Log.Info($"Player {e.Player.DisplayName} cannot pickup high-value weapons");
        }
    }
}

Key Behaviors

  • Cancellable: Set Cancelled = true to prevent the action
  • Two scopes: Local (player only) vs Global (entire scene)
  • Default empty: All interface methods have default implementations
  • Camera modification: OnCameraMove uses ref Angles for modification
Was this helpful?