Skip to content

Working with SFEvents

Алексей . edited this page Oct 22, 2026 · 3 revisions

context.SF.Samp.Events dispatches typed parsed payloads. Reference the host-compatible SF.Protocol assembly for its standard RPC and sync model types; a separately compiled lookalike class is a different .NET type.

using SFSharp.Protocol.Rpc;

Context.RegisterDisposable(Context.SF.Samp.Events.OnIncomingRpc<ClientMessageRpc>(message =>
    Context.SetDetail("chat.last", message.Text)));

OnIncomingRpc/OnOutgoingRpc/OnIncomingPacket/OnOutgoingPacket return disposable subscriptions. The equivalent Stream methods support await foreach with a cancellation token. Registration is thread-safe and callbacks are delivered on the game thread. Keep them short and own any worker processing.

Pass direct registrations to RegisterDisposable, or finish stream enumeration when the run stops. Weak type-key caches do not release live consumers automatically. A stopped plugin must not leave a detached stream task running.

Typed events depend on successful parsing and are not a raw recorder. Use frames and TryParse when a model is missing or invalid. Native Actions observers expose client processing boundaries, which are a different layer from parsed wire messages. Chat streams also differ: local chat additions include module output, so echoing them back without source checks can loop.

Sources: ISFEvents, model sources, event channels. See examples and lifetime details.

Clone this wiki locally