💻
alt:V Athena Docs v3.0.0
  • Info
    • Introduction
    • Patreon & Support
    • Athena Discord
    • FAQ
  • Installation
    • Common Issues
    • Windows
    • Linux (Ubuntu 20.04+)
    • Debugging
    • Updating
  • Info
    • Admin
    • Configuration
    • Console
    • Database
    • Hotkeys
    • Identifier
  • Plugins
    • Load Plugins
    • Create Plugins
    • Mods
    • Clothing
  • Controllers
    • What is a Controller?
    • Blip Controller
    • Interaction Controller
    • Marker Controller
    • Object Controller
    • Ped Controller
    • Text Label Controller
    • World Notification Controller
  • Systems
    • Interiors
    • Inventory & Items
    • Inventory Rules
    • Jobs
    • Time
    • Weather
  • Menus
    • Menu Types
    • Action Menus
    • Input Menu
    • Wheel Menu
  • Player
    • Admin-Commands
    • Animations
    • Attach Objects
    • Credits
    • Currency
    • Commands
    • Error Screen
    • Message
    • Meta
    • Notifications
    • Particle
    • Progress Bar
    • Save
    • Shard
    • Sound
    • Spinners
    • Task Timeline
  • Custom WebViews
    • Introduction
    • Your First Page
    • CSS Framework
  • Misc
    • Custom Sounds
    • Custom Streamers
    • Custom Icons
    • Adding Locale / Translations
    • Adding Vehicle Rules
    • Adding Whitelist
    • Adding Wheel Menus
    • Adding Parking Garages
Powered by GitBook
On this page
  • How does it Work?
  • Custom Streamer Server Side
  • Custom Streamer Client Side
Edit on GitHub
  1. Misc

Custom Streamers

Create a custom streamer for streaming data.

A custom streamer is something that will allow you to synchronize a static object, pedestrian, etc. in the world for all player(s) to see. It inheritely uses the streaming service that is provided by the Athena Framework.

You can use it for something like synchronizing a door state.

How does it Work?

You create a custom keyword for a streamer service.

That keyword is then used to call a function inside of your own custom streamer.

The custom function inside of your streamer will come back with the player and the stream data near the player of this specific type. In the instance below it would have a bunch of doors that are close to the user.

You can then take the data and pass it client-side and do something with it.

This makes synchronizing custom things very easy for static data sets.

Custom Streamer Server Side

Create a custom streamer on server-side. The client-side code can be found below.

Imports may vary

import * as alt from 'alt-server';

import { sha256Random } from '../utility/encryption';
import { StreamerService } from './streamer';

const globalDoors: Array<IDoorState> = [];
const STREAM_RANGE = 25;
const KEY = 'doors';

interface IDoorState {
    uid?: string;

    /**
     * Position of the Object in a 3D space.
     * @type {Vector3}
     * @memberof IDoorState
     */
    pos: Vector3;

    /**
     * Some custom data for door state...
     * Add whatever you want...
     */
    isOpen?: boolean;
}

export class DoorController {
    /**
     * Initializes the streamer to use this callback to update players.
     */
    static init() {
        StreamerService.registerCallback(KEY, DoorController.update, STREAM_RANGE);
    }

    /**
     * Called when stream data is updated for this type.
     */
    static update(player: alt.Player, doors: Array<IDoorState>) {
        // You should listen to this event on client-side and do something with it.
        alt.emitClient(player, 'populate:Doors', doors);
    }

    /**
     * Call this when you add / remove global stream data.
     */
    static refresh() {
        StreamerService.updateData(KEY, globalDoors);
    }

    /**
     * Call this when you want to add new stream data.
     */
    static append(doorData: IDoorState): string {
        if (!doorData.uid) {
            doorData.uid = sha256Random(JSON.stringify(doorData));
        }

        globalDoors.push(doorData);
        DoorController.refresh();
        return doorData.uid;
    }
}

DoorController.init();

Custom Streamer Client Side

You have to figure out what you do with the data.

Check out some of the other core streamers to get a general idea of how to build this out.

alt.onServer('populate:Doors', (someData: Array<IDoorState>) => {
    console.log(JSON.stringify(someData, null, '\t'));
});
PreviousCustom SoundsNextCustom Icons

Last updated 3 years ago