π Battery System
Key Features
- Realistic Battery Drain: Different drain rates for active/inactive phone states
- Vehicle Charging: Charge phones using USB cables in compatible vehicles
- Signal Management: Phone loses signal when battery dies, restores when charged
- Database Persistence: Battery levels saved and restored across sessions
- Unique Phone Support: Individual battery tracking for each phone IMEI
- Configurable Settings: Highly customizable drain rates, charging speeds, and thresholds
Configuration
config/config.battery.lua
lua
Inventory Item
You need this item to use the built-in charging system.
lua
lua
Exports(client-side)
Battery Information
GetBatteryLevel()
Returns the current battery percentage.
lua
GetBatteryInfo()
Returns battery information.
lua
Battery Control
SetBatteryLevel(level)
Sets the battery to a specific percentage (0-100).
lua
ChargeBattery(amount)
Adds the specified amount to current battery level.
lua
Charging Control
StartCharging()
Starts the charging process.
lua
StopCharging()
Stops the charging process.
lua
Events
Client Events
Battery State Events
lua
Phone State Events
lua
Vehicle Charging Integration
How Vehicle Charging Works
- Requirements: Player must have USB cable item in inventory
- Vehicle Check: Player must be in a compatible vehicle with engine running
- Usage: Use USB cable item to start charging
- Automatic Stop: Charging stops when exiting vehicle or engine turns off
Database Integration
Automatic Saving
- Battery data is automatically saved every 6 updates (~30 seconds during drain)
- Immediate save on significant events (charging start/stop, manual changes)
- Data persists across server restarts and resource restarts
Performance Considerations
Best Practices
- Use appropriate charging rates: Don't exceed realistic charging speeds (1-20% per minute)
- Handle edge cases: Check for nil values when accessing battery data
Troubleshooting
Common Issues
- Battery not draining: Check if
Config.Battery.Enabledis true - Vehicle charging not working: Verify USB cable item exists and vehicle types are configured
- Database not saving: Check database permissions and connection
This battery system provides a comprehensive and realistic phone battery experience while remaining highly customizable and extensible for your specific server needs.