Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] - add link to item metadata for phone data #10

Open
Mesrine67 opened this issue Dec 4, 2024 · 0 comments
Open

[suggestion] - add link to item metadata for phone data #10

Mesrine67 opened this issue Dec 4, 2024 · 0 comments

Comments

@Mesrine67
Copy link

Synchronizing phone data through metadata could enhance roleplay for players. For example, they could own two phones or hand over a phone with all its associated data intact.

local _config = {
    Locale = 'fr',
    PhonePrefixes = {
        fr = {
            countryCode = '+33',
            prefixes = { '06', '07' },
            defaultOperator = 'Orange',
            defaultSubscription = 'Prepaid'
        },
        en = {
            countryCode = '+1',
            prefixes = { '201', '202', '203' },
            defaultOperator = 'Verizon',
            defaultSubscription = 'Postpaid'
        }
    }
}

local templateApps = {
    zcloud = {
        login = true,
        doubleAuthentification = true,
        loginAccess = '[email protected]',
        loginPassword = 'DevZ_Phone-123',
    },
    email = {
        login = false,
        doubleAuthentification = false,
        loginAccess = '',
        loginPassword = '',
    },
}

local hookId = exports.ox_inventory:registerHook('createItem', function(payload)
    print(json.encode(payload, { indent = true }))
    if payload.item.name == 'phone' then
        local metadata = payload.metadata or {}
        local localeConfig = _config.PhonePrefixes[_config.Locale]
        if not localeConfig or not localeConfig.prefixes or #localeConfig.prefixes == 0 then
            lib.print.error('Configuration introuvable ou invalide pour la langue : '.._config.Locale)
            return payload.metadata
        end
        local prefix = localeConfig.prefixes[math.random(1, #localeConfig.prefixes)]
        metadata.imei = metadata.imei or ('IMEI-' .. lib.string.random('AAAA1111', 12))
        metadata.sim_number = metadata.sim_number or (localeConfig.countryCode .. prefix .. lib.string.random('1111111', 7))
        metadata.operator = metadata.operator or localeConfig.defaultOperator
        metadata.subscription_type = metadata.subscription_type or localeConfig.defaultSubscription
        metadata.apps = metadata.apps or templateApps
        print('[INFO] Téléphone créé avec les métadonnées suivantes :', json.encode(metadata, { indent = true }))
        return metadata
    end
    return payload.metadata
end, {
    print = true,
    itemFilter = { phone = true }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant