3 releases (breaking)

0.3.0 Jun 1, 2024
0.2.0 May 20, 2024
0.1.0 May 6, 2024

#28 in #necessary

Download history 1/week @ 2024-09-14 36/week @ 2024-09-21 2/week @ 2024-09-28

155 downloads per month
Used in 2 crates (via omp-gdk)

Apache-2.0

14KB
334 lines

omprs

crates.io docs.rs build status patreon kofi

omprs is a tool to develop open.mp gamemodes in Rust.

Structure

Crate Description
omp-codegen Generates exported functions and FFI related code automatically
omp-sdk GDK crate, that does the core functionality like loading function address, executing, providing necessary types etc
omp The main crate the is supposed to be used by the players, neatly exposing all of the functionalities and APIs.

Writing my first gamemode in Rust

  1. Download the omprs component from here

  2. Place the Rust.dll or Rust.so component in components folder

  3. Create a new rust project cargo new mygm --lib

  4. Add omp to dependecies cargo add omp

  5. Add this to your Cargo.toml

    [lib]
    crate-type = ["cdylib"]
    
  6. Write a basic code like this

    use omp::{events::Events, main, register, types::colour::Colour};
    
    struct MyGM;
    
    impl Events for MyGM {
        fn on_player_connect(&mut self, player: omp::players::Player) {
            player.send_client_message(Colour::from_rgba(0xFFFFFFFF), "Welcome to my server!");
        }
    }
    
    #[main]
    pub fn game_main() {
        register!(MyGM);
    }
    
  7. Build the gamemode

    cargo +stable-i686 build

  8. Put the compile mygm.dll or mygm.so to gamemodes folder

  9. Goto config.json add following to it

    "rust":{
        "gamemode":"mygm"
    }
    
  10. Run your server


lib.rs:

codgen crate that gives proc macros to generate exported functions and FFI related code automatically

Dependencies

~230–670KB
~16K SLoC