πBattery System
The YSeries battery system provides realistic phone battery simulation with automatic drain, charging capabilities. The system saves battery state to the database and persists across server restarts.
Key Features
Configuration
config/config.battery.lua
config/config.battery.lua-- With these settings, a full charge will last around 2 hours.
Config.Battery = {}
Config.Battery.Enabled = false -- Enable battery on the phone, you'll need to use the exports to charge it.
Config.Battery.DrainInterval = {
Active = { 50, 60 }, -- Always keep 2 numbers in the array. Min and Max seconds to drain 1% of the battery.
Inactive = { 80, 120 } -- Always keep 2 numbers in the array. Min and Max seconds to drain 1% of the battery.
}
Config.Battery.StartingBattery = 100 -- Starting battery percentage
Config.Battery.ShutdownThreshold = 0 -- Phone shuts down at this percentage
Config.Battery.ChargingRate = 5 -- Percentage per minute when charging
-- Vehicle Charging System
Config.Battery.VehicleCharging = {
Enabled = true, -- Enable vehicle charging
RequiredItem = "usb_cable", -- Required item to charge in vehicle
ChargingRate = 8, -- Percentage per minute when charging in vehicle(default)
EngineRequired = true, -- Vehicle engine must be running
MinEngineHealth = 300, -- Minimum engine health required for charging
VehicleTypes = { -- Vehicle types that support charging
[0] = true, -- Compacts
[1] = true, -- Sedans
[2] = true, -- SUVs
...
}Inventory Item
Exports(client-side)
Battery Information
GetBatteryLevel()
GetBatteryLevel()GetBatteryInfo()
GetBatteryInfo()Battery Control
SetBatteryLevel(level)
SetBatteryLevel(level)ChargeBattery(amount)
ChargeBattery(amount)Charging Control
StartCharging()
StartCharging()StopCharging()
StopCharging()Events
Client Events
Battery State Events
Phone State Events
Vehicle Charging Integration
How Vehicle Charging Works
Database Integration
Automatic Saving
Performance Considerations
Best Practices
Troubleshooting
Common Issues
Last updated