Crates.io | altv_internal_logger |
lib.rs | altv_internal_logger |
version | 16.1.0 |
source | src |
created_at | 2023-04-17 23:13:50.136442 |
updated_at | 2024-06-02 14:15:47.855267 |
description | An internal logger for alt:V module. Not intended for direct use. |
homepage | |
repository | https://github.com/xxshady/altv-rust |
max_upload_size | |
id | 841946 |
size | 6,561 |
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
Work is being done in this branch.
Will never be published or released because alt:V does not allow you to use custom client-side modules (.dll) in production
API documentation can be found here
Before all this, you need to install LLVM
[!WARNING] Currently on Windows latest version of LLVM doesn't work with Rust module, you need to install 16.0.6, for example with winget you can do it using this command
winget install LLVM.LLVM --version 16.0.6
[!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
Video format of this tutorial if you are more into video tutorials
Create new cargo package with cargo new altv-resource --lib
Configure cargo to compile your crate as cdylib
in your Cargo.toml
[lib]
crate-type = ['cdylib']
After that you can install altv
crate with: cargo add altv
Next step will be to add main function to your resource (src/lib.rs
)
use altv::prelude::*; // Entity, WorldObject traits
#[altv::main] // This is required
fn main() -> impl altv::IntoVoidResult {
altv::log!("~gl~hello world");
}
Now you can build your resource with cargo build
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 2)
Create new alt:V resource, in resources
directory of your server
Copy compiled .dll
or .so
to resource directory
Create resource.toml
with this content:
type = 'rs'
main = 'example.dll' # your compiled .dll or .so
Don't forget to add resource to server.toml
Now you can download rust-module .dll
or .so
from latest release or with cargo-altvup
Copy it to modules
directory of your server (if you do not use cargo-altvup
)
Add rust-module
to server.toml
like that:
modules = ['rust-module']