GE Lua Documentation

Press F to search!

setScenarioHighscoresCustom

Definition


-- @/lua/ge/extensions/core/highscores.lua:86

local function setScenarioHighscoresCustom(timeInMillis, record, levelName, scenarioName, configKey)
  local currentHighscores = getScenarioHighscores(levelName,scenarioName,configKey)
  timeInMillis = math.floor(timeInMillis+.5)

  record.detailed = false
  record.timeStamp = os.time()
  record.formattedTimestamp = os.date("!%c",os.time())
  record.timeInMillis = timeInMillis
  record.formattedTime = string.format("%.2d:%.2d.%.3d", (timeInMillis/1000)/60, (timeInMillis/1000)%60, timeInMillis%1000)

  log('I', 'highscores', 'Writing Highscore for '..levelName.."/"..scenarioName.."/"..configKey .. ' = ' .. dumps(record))

  currentHighscores[#currentHighscores+1] = record

  table.sort(currentHighscores, function (a,b) return (a.timeInMillis < b.timeInMillis) end)

  local newIndex = -1
  for k,v in ipairs(currentHighscores) do
    if v == record then newIndex = k end
  end
  if newIndex > maxHighScoreCount then
    return -1
  end
  local newHighscores = {}
  for i = 1,maxHighScoreCount do
    newHighscores[i] = currentHighscores[i]
  end

  local scores = M.getHighscores()
  if scores[levelName] == nil then
    scores[levelName] = {}
  end
  if scores[levelName][scenarioName] == nil then
    scores[levelName][scenarioName] = {}
  end
  if scores[levelName][scenarioName][configKey] == nil then
    scores[levelName][scenarioName][configKey] = {}
  end

  scores[levelName][scenarioName][configKey] = newHighscores
  setHighscores(scores)
  return newIndex
end

Callers

@/lua/ge/extensions/flowgraph/nodes/gameplay/race/raceHighscoresLap.lua

      local place = core_highscores.setScenarioHighscoresCustom(
        state.historicTimes[#state.historicTimes].endTime*1000,
@/lua/ge/extensions/core/highscores.lua
  }
  return M.setScenarioHighscoresCustom(timeInMillis,record,levelName,scenarioName,configKey)
end
@/lua/ge/extensions/flowgraph/nodes/gameplay/race/raceHighscoresComplete.lua

      local place = core_highscores.setScenarioHighscoresCustom(
        state.historicTimes[#state.historicTimes].endTime*1000,
@/lua/ge/extensions/scenario/quickRace.lua

    local place = core_highscores.setScenarioHighscoresCustom(times[#times]*1000,record,scenario.levelName,scenario.scenarioName,M.getConfigKey(false,nil,0))

  local place = core_highscores.setScenarioHighscoresCustom(final.finalTime*1000, record ,scenario.levelName,scenario.scenarioName,M.getConfigKey())
  local scores = core_highscores.getScenarioHighscores(scenario.levelName, scenario.scenarioName, M.getConfigKey())
@/lua/ge/extensions/scenario/busdriver.lua
    }
    core_highscores.setScenarioHighscoresCustom(final.finalTime*1000, record, scenario.levelName, scenario.name, "busRoute")
  end