💻
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
  • Save Injections
  • Conditional Saving
Edit on GitHub
  1. Player

Save

Saving player data, new data, etc.

There are a few things that are automatically saved to the database every 5 seconds but there are certain things that are obviously not saved all the time.

Saved Every 5 Seconds

  • position

  • health

  • armour

  • hours

  • water

  • food

Saved automatically

Conditional Saves

  • inventory

  • equipment

  • toolbar

  • death state

  • wanted

  • faction

  • appearance

  • info

  • cash

  • bank

Saved based on things that trigger them

Save Injections

Save injections are a simple way to define an object with multiple keys, and values to save. Save injections should be used sparingly.

Save injections work as a callback meaning that it runs a function before it sends back the data to save. With a save injection you are going to want to dynamically apply this data based on what is needed.

Important

You should only add a save injection once. It will automatically call the callback every 5 seconds to add to the saved data.

Example

Athena.player.save.addSaveInjection((player: alt.Player) => {
    return { hello: 'world' };
});

The above automatically saves the key hello and value world every 5 seconds

Conditional Saving

You do not need a key to exist in the Character interface to save data. However, it is best practice to extend the Character interface in your plugin to apply new values.

Extending the Interface

import * as alt from 'alt-server';
import * as charRef from '../../../shared/interfaces/character';

// Extends the player interface.
declare module 'alt-server' {
    export interface Character extends Partial<charRef.Character> {
        someNewValue?: null | undefined | string;
    }
}

The Conditional Save

Athena.player.save.field(player, 'someNewValue', player.data.someNewValue);

Used for single key and value

OR

Athena.player.save.partial(player, { someNewValue: player.data.someNewValue });

Used for multiple keys and values

PreviousProgress BarNextShard

Last updated 3 years ago