SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 14/03/2018, 10:39 AM   #1
EvaBaka
Little Clucker
 
Join Date: Jul 2016
Posts: 3
Reputation: 23
Default Rust SA:MP SDK

It's a Rust library allows you to write plugins in Rust.

Features
Hides most of type coercion. You don't need make a cell type as a String or other things yourself.

Macros:
  • new_plugin! that defines a plugin and exports functions.
  • define_native! defines a native and parses arguments.
  • log! calls logprinft funciton.
  • natives! makes a vec of your natives.
  • get_string! and get_array! convert pointers to a slice or a String.
  • set_string! sets a string to an AMX by a physical address.

Make a new plugin
Code:
struct Plugin {
    version: &'static str,
    amx_count: u32,
}

impl Plugin {
    fn load(&self) -> bool {
        log!("Plugin is loaded. Version: {}", self.version);
        return true;
    }

    fn amx_load(&mut self, amx: &AMX) -> Cell {
        let natives = natives![
            { "MyFunction", my_function }
        ];

        match amx.register(natives) {
            Ok(_) => log!("Natives are successful loaded"),
            Err(err) => log!("Whoops, there is an error {:?}", err),
        }

        self.amx_count += 1;

        AMX_ERR_NONE
    }

    fn amx_unload(&mut self, _: &AMX) -> Cell {
        self.amx_count -= 1;

        AMX_ERR_NONE
    }

    fn my_function(&self, _amx: &AMX, player_id: i32) -> AmxResult<Cell> {
        Ok(-player_id)
    }
}

impl Default for Plugin {
    fn default() -> Self {
        Plugin {
            version: "0.1",
            amx_count: 0,
        }
    }
}

new_plugin!(Plugin);

// Also you can make a plugin with ProcessTick support.
new_plugin!(Plugin with process_tick)
Define a native function.
Hides arguments parsing inside the macro.

All you need are to define a method function_name in your new plugin with given arguments.

Code:
// native: FunctionName(int_arg, &float_arg);
define_native!(function_name, int_arg: i32, float_ref_arg: ref f32);

// native: WithoutArguments();
define_native(function_name);
Call natives and public functions.
Code:
// Broadcast to all subscribers that a user have changed his name.
fn notify(&self, amx: AMX, player_id: u32, old_name: String, new_name: String) -> AmxResult<Cell> {
    exec_public!(amx, "OnPlayerNameChanged"; player_id, old_name => string, new_name => string) 
}
Documentation and examples
Here is documentation and there is an example plugin (Memcached library) and here is a more simple example.

Repository
https://github.com/ZOTTCE/samp-sdk

Ask your questions and more popular will be in wiki on GitHub.

Last edited by EvaBaka; 15/03/2018 at 06:39 PM.
EvaBaka is offline   Reply With Quote
Old 14/03/2018, 10:54 AM   #2
Sia
Little Clucker
 
Sia's Avatar
 
Join Date: Sep 2017
Location: Ukraine
Posts: 6
Reputation: 0
Default Re: Rust SA:MP SDK

Nice proga SDK plygin
__________________
Sia is offline   Reply With Quote
Old 14/03/2018, 11:42 PM   #4
Kaperstone
High-roller
 
Kaperstone's Avatar
 
Join Date: May 2011
Location: Russia
Posts: 3,353
Reputation: 822
Default Re: Rust SA:MP SDK

Awesome!
__________________
Find me on GitHubSEF Community (Official NEF Successor) • SA:MP ReviewsFind me on Steam
Kaperstone is offline   Reply With Quote
Old 15/03/2018, 01:11 AM   #5
KayJ
Gangsta
 
Join Date: Apr 2014
Posts: 706
Reputation: 61
Default Re: Rust SA:MP SDK

Nice
__________________
SA:MP Wikipedia Profile

[Filterscript] Position - Save, Load & Delete [Y_INI] [ZCMD]
[Include] InfoText TextDraw
KayJ is offline   Reply With Quote
Old 15/03/2018, 01:21 AM   #6
SyS
High-roller
 
SyS's Avatar
 
Join Date: Oct 2015
Posts: 1,982
Reputation: 453
Default Re: Rust SA:MP SDK

Nice
SyS is offline   Reply With Quote
Old 15/03/2018, 09:01 AM   #7
Zeth
Huge Clucker
 
Zeth's Avatar
 
Join Date: Feb 2017
Location: India
Posts: 481
Reputation: 90
Default Re: Rust SA:MP SDK

Amazing!
__________________
Zeth is offline   Reply With Quote
Old 15/03/2018, 10:41 AM   #8
KashCherry
Little Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 30
Reputation: 19
Default Re: Rust SA:MP SDK

Nice
KashCherry is offline   Reply With Quote
Old 15/03/2018, 11:03 AM   #9
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Posts: 1,448
Reputation: 444
Default Re: Rust SA:MP SDK

Nice, definitely going to try it out.
NaS is offline   Reply With Quote
Old 15/03/2018, 01:07 PM   #10
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Portugal
Posts: 7,186
Reputation: 775
Default Re: Rust SA:MP SDK

It’s very interesting this plugin

Nice work
__________________
"Quem caiu e se levantou honrado era e honrado ficou..."


CVU vai voltar e.e


http://steamcommunity.com/id/pt_player/
PT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rust On 4GB RAM K0P Everything and Nothing 20 28/12/2016 12:34 AM
[Projeto] San Andreas Rust (DayZ/Rust/Survival) JPedro Português/Portuguese 38 15/10/2015 02:31 AM
[Off] Rust para SA-MP PratesPlay Português/Portuguese 17 27/02/2014 07:29 PM
Anybody got Rust on steam to trade? RedJohn Everything and Nothing 10 22/02/2014 11:13 PM
Rust map from MW2 Nightcell Screenshots and Videos 4 30/01/2014 02:42 PM


All times are GMT. The time now is 02:39 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.