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
Tier Names: Always use exact tier names as defined:
"Silver"
"Gold"
"Platinum"
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)
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.