Giter Site home page Giter Site logo

altv-rs's Introduction

alt:V Rust Module

Rust Current Crates.io Version MIT/Apache

What is alt:V?

alt:V is a free third-party multiplayer modification for Grand Theft Auto: V. It allows you to play with your friends on dedicated servers with custom gamemodes with an ultimate experience.

The module allows you to write your own gamemode in Rust.

Setup

Before you start writing your own gamemode, setup an alt:V server following this tutorial:

To make the alt:V server compatible with rust, paste the rust-module into the modules/ folder and add this line to your server.cfg file:

modules: [ rust-module ]

If you want to use multiple modules e.g. the csharp-module or js-module, seperate them with a ,:

modules: [ rust-module, csharp-module, js-module ]

Example

Create a rust lib project and add this line to your Cargo.toml file under [dependencies]:

altv = "0.2.0" 

Alternatively, pull it from GitHub to obtain the latest version from develop:

altv = { git = "https://github.com/DimaaIO/altv-rs" } 

Then replace src/lib.rs with the following:

use altv::app::{ApplicationBuilder, CoreApplication};
use altv::game_data::{GameData, GameDataBuilder, StateData};
use altv::sdk::events::*;
use altv::state::State;
use std::error::Error;

pub struct GameState;

impl State for GameState {
    fn on_start(&mut self, data: StateData<GameData>) {
        altv::sdk::log::info("Hello from rust!");
    }

    fn on_stop(&mut self, data: StateData<GameData>) {
        altv::sdk::log::info("Time to sleep, bye!");
    }

    fn handle_event(&mut self, data: StateData<GameData>, event: CEvent) {
        match &event {
            CEvent::PlayerConnect(event) => {
                altv::sdk::log::info("Listen closely! A new player connected to the server!")
            }
            _ => {}
        };
    }
}

#[no_mangle]
pub fn main(core: usize) -> Result<CoreApplication, Box<dyn Error>> {
    let game_data_builder = GameDataBuilder::new();
    let application = ApplicationBuilder::new(core, Box::new(GameState)).build(game_data_builder);
    Ok(application)
}

We have several simple example projects included. You can see the full list in the examples/ folder.

To compile any of the examples run:

$ cargo build

Now create a new folder for the resource: resource/example and create a new file resource.cfg with the following text:

type: rust,
main: libexample.so

To enable the resource, add a reference in the server.cfg file:

resources: [ example ]

Then copy the compiled lib from target/[debug/release]/libexample.so to the example resource folder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.