Skip to main content

Crate samp

Crate samp 

Source
Expand description

Rust toolkit for developing SA-MP plugins and native Open Multiplayer components.

§Workspace structure

  • samp — main crate; re-exports SDK + codegen and exposes the API the plugin uses.
  • samp-codegen — proc macros (#[native], initialize_plugin!, #[derive(SampPlugin)]) that generate FFI entry points and argument parsing.
  • samp-sdk — low-level bindings for the AMX VM (SA-MP) and for the component ABI (Open Multiplayer).

§Minimal Cargo.toml setup

[lib]
crate-type = ["cdylib"]

[dependencies]
samp = { git = "https://github.com/NullSablex/rust-samp" }

§Plugin example

use samp::prelude::*;
use samp::{native, initialize_plugin, SampPlugin};

#[derive(SampPlugin, Default)]
struct MyPlugin;

impl MyPlugin {
    #[native(name = "Greet")]
    fn greet(&mut self, _amx: &Amx, name: &AmxString) -> AmxResult<bool> {
        if name.starts_with("Admin") {
            println!("[VIP] Welcome, {}!", &**name);
        } else {
            println!("Hello, {}!", &**name);
        }
        Ok(true)
    }
}

// Short form — default constructor via Default::default().
initialize_plugin!(
    type: MyPlugin,
    natives: [MyPlugin::greet],
);

// Full form when there is setup in the constructor (logger, tick, etc):
// initialize_plugin!(
//     natives: [MyPlugin::greet],
//     {
//         samp::plugin::enable_tick();
//         return MyPlugin;
//     }
// );

Modules§

amx
Re-exports the SDK’s Amx API and adds a global registry of active instances + an opaque identity to pass between callbacks.
args
Parsing of arguments from a Pawn native call.
cell
Smart pointers for accessing AMX VM cells from safe Rust code.
consts
SA-MP ABI constants: plugin flags, offsets of the server’s exports table and internal AMX VM flags. Values identical to those in the C header.
encoding
Global encoding for Rust <-> AMX conversion (only with the encoding feature).
error
Errors emitted by the AMX VM and the SA-MP amx_* functions.
exports
Typed access to the amx_* functions exported by the server.
logger
Turnkey logging for plugins.
omp
Native bindings for the Open Multiplayer SDK.
plugin
API the Rust plugin uses: trait SampPlugin (lifecycle) + global functions to enable features (enable_tick, logger, omp_query).
prelude
Most commonly used imports in plugins.
raw
Direct translation of the types and function pointers from the AMX C header.

Macros§

enable_logger
Installs the SDK logger with defaults derived from the caller’s Cargo.toml. Writes to logs/{CARGO_PKG_NAME}.log with size-based rotation (50 MB × 5 archives) and forwards every line to the server’s own log prefixed with [CARGO_PKG_NAME].
enable_logger_with
Installs the SDK logger with an explicit LoggerConfig.
exec_public
Executes an AMX public function by name.
initialize_plugin
Generates the entry points required by the server (SA-MP + Open Multiplayer), the Rust IComponent vtable and the registration of the plugin’s native list.

Attribute Macros§

native
Generates the extern "C" wrapper that reads the AMX argument table, parses it into the Rust types declared in the signature and invokes the marked method.

Derive Macros§

SampPlugin
Derive macro that generates an empty impl SampPlugin for T {} for structs that do not need to customize any trait method. For structs with logic in on_load/on_tick/etc, declare impl SampPlugin for T { ... } manually instead of using the derive. Generates impl SampPlugin for T {} with all methods using the default behavior (empty). Use for structs that do not need to customize any lifecycle callback — write the impl SampPlugin manually when some method needs custom logic.