🎁
Loyalty - QBCore
  • What's new?
  • Royalty Program - QBCore
  • App Configuration
  • Tiers
  • Exports
  • Custom Money Handling
  • Loyalty Program Language Configuration Guide
Powered by GitBook
On this page
  • Overview
  • Export Usage
  • Example Implementations
  • Important Notes
  • Tier Thresholds

Tiers

Overview

The loyalty system provides an export that allows you to check a player's loyalty tier (Silver, Gold, or Platinum) based on their accumulated points. You can use this information to provide tier-based benefits like discounts, exclusive access, or special features.

Export Usage

The loyalty system exposes the following export:

exports['Loyalty']:GetPlayerTier(playerId, function(success, tier)
    -- Your code here
end)

Parameters

  • playerId: The server ID of the player

  • callback: Function that receives two parameters:

    • success: Boolean indicating if the operation was successful

    • tier: String containing the player's tier ("Silver", "Gold", "Platinum") or error message

Example Implementations

1. Basic Shop Discount System

-- In your shop script
function CalculatePrice(playerId, basePrice)
    exports['Loyalty']:GetPlayerTier(playerId, function(success, tier)
        if not success then
            return basePrice -- No discount if error
        end
        
        local discount = 0
        if tier == "Silver" then
            discount = 0.05 -- 5% discount
        elseif tier == "Gold" then
            discount = 0.10 -- 10% discount
        elseif tier == "Platinum" then
            discount = 0.15 -- 15% discount
        end
        
        return basePrice * (1 - discount)
    end)
end

2. VIP Area Access

-- In your VIP area script
AddEventHandler('playerAttemptingVIPEntry', function(playerId)
    exports['Loyalty']:GetPlayerTier(playerId, function(success, tier)
        if success then
            if tier == "Platinum" then
                -- Allow free entry
                TriggerClientEvent('vip:allowEntry', playerId, true)
            elseif tier == "Gold" then
                -- Charge reduced entry fee
                TriggerClientEvent('vip:allowEntry', playerId, true, 500)
            else
                -- Regular entry fee or deny access
                TriggerClientEvent('vip:allowEntry', playerId, false)
            end
        else
            -- Handle error case
            TriggerClientEvent('vip:allowEntry', playerId, false)
        end
    end)
end)

3. Special Item Access

-- In your shop/inventory script
function CanPurchaseSpecialItem(playerId, itemName)
    exports['Loyalty']:GetPlayerTier(playerId, function(success, tier)
        if not success then return false end
        
        local requiredTiers = {
            ['rare_item'] = "Gold",
            ['legendary_item'] = "Platinum"
        }
        
        local requiredTier = requiredTiers[itemName]
        if not requiredTier then return true end -- No tier restriction
        
        -- Compare tiers (assuming hierarchy: Platinum > Gold > Silver)
        if tier == "Platinum" then return true end
        if tier == "Gold" and requiredTier == "Gold" then return true end
        
        return false
    end)
end

Important Notes

  1. Tier Names: Always use exact tier names as defined:

    • "Silver"

    • "Gold"

    • "Platinum"

  2. Error Handling: Always check the success parameter before using the tier value:

exports['Loyalty']:GetPlayerTier(playerId, function(success, tier)
    if not success then
        print("Error: " .. tier) -- tier contains error message when success is false
        return
    end
    -- Continue with your code
end)
  1. Asynchronous Operation: The export uses a callback function because it queries the database. Make sure your code handles this asynchronous behavior appropriately.

Tier Thresholds

  • Silver: 0-999 points

  • Gold: 1,000-4,999 points

  • Platinum: 5,000+ points

These thresholds are configured in Config.Tiers and should be considered when designing tier-based features.

-- Tiers Configuration
Config.Tiers = {
    { name = "Silver", minPoints = 0, maxPoints = 999 },
    { name = "Gold", minPoints = 1000, maxPoints = 4999 },
    { name = "Platinum", minPoints = 5000 }
}

PreviousApp ConfigurationNextExports

Last updated 7 months ago