# Games

#### Gaming Rewards & Achievements

Enhance player engagement and retention in your games with strategic rewards and achievements.

**Daily Login Rewards**

Reward players for logging in consecutively:

```lua
-- Roblox example for daily rewards
local GiftoinModule = require(ServerScriptService:WaitForChild("GiftoinModule"))
local GiftoinEvents = GiftoinModule.Events

-- Track player logins
local function onPlayerJoin(player)
    local userId = tostring(player.UserId)
    local lastLogin = getLastLoginTime(userId)
    local currentTime = os.time()
    
    -- Check if this is a new daily login
    if isNewDay(lastLogin, currentTime) then
        -- Increment streak counter
        local streak = incrementLoginStreak(userId)
        
        -- Award points based on streak length
        local pointsToAward = calculateStreakPoints(streak)
        GiftoinEvents.sendPoints(player, "daily_login", pointsToAward)
        
        -- On milestone days, send special gifts
        if streak == 7 then
            -- Weekly milestone reward
            GiftoinEvents.sendSpecialReward(player, "weekly_milestone")
        elseif streak == 30 then
            -- Monthly milestone reward
            GiftoinEvents.sendSpecialReward(player, "monthly_milestone")
        end
        
        -- Update last login time
        updateLastLoginTime(userId, currentTime)
    end
end

-- Connect to PlayerAdded event
game.Players.PlayerAdded:Connect(onPlayerJoin)
```

**Achievement Systems**

Create a comprehensive achievement system:

1. Define achievement categories:
   * Progression (completing levels, reaching milestones)
   * Collection (gathering items, completing sets)
   * Skill (mastering game mechanics, setting records)
   * Social (team play, community participation)
2. Design a reward structure:
   * Digital collectibles for visual achievements
   * In-game currency or items for functional rewards
   * Status badges for social recognition
   * Access to exclusive content or features
3. Implementation example:

```javascript
// Track achievement progress and award when completed
function updateAchievementProgress(userId, achievementId, progress) {
  // Get current progress
  const currentProgress = getUserAchievementProgress(userId, achievementId);
  const achievement = getAchievementDetails(achievementId);
  
  // Update progress
  const newProgress = currentProgress + progress;
  saveUserAchievementProgress(userId, achievementId, newProgress);
  
  // Check if achievement is completed
  if (newProgress >= achievement.targetValue && !isAchievementCompleted(userId, achievementId)) {
    // Mark as completed
    markAchievementCompleted(userId, achievementId);
    
    // Send Giftoin reward
    sendAchievementReward(userId, achievementId);
  }
}

// Send the reward through Giftoin
async function sendAchievementReward(userId, achievementId) {
  const achievement = getAchievementDetails(achievementId);
  const userEmail = getUserEmail(userId);
  
  try {
    const response = await fetch(`https://api.giftoin.org/api/v1/gcm/reseller/campaign/${achievement.campaignId}/order`, {
      method: 'POST',
      headers: {
        'x-gft_api_key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        contacts: [userEmail],
        title: `Achievement Unlocked: ${achievement.name}`,
        description: achievement.rewardDescription,
        metadata: {
          achievementId: achievementId,
          userId: userId
        }
      })
    });
    
    // Notify the user in-game
    notifyUserOfAchievement(userId, achievementId);
    
  } catch (error) {
    console.error(`Error sending achievement reward for ${achievementId}:`, error);
    // Handle error - queue for retry
  }
}
```

**Player Retention Strategies**

* Create progression systems with increasing rewards
* Implement surprise gifts for reaching milestones
* Design limited-time events with exclusive rewards
* Create collection mechanics that encourage completionism
* Implement leaderboards with periodic rewards
* Use rewards to guide players to underutilized game features

**Analytics and Optimization**

Track these metrics to optimize your gaming rewards:

* Redemption rates by reward type
* Player retention lift from reward programs
* Session frequency and duration changes
* Social sharing of achievements
* Conversion impact on in-game purchases


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.giftoin.org/resources/use-cases/games.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
