GE Lua Documentation

Press F to search!

addNewPlayerScore

Definition


-- @/lua/ge/extensions/gameplay/crawl/saveSystem.lua:771

local function addNewPlayerScore(trailId, time, penaltyPoints)
  local trail = M.getPlayerCrawlTrailById(trailId)
  if not trail then
    -- Mission trails may not be in player trail list, which is expected
    log("D", logTag, "Trail not found in player list (likely mission trail): " .. tostring(trailId))
    return
  end

  local saveData = trail.saveData
  local currentDate = os.time()
  local isNewBestTime = false
  local isNewBestPenaltyPoints = false

  -- Update best time if this is better (and time is valid)
  if time and time > 0 and time < saveData.bestTime then
    saveData.bestTime = time
    saveData.bestTimeDate = currentDate
    isNewBestTime = true
  end

  -- Update best penalty points if this is better (lower is better)
  if penaltyPoints and penaltyPoints >= 0 and penaltyPoints < saveData.bestPenaltyPoints then
    saveData.bestPenaltyPoints = penaltyPoints
    saveData.bestPenaltyPointsDate = currentDate
    isNewBestPenaltyPoints = true
  end

  -- Increment attempt counter
  saveData.attempts = saveData.attempts + 1

  -- Save the updated data
  savePlayerCrawlTrailScoresForTrailById(trailId)

  return {
    isNewBestTime = isNewBestTime,
    isNewBestPenaltyPoints = isNewBestPenaltyPoints,
    bestTime = saveData.bestTime,
    bestPenaltyPoints = saveData.bestPenaltyPoints
  }
end

Callers

@/lua/ge/extensions/gameplay/crawl/general.lua
    if trailId then
      gameplay_crawl_saveSystem.addNewPlayerScore(trailId, time, points)
    end