#altv #module #alt-v #events #server-side #client-side #api

altv_internal_sdk

An internal crate for alt:V module. Not intended for direct use.

89 releases (11 stable)

new 16.2.4 Nov 20, 2024
16.2.2 Sep 18, 2024
16.1.0 Jun 2, 2024
16.0.0-dev.1 Dec 29, 2023
0.3.1 Apr 17, 2023

#852 in WebAssembly

Download history 123/week @ 2024-07-29 28/week @ 2024-08-05 25/week @ 2024-08-12 153/week @ 2024-08-19 38/week @ 2024-08-26 9/week @ 2024-09-02 8/week @ 2024-09-09 154/week @ 2024-09-16 130/week @ 2024-09-23 21/week @ 2024-09-30 7/week @ 2024-10-07 19/week @ 2024-10-14 4/week @ 2024-10-21 10/week @ 2024-11-04 309/week @ 2024-11-11

326 downloads per month
Used in 4 crates

MIT license

80KB
695 lines


alt:V API for Rust

crates.io

altv::events::on_player_connect(|event| {
  let name = event.player.name()?;
  altv::log!("player with name: {name} connected!");
  Ok(())
});

New server-side Rust module for alt:V platform

Big thanks to the creator of the first Rust module, as their work helped me understand how to start my own module

Client-side part

At first it was native implementation using wasmtime without JavaScript. It worked, but because alt:V does not allow you to use custom client-side modules (.dll) in production without approval, integration into the client core, constant maintenance and more than 0 people using this module, I switched to a more realistic approach, JavaScript WASM

Docs

API documentation can be found here

How to use

First you need to install LLVM because it's required by autocxx crate

[!WARNING] Currently on Windows latest version of LLVM doesn't work with Rust module, you need to install 17.0.1, for example with winget you can do it using this command winget install LLVM.LLVM --version 17.0.1 (add --force if it fails)

[!IMPORTANT] On Windows set LIBCLANG_PATH as an environment variable pointing to the bin directory of your LLVM install. For example, if you installed LLVM to D:\programs\LLVM, then you'd set the value to be D:\programs\LLVM\bin. You also need to have installed Visual Studio with MSVC compiler (usually installed with Rust using Rustup)

[!NOTE] If you have similar error: src/alt_bridge.h:5:10: fatal error: 'memory' file not found when installing or building altv_internal_sdk, try this

  1. Use altvup to install rust-module binary and alt:V server files

  2. Create new cargo package with cargo new altv-resource --lib

  3. Configure cargo to compile your crate as cdylib in your Cargo.toml

[lib]
crate-type = ['cdylib']
  1. After that you can install altv crate with: cargo add altv

  2. Next step will be to add main function to your resource (src/lib.rs)

use altv::prelude::*;

#[altv::main] // This is required
fn main() -> impl altv::IntoVoidResult {
    altv::log!("~gl~hello world");
}
  1. Now you can build your resource with cargo build

  2. In target/debug/ you should see the .dll or .so you just compiled (if you don't see it, make sure you set lib.crate-type to ["cdylib"], see step 3)

  3. Create new alt:V resource, in resources directory of your server

  4. Copy compiled .dll or .so to resource directory

  5. Create resource.toml with this content:

type = 'rs'
main = 'example' # extension not needed
  1. Don't forget to add resource to server.toml
# ...
resources = ['your-rust-resource']
# ...
  1. Now you can start altv-server

[!NOTE] If you are on Linux don't forget to run chmod +x for altv-server and altv-crash-handler:

chmod +x altv-server
chmod +x altv-crash-handler
  1. If you have done everything correctly, you should see green "hello world" message in the console

Dependencies

~2.6–7.5MB
~136K SLoC