Introduction
The Player Data system is the heart of RSG Frameworkโs player management. It handles all player information including character data, jobs, gangs, money, metadata, and inventory. Understanding this system is essential for creating resources that interact with players. Location:resources/[framework]/rsg-core/server/player.lua
Player data is automatically saved to the database at intervals defined in config (
UpdateInterval), and on logout.Core Features
๐ Comprehensive Data Management
- Character Info: Names, birthdate, gender, nationality
- Money System: Multiple currency types with transaction logging
- Jobs & Gangs: Full hierarchy system with grades and boss status
- Metadata: Health, hunger, thirst, stress, and custom data
- Reputation: Flexible reputation system for any activity
๐ Real-time Synchronization
- StateBags: Instant sync for frequently updated data
- Events: Server and client events for data changes
- Auto-save: Periodic database persistence
โ๏ธ Flexible API
- Player Functions: Comprehensive function set for data manipulation
- Direct Access: Read player data directly from PlayerData table
- Extension: Add custom methods and fields dynamically
Core Server Functions
RSGCore.Player.Login
- On player login, gets their data or sets default values
RSGCore.Player.CheckPlayerData
- Function called above on player join to gather player data (this is where you can add/remove additional player data)
RSGCore.Player.Logout
- Saves player on logout and removes them from active players table
RSGCore.Player.CreatePlayer
- Creates a new character and sets default data (any function inside the self table can be called on the player after using the GetPlayer function)
RSGCore.Player.Save
- Saves the playerโs info to the database
RSGCore.Player.DeleteCharacter
- Deletes a character and all corresponding data in the database
Player Object Functions
Once you have a Player object (viaRSGCore.Functions.GetPlayer(source)), you can use the following functions on that player:
Player.Functions.SetJob
- Sets a playerโs job and grade
Player.Functions.SetGang
- Sets a playerโs gang and grade
Player.Functions.SetJobDuty
- Sets a playerโs on/off duty status for their job
Player.Functions.AddMoney
- Add money to a playerโs account
Player.Functions.RemoveMoney
- Remove money from a playerโs account
Player.Functions.SetMoney
- Set a playerโs money to a specific amount
Player.Functions.GetMoney
- Get the amount of money a player has in a specific account
Player.Functions.SetMetaData
- Set metadata for a player
Player.Functions.GetMetaData
- Get metadata for a player
Player.Functions.AddRep
- Add reputation points for a specific reputation type
Reputation System: The framework includes a flexible reputation system stored in
metadata.rep. You can create any reputation types you need (hunting, fishing, crafting, lawman, outlaw, etc.)Player.Functions.RemoveRep
- Remove reputation points for a specific reputation type
Player.Functions.GetRep
- Get reputation points for a specific reputation type
hunting- Tracking, animal kills, perfect peltsfishing- Fish caught, legendary fishcrafting- Items crafted, quality of worklawman- Criminal arrests, bounties collectedoutlaw- Crimes committed, bounties escapedtrader- Goods sold, trading reputationdoctor- Patients healed, medical services- Custom types as needed for your server
Player.Functions.HasItem
- Check if player has a specific item
Player.Functions.SetPlayerData
- Set any player data field
Player.Functions.Save
- Manually save a playerโs data to database
Player.Functions.Logout
- Log a player out (removes from active players)
Player.Functions.UpdatePlayerData
- Trigger an update of player data to client
Accessing Player Data
Once you have a Player object, you can access their data directly:StateBags System
The RSG Framework uses FiveMโs StateBags system to sync specific metadata between server and client in real-time. This provides better performance than constantly triggering events.What are StateBags?
StateBags are key-value stores attached to entities (players, vehicles, etc.) that automatically sync between server and client. Theyโre more efficient than events for frequently updated data. Synced Metadata Keys:hunger(0-100)thirst(0-100)cleanliness(0-100)stress(0-100)health(0-600)isLoggedIn(boolean)
How StateBags Work
Reading StateBags (Client-Side)
Using StateBags in Resources
Benefits of StateBags
Performance: No need to constantly trigger events for metadata updates
Real-time: Changes sync instantly without event delays
Clean Code: Access data directly instead of callback hell
When to Use StateBags vs Events
Use StateBags for:- Frequently updated data (hunger, thirst, health)
- Data that needs instant client access
- Simple value syncing
- Complex data updates
- Actions that need validation
- One-time notifications
Example: Custom HUD Using StateBags
Complete Metadata Structure
The fullmetadata table structure in PlayerData:
Best Practices
Use StateBags for HUDs: For frequently updated display data (hunger, thirst, health), read from StateBags instead of triggering events
Performance Tips
- Batch Updates: When setting multiple metadata values, group them to reduce database writes
- Cache Player Objects: Store the Player object in a variable instead of calling GetPlayer multiple times
- Use GetRep Sparingly: If checking reputation frequently, cache the value locally
- Avoid Save Spam: Donโt call Player.Functions.Save() excessively - let auto-save handle it
Common Patterns
Next Steps
- Server Functions Reference - Complete server function list
- Configuration Guide - Configure player defaults
- Money System - Complete money system guide
- StateBags System - Deep dive into state synchronization
- Reputation System - Detailed reputation guide
Need help? Join the RSG Framework Discord!