pub trait SampPlugin {
// Provided methods
fn on_load(&mut self) { ... }
fn on_unload(&mut self) { ... }
fn on_amx_load(&mut self, amx: &Amx) { ... }
fn on_amx_unload(&mut self, amx: &Amx) { ... }
fn on_debug_break(&mut self, amx: &Amx) { ... }
fn on_tick(&mut self, ctx: TickContext) { ... }
fn on_omp_ready(&mut self) { ... }
fn on_component_free(&mut self) { ... }
}Expand description
Plugin lifecycle. All methods are optional — the trait provides empty implementations so the plugin only overrides the relevant ones.
Instead of implementing manually, use #[derive(SampPlugin)] if no
method needs custom logic.
Provided Methods§
Sourcefn on_load(&mut self)
fn on_load(&mut self)
Server has finished loading the plugin (Load() on SA-MP /
onLoad(ICore*) on Open Multiplayer). Good moment to initialize state.
Sourcefn on_amx_load(&mut self, amx: &Amx)
fn on_amx_load(&mut self, amx: &Amx)
A Pawn script (.amx) was loaded. On SA-MP it is called by the
AmxLoad export; on Open Multiplayer by IEventDispatcher<PawnEventHandler>.
Sourcefn on_amx_unload(&mut self, amx: &Amx)
fn on_amx_unload(&mut self, amx: &Amx)
A Pawn script is being unloaded. Clean per-AMX state here.
Sourcefn on_debug_break(&mut self, amx: &Amx)
fn on_debug_break(&mut self, amx: &Amx)
The VM’s debug hook fired on a source line. Only called for AMXs the
plugin opted in via enable_debug_hook, and only when the .amx was
compiled with -d2/-d3.
This runs on the VM thread, synchronously, on every executed line — keep
it cheap, and block here (e.g. waiting for a debugger client) only if you
intend to freeze the server. Use the VM accessors on Amx
(cip, frame, read_cell/write_cell) to read the paused state, and
pair them with samp::debug (feature debug) to map addresses to source
lines and symbols.
Sourcefn on_tick(&mut self, ctx: TickContext)
fn on_tick(&mut self, ctx: TickContext)
Periodic callback. Fires only when the plugin opted in via
enable_tick (or enable_tick_with).
The two servers schedule this differently:
- SA-MP: the server invokes the
ProcessTickexport on every iteration of its main loop. The cadence is whatever the server is configured for — the SDK has no control over it. - native Open Multiplayer: there is no native equivalent of
ProcessTickfor components. The SDK installs a repeating timer on the server’sITimersComponentinon_readyand dispatches its timeout here. The interval is whateverTickConfig::omp_intervalwas set to (default: 5 ms).
ctx.source tells which server scheduled the call; ctx.elapsed
is the wall-clock time since the previous dispatch (zero on the
first call).
Sourcefn on_omp_ready(&mut self)
fn on_omp_ready(&mut self)
Called when all Open Multiplayer components have finished initializing.
This is the safe moment to interact with other server components,
since all of them have already gone through their on_init.
Available only in native Open Multiplayer mode (without the samp-only feature).
Sourcefn on_component_free(&mut self)
fn on_component_free(&mut self)
Called when any Open Multiplayer component is being unloaded.
Use together with samp::plugin::omp_query_component() to check
which components are still available after the notification.
Available only in native Open Multiplayer mode (without the samp-only feature).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".