> For the complete documentation index, see [llms.txt](https://dragon-heart-studios.gitbook.io/dragonheartstudios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dragon-heart-studios.gitbook.io/dragonheartstudios/scripts/dhs-bankingsim/integration.md).

# Integration

{% hint style="warning" %}
WARNING: ONLY MESS WITH THESE IF YOU KNOW WHAT YOU ARE DOING!!!!
{% endhint %}

### Phone Banking

{% hint style="info" %}
There is many different types of phones out there so this event is open for you to incorporate whatever you could possibly need!
{% endhint %}

```lua
-- Add additional phone resources here as needed.
function EditableFunctions.SendPhoneMessage(currentPhoneName, payload)
    if currentPhoneName == 'lb-phone' then
        exports['lb-phone']:SendCustomAppMessage('dhs-banking', payload)
    elseif currentPhoneName == 'roadphone' then
        exports['roadphone']:SendMessageNUI({
            customevent = payload.action,
            data        = payload.data,
        })
    elseif currentPhoneName == '17mov_Phone' then
        exports['17mov_Phone']:SendAppMessage('dhs-banking', {
            action  = payload.action,
            payload = payload.data,
        })
    else
        SendNUIMessage(payload)
    end
end

-- Add a new elseif block to support your phone resource.
function EditableFunctions.RegisterPhoneApp(openCallback, closeCallback)
    local detectedName = Bridge.Phone.GetPhoneName()
    local detected = false

    -- Fallback detection if Community Bridge returns 'default'.
    if detectedName == 'default' or detectedName == '_default' then
        if GetResourceState('lb-phone') == 'started' then
            detectedName = 'lb-phone'
        elseif GetResourceState('roadphone') == 'started' then
            detectedName = 'roadphone'
        elseif GetResourceState('17mov_Phone') == 'started' then
            detectedName = '17mov_Phone'
        end
    end

    if Config.Debug then
        print('[DHS-BankingSim][Phone] Detected phone resource: ' .. tostring(detectedName))
    end

    if detectedName == 'lb-phone' then
        local ok, err = pcall(function()
            exports['lb-phone']:AddCustomApp({
                identifier = 'dhs-banking',
                name = Config.BankingName or 'Fleeca Bank',
                description = L('lua_phone.app_name'),
                icon = 'https://i.imgur.com/banking-icon.png',
                ui = GetCurrentResourceName() .. '/web/build/phone.html',
                defaultApp = true,
                fixBlur = true,
                keepOpen = true,
                onOpen = function()
                    openCallback()
                end,
                onClose = function()
                    closeCallback()
                end,
            })
        end)
        if ok then
            detected = true
            if Config.Debug then
                print('[DHS-BankingSim][Phone] Registered app with lb-phone')
            end
        elseif Config.Debug then
            print('[DHS-BankingSim][Phone] Failed to register with lb-phone: ' .. tostring(err))
        end
    elseif detectedName == 'roadphone' then
        -- roadphone registers apps via config.json, not Lua.
        -- Add the following to the "AppStore" array in roadphone's config.json:
        --
        --   {
        --     "name": "Fleeca Bank",
        --     "light_icon": "/public/img/Apps/light_mode/bank.webp",
        --     "dark_icon": "/public/img/Apps/dark_mode/bank.webp",
        --     "default": true,
        --     "category": "apps",
        --     "custom_app_id": "dhs-banking",
        --     "redirect": "custom_app",
        --     "url": "https://cfx-nui-DHS-BankingSim/web/build/phone.html?phone=roadphone",
        --     "darkmode": true,
        --     "allowJobs": [],
        --     "disallowJobs": [],
        --     "custom_event": { "active": false, "closeWhenOpenApp": false }
        --   }
        --
        if Config.Debug then
            print('[DHS-BankingSim][Phone] roadphone detected — ensure dhs-banking is in config.json AppStore with redirect=custom_app.')
        end
        detected = true

        RegisterNUICallback('phoneRoadphoneReady', function(_, cb)
            cb({})
            openCallback()
        end)

        RegisterNUICallback('phoneGetBankingData', function(_, cb)
            local result = lib.callback.await('DHS-BankingSim:Server:PhoneCheckEnrollment', false)
            if not result or not result.success then
                cb({ error = 'no_connection' })
                return
            end
            if not result.enrolled then
                cb({ error = 'not_enrolled' })
                return
            end
            if result.status == 'disabled' then
                cb({ error = 'disabled' })
                return
            end
            if result.status == 'locked' then
                cb({ error = 'locked' })
                return
            end
            local bankingData = lib.callback.await('DHS-BankingSim:Server:GetPlayerBankingData', false)
            if not bankingData then
                cb({ error = 'no_data' })
                return
            end
            cb({
                enrolled      = result.enrolled,
                hasSession    = result.hasSession,
                status        = result.status,
                playerName    = bankingData.playerName    or 'Unknown',
                citizenId     = bankingData.citizenId     or 'N/A',
                cash          = bankingData.cash          or 0,
                bank          = bankingData.bank          or 0,
                accounts      = bankingData.accounts      or {},
                transactions  = bankingData.transactions  or {},
                bills         = bankingData.bills         or {},
                cards         = bankingData.cards         or {},
                loans         = bankingData.loans         or {},
                theme         = bankingData.theme         or 'dark',
                bankingName   = Config.BankingName        or 'Fleeca',
            })
        end)

    elseif detectedName == '17mov_Phone' then
        local resourceName = GetCurrentResourceName()
        local ok, err = pcall(function()
            local appData = {
                name            = 'dhs-banking',
                label           = Config.BankingName or 'Fleeca Bank',
                ui              = ("https://cfx-nui-%s/web/build/phone.html"):format(resourceName),
                icon            = 'https://i.imgur.com/banking-icon.png',
                iconBackground  = { angle = 135, colors = { '#4F46E5', '#7C3AED' } },
                default         = false,
                preInstalled    = true,
                resourceName    = resourceName,
                rating          = 5.0,
            }
            exports['17mov_Phone']:AddApplication(appData)

            RegisterNUICallback('phone17movReady', function(_, cb)
                cb({})
                openCallback()
            end)

            -- Re-register when the phone resource restarts
            RegisterNetEvent('17mov_Phone:Client:Ready', function()
                exports['17mov_Phone']:AddApplication(appData)
            end)

            AddEventHandler('onResourceStop', function(stopped)
                if stopped == resourceName then
                    exports['17mov_Phone']:RemoveApplication({
                        name         = 'dhs-banking',
                        resourceName = resourceName,
                    })
                end
            end)
        end)
        if ok then
            detected = true
            if Config.Debug then
                print('[DHS-BankingSim][Phone] Registered app with 17mov_Phone')
            end
        elseif Config.Debug then
            print('[DHS-BankingSim][Phone] Failed to register with 17mov_Phone: ' .. tostring(err))
        end
    -- Add your own phone resource here
    else
        if Config.Debug then
            print('[DHS-BankingSim][Phone] No supported phone resource detected. App registration skipped.')
            print('[DHS-BankingSim][Phone] Use /phonebank command to test phone banking.')
        end
    end

    return detected, detectedName

end
```

***

## Door Locks

```lua
-- ================================================
-- CUSTOM DOORLOCK BACKEND (CLIENT)
-- ================================================
-- Set Config.Doorlock.Mode = 'custom' in config/config.lua, then implement
-- the three functions below to wire door locking into any doorlock resource.
--
-- Parameters (ApplyState / RegisterBranch):
--   bankId  - numeric branch ID (matches Config.Banks[*].locations[*].id)
--   locked  - boolean (true = lock, false = unlock)
--   doors   - the branch's `doors` array from config (may be empty)

--- Lock/unlock a branch's front doors. Called when the server broadcasts a state change.
function EditableFunctions.CustomDoorlockApplyState(bankId, locked, doors)
    -- for _, door in ipairs(doors or {}) do
    --     exports['my_doorlock']:SetDoorState(door.id, locked)
    -- end
end

--- Register branch doors on resource start.
function EditableFunctions.CustomDoorlockRegisterBranch(bankId, doors)
    -- for _, door in ipairs(doors or {}) do
    --     exports['my_doorlock']:RegisterDoor(door)
    -- end
end

--- Clean up any doors registered in CustomDoorlockRegisterBranch on resource stop.
function EditableFunctions.CustomDoorlockCleanup()
    -- exports['my_doorlock']:RemoveAllDHSDoors()
end
```
