Skip to content

Adding Custom Scores

Lynn edited this page Jun 1, 2019 · 1 revision

Registering a score tracker

To add a score tracker, regardless of whether it's global or per player, you have to register it:

local ScoreTracker = require 'utils.score_tracker'

local name = 'rocks-smashed' -- the name used to refer to the score in get/set functions
local locale_string = {'player_stats.rocks_smashed'} -- the translation
local icon = '[img=entity.rock-huge]' -- rich text icon, can be nil if no icon is needed

ScoreTracker.register(name, locale_string, icon)

When a certain score is updated, ScoreTracker.events.on_player_score_changed or ScoreTracker.events.on_global_score_changed events are fired. Those events can be used to trigger a GUI update for example.

Working with per-player scores

local ScoreTracker = require 'utils.score_tracker'

-- stores the score for this player only
ScoreTracker.change_for_player(player.index, 'rocks-smashed', 1)

-- gives the amount of rocks smashed by this player
ScoreTracker.get_for_player(player.index, 'rocks-smashed')

-- returns: {name, locale_string, icon, value}
-- primarily used when you need multiple settings and the translations or icons
ScoreTracker.get_player_scores_with_metadata(player.index, {'rocks-smash', 'another-score'})

Working with global scores

local ScoreTracker = require 'utils.score_tracker'

-- stores the score globally, doesn't track per player
ScoreTracker.change_for_global(player.index, 'rocks-smashed')

-- gives the amount of rocks smashed globally
ScoreTracker.get_for_global('rocks-smashed')

-- returns: {name, locale_string, icon, value}
-- primarily used when you need multiple settings and the translations or icons
ScoreTracker.get_global_scores_with_metadata({'rocks-smash', 'another-score'})

Customizing existing displays

There are currently two tools to display scores, one is for global scores and the other is for player scores. You can also edit either of those defaults via by changing their respective tables in config.lua.

Global scores

Global scores are accessible via the Score button in the top menu. You can configure the available options in this list via the config global:

local global_to_show = global.config.score.global_to_show
global_to_show[#global_to_show + 1] = 'the-name-of-the-score

Player specific scores

Player specific scores are available via the /whois <player_name> command. You can configure the available options in this via the config global:

local global_to_show = global.config.redmew_commands.whois.player_data_to_show
global_to_show[#global_to_show + 1] = 'the-name-of-the-score
Clone this wiki locally