Skip to content

Latest commit

 

History

History
88 lines (69 loc) · 3.54 KB

File metadata and controls

88 lines (69 loc) · 3.54 KB

Migration guide

A short overview for users coming from an older release. For the full multi-version walkthrough see docs/migration.md.

Legacy samp_sdk → current rust-samp

Before Now
samp_sdk = "*" samp = { package = "rust-samp", version = "3" } (crates.io, v3.1.0+) — or samp = { git = "https://github.com/NullSablex/rust-samp.git", tag = "v3.1.0" } (any version)
new_plugin!(Plugin) initialize_plugin!(type: T, natives: [...]) or the constructor-block form
define_native!(name, args) #[native(name = "Name")]
Manual impl Default for Plugin + new_plugin! #[derive(SampPlugin, Default)]
AMX (raw pointer) Amx (safe wrapper)
Cell i32, Ref<T>, AmxString, custom types via AmxCell
string.to_string() &*string (via Deref<Target = str>)
f32::from_bits(buf[i] as u32) buf.get_as::<f32>(i)
process_tick (SA-MP only) on_tick(ctx: TickContext) (unified — fires on SA-MP and on native Open Multiplayer; opt in via enable_tick() / enable_tick_with(TickConfig))

Before

use samp_sdk::new_plugin;

define_native!(my_native, string: String);

pub struct Plugin;

impl Plugin {
    fn load(&self) {
        let natives = natives! { "MyNative" => my_native };
        amx.register(&natives);
    }

    fn my_native(&self, amx: &AMX, string: String) -> AmxResult<Cell> {
        println!("{}", string);
        Ok(1)
    }
}

impl Default for Plugin {
    fn default() -> Plugin { Plugin }
}

new_plugin!(Plugin);

Now

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

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

impl Plugin {
    #[native(name = "MyNative")]
    fn my_native(&mut self, _amx: &Amx, text: &AmxString) -> AmxResult<bool> {
        println!("{}", &**text);
        Ok(true)
    }
}

initialize_plugin!(
    type: Plugin,
    natives: [Plugin::my_native],
);

v2.x → v3.0.0 essentials

  • Native Open Multiplayer support is generated by default. The same binary loads on SA-MP and on Open Multiplayer as a first-class component. To opt out, enable the samp-only feature.
  • The unified tick callback is on_tick(&mut self, ctx: TickContext). Enable it once with samp::plugin::enable_tick() (or the explicit enable_tick_with(TickConfig::new()...)) inside the constructor block. TickContext::source distinguishes the SA-MP and Open Multiplayer paths; TickContext::elapsed is the wall-clock interval since the previous dispatch.
  • The component UID is created automatically (FNV-1a of CARGO_PKG_NAME@CARGO_PKG_VERSION) and persisted to Cargo.toml under [package.metadata.samp] on the first build that needs it.

The full walkthrough — including the build-time error when the target is not i686, the platform support matrix, and the optional #[cfg]-gated Open Multiplayer hooks — lives in docs/migration.md.