Battery System

Quasar Smartphone has a huge battery system, managed by intelligent json that is stored in your asset, where you will find the information of each player along with their battery. Here we will teach you everything about the battery system and its functionalities.

How do I enable the battery system?

To enable the battery system, simply enable Config.EnableBattery within your config.lua.

I can't use the item powerbank

If this is your case, you may not have an inventory that uses native qbcore or esx events. In this case we recommend that you contact the creator of your inventory and make the appropriate modifications on the Smartphone or on your own inventory system.

I have general problems with the battery

You can try simply changing the content of battery.json on your qs-smarphone to {} and it will automatically reset all battery systems and their caches.


Battery usage mode

Remember to have Config.EnableBattery enabled in your config.lua, otherwise this will not work.

You will be able to manipulate the settings so that it takes more or less battery depending on an application, as well as manipulate the overall battery usage that will be used. This is found within config.lua, using Config.Battery.

You can add or remove applications, adding or subtracting battery usage depending on the app used, manage it as you like.

Config.Battery = {
    default = 0.01, -- This is the rate at which the battery drains by default.
    apps = { -- The following applications will make your battery go down faster.
        ['phone'] = 0.02,
        ['photos'] = 0.02,
        ['messages'] = 0.02,
        ['settings'] = 0.02,
        ['clock'] = 0.02,
        ['camera'] = 0.02,
        ['mail'] = 0.02,
        ['bank'] = 0.02,
        ['calendar'] = 0.02,
        ['notes'] = 0.02,
        ['calculator'] = 0.02,
        ['store'] = 0.02,
        ['music'] = 0.02,
        ['ping'] = 0.02,
        ['instagram'] = 0.02,
        ['garage'] = 0.02,
        ['whatsapp'] = 0.02,
        ['twitter'] = 0.02,
        ['advert'] = 0.02,
        ['tinder'] = 0.02,
        ['cs-stories'] = 0.02,
        ['youtube'] = 0.02,
        ['uber'] = 0.02,
        ['darkweb'] = 0.02,
        ['state'] = 0.02,
        ['meos'] = 0.02,
        ['jump'] = 0.02,
        ['business'] = 0.02,
        ['society'] = 0.02,
        ['spotify'] = 0.02,
        ['flappy'] = 0.02,
        ['kong'] = 0.02,
        ['group-chats'] = 0.02,
        ['uberDriver'] = 0.02,
        ['rentel'] = 0.02,
        ['racing'] = 0.02,
        ['labyrinth'] = 0.02,
        ['tower'] = 0.02,
        ['tiktok'] = 0.02,
        -- ['example'] = 0.02,
    }
}

Battery recharging via Powerbank

You can use the powerbank item, which will begin to recharge your phone's battery until it reaches 100%, at which point the item will stop having its effect. Don't forget to add said item to your database or item base to be able to use it.


Recharge via charging spot

We only include one spot in the configuration, but you can add as many as you want.

You can charge the phone using the charger spots that you will find on your map, these are found in the same config.lua in the Config.ChargerSpots configuration. You can create infinite charging spots for players, where their phone will be taken away and the level of charge their phone contains will be shown until it reaches 100%.

-- Here you can add plugs to charge your phone wherever you want.
Config.ChargerSpots = {
    {
        coords = vec3(1430.043945, -2004.237305, 62.659302),
        isAvailable = true,
        chargeSpeed = 3.0 -- 3 second later +3 charge.
    },
}

Administrator command

Administrators will be able to use the battery charge for other players by enabling the Config.AdminCommand within config.lua, there we can manage the permissions or the exclusive command for such a thing. The command will be used as follows /adminbattery id ammount.

-- Usage /adminbattery id ammount
Config.AdminCommand = true -- Recharge the batery for admins?
Config.AdminCommandName = 'adminbattery'
Config.AdminCommandDescription = 'Recharge your battery like a elon musk'
Config.AdminPermissions = 'admin'

Exports to check the battery

This export will simply return the battery level on the client-side, you can use it to create interesting events.

We can use the getBattery export to check the battery on the client side, this is a simple export and we can execute it as follows.

-- Export to check battery from the client-side
exports['qs-smartphone']:getBattery()

Last updated

Was this helpful?