vRP Framework

repository·master·Indexed 43 days ago

https://github.com/vrp-framework/vrp

A high-performance, OOP-based Roleplay framework for FiveM. It provides essential server mechanics including economy, inventory, identity, and permissions, featuring a robust extension system, a key-value API for custom data, and specialized modules for administration, aptitudes, ATMs, and VoIP audio.

Tokens
27.9K
Snippets
100
Records
147
Agent score
56%

What's inside vRP

  1. Overview of vRP Framework

    master

    vRP is a generic and simple Roleplay (RP) framework for FiveM. It is designed to provide a structured, low-overhead foundation for developers to build RP servers without reinventing core mechanics.

    Key features include:

    • Core Systems: Admin tools (kick, ban, whitelist), groups/permissions, identification systems, and a MySQL database driver system.
    • Player Mechanics: Survival vitals, weapons, appearance, position, identity, phone, and aptitudes.
    • Economy & Business: Money (wallet/bank), business systems, homes, and shops.
    • Gameplay Systems: Inventory (custom/parametric items), vehicle trunks (chests), harvesting/processing (transformer), and basic police/emergency services.
    • UI & Interaction: Dynamic menus, progress bars, prompts, map blips/markers, and area enter/leave callbacks.
    • Developer Tools: OOP design, Proxy for inter-resource development, Tunnel for server/client communication, and a Lua profiler.
  2. What is the Transformer module?

    master

    The Transformer module is a generic system used to transform, generate, process, or convert items, money, or other resources within a specific area.

    Key characteristics:

    • Unit-based: Each transformer uses 'units of work' that regenerate periodically at a specific rate.
    • Recipe-driven: Transformers use reagents to produce products (e.g., a harvest transformer might require no reagents to produce a product).
    • Area-specific: Transformers operate within defined spatial properties like pos, radius, and height.
  3. How Proxy and Tunnel work

    master

    vRP uses two primary mechanisms for cross-resource and cross-side communication:

    Proxy

    Used to call functions in other resources through a proxy event. It is typically used for communication between different resources on the same side.

    Tunnel

    Used to access exposed server functions from a client resource, or client functions from a server resource.

    Optimization: Non-blocking calls

    By default, Proxy and Tunnel calls are blocking (they wait for the return value). To optimize speed and bypass waiting (discarding return values), prefix the function name with +_+.

    Example of non-blocking call: interface._func()

    If you need the return values but want non-blocking behavior, wrap the call in Citizen.CreateThreadNow or async.

  4. How extensions work in vRP

    master

    An extension is a class that extends vRP.Extension. Extensions allow you to add functionality directly into the vRP resource context, providing access to data and methods that might not be exposed via standard APIs, with lower overhead than using a Proxy.

    Key Features:

    • Registration: Extensions are registered via vRP:registerExtension(extension).
    • Access: Once loaded, extensions are accessible via the vRP.EXT table (e.g., vRP.EXT.MyExt:method()).
    • User Extension: You can extend player properties and methods by defining a User class within your extension.
    • Event Listening: Extensions can listen to global events by defining methods in an event table.
    • Proxy/Tunnel Listening: Extensions can intercept proxy or tunnel calls by defining methods in proxy or tunnel tables.
    • Inter-extension Communication: Extensions should use the tunnel/remote interfaces to communicate between client and server sides, but they should not use Proxy to communicate with each other.
    -- Define an extension
    local MyExt = class("MyExt", vRP.Extension)
    
    -- Access an extension method
    vRP.EXT.MyExt:test()
    
    -- Extend User properties
    MyExt.User = class("User")
    
    -- Listen to events
    MyExt.event = {}
    function MyExt.event:playerSpawn(user, first_spawn)
    end
  5. Use money in Items and Transformers

    master

    The Money module provides abstractions for handling currency within the item and transformer systems.

    Items

    • money: Represents money as a packable item.
    • money_binder: A utility used to pack a specific amount of wallet money into a money item.

    Transformer Processors

    Transformers can consume and produce money using the money processor. In this context, money represents the amount.

    Example Transformer Value:

    money = 200
  6. Use the SkinShop menu and sub-menus

    master

    The SkinShop module provides a menu system consisting of a main skinshop menu and individual skinshop.part sub-menus.

    SkinShop Menu

    The main menu contains multiple configuration parts defined in the parts data field.

    SkinShop Part Sub-menu

    Each part within the skinshop menu is represented as a skinshop.part and contains the following data fields:

    • title: The display title for the part.
    • part: The internal name of the part.
    • custom: The current customization state for the skinshop.
  7. Use permission syntax for group and negation checks

    master

    Permissions can be constructed using specific prefixes to check for group membership or to negate existing permission checks.

    • Group Check: Use !group.<name> to check if a user belongs to a specific group.
    • Negation: Use !not.<...> to negate any permission check.

    Examples:

    • !group.admin: Returns true if the user is in the 'admin' group.
    • !not.group.admin: Returns true if the user is NOT in the 'admin' group.
  8. Use home component menus

    master

    The home_components module provides several menu components that can be accessed within a home environment:

    • home:component:wardrobe: A wardrobe menu used for managing clothing. It uses a sets map where each entry maps a name to a specific customization.
    • home:component:gametable: A menu for interacting with the gametable.
    • home:component:radio: A menu for interacting with the radio component.
    -- Example data structure for wardrobe menu
    -- sets:: map of name => customization
  9. Handle identity updates with characterIdentityUpdate

    master

    The identity system emits the characterIdentityUpdate(user) event whenever an identity is updated, such as when it is loaded or changed. Listen to this event to react to identity changes.

    -- Example event listener
    AddEventHandler('characterIdentityUpdate', function(user)
        -- Handle identity update logic here
    end)