diff --git a/config.lua b/config.lua index 95398b29..602fab19 100644 --- a/config.lua +++ b/config.lua @@ -80,7 +80,19 @@ global.config = { }, -- enables score and tracking thereof score = { - enabled = true + enabled = true, + + -- the global score trackers to show + global_to_show = { + 'satellites-launched', + 'aliens-killed', + 'built-by-players', + 'built-by-robots', + 'trees-cut', + 'rocks-smashed', + 'kills-by-trains', + 'coins-spent' + } }, -- adds a paint brush paint = { diff --git a/features/gui/score.lua b/features/gui/score.lua index a1d0aeff..0890df19 100644 --- a/features/gui/score.lua +++ b/features/gui/score.lua @@ -1,26 +1,80 @@ +local Global = require 'utils.global' local Event = require 'utils.event' -local PlayerStats = require 'features.player_stats' +local Token = require 'utils.token' +local Schedule = require 'utils.task' local Gui = require 'utils.gui' local Color = require 'resources.color_presets' local Server = require 'features.server' local ScoreTracker = require 'utils.score_tracker' -local concat = table.concat - +local pairs = pairs +local scores_to_show = global.config.score.global_to_show +local set_timeout_in_ticks = Schedule.set_timeout_in_ticks local main_frame_name = Gui.uid_name() local main_button_name = Gui.uid_name() -local descriptions = { - {disc = 'Satellites launched', icon = '[img=item.satellite]'}, - {disc = 'Biters liberated', icon = '[img=entity.medium-biter]'}, - {disc = 'Buildings by hand', icon = '[img=utility.hand]'}, - {disc = 'Buildings by robots', icon = '[img=item.construction-robot]'}, - {disc = 'Trees chopped', icon = '[img=entity.tree-02]'}, - {disc = 'Rocks smashed', icon = '[img=entity.rock-huge]'}, - {disc = 'Kills by train', icon = '[img=item.locomotive]'}, - {disc = 'Coins spent', icon = '[img=item.coin]'}, +local memory = { + redraw_score_scheduled = false, + player_last_position = {}, + player_death_causes = {} } -local function create_score_gui(event) +Global.register(memory, function(tbl) memory = tbl end) + +---Creates a map of score name => {captain, tooltip} +local function get_global_score_labels() + local metadata = ScoreTracker.get_score_metadata() + local scores = {} + + for index = 1, #scores_to_show do + local score_name = scores_to_show[index] + local score_metadata = metadata[score_name] + if score_metadata then + local icon = score_metadata.icon + local label_text = '' + if icon then + label_text = icon .. ' ' + end + + scores[score_name] = { + caption = label_text .. ScoreTracker.get_for_global(score_name), + tooltip = score_metadata.localised_string + } + end + end + + return scores +end + +local do_redraw_score = Token.register(function() + local players = game.connected_players + local scores = get_global_score_labels() + + for i = 1, #players do + local player = players[i] + local frame = player.gui.top[main_frame_name] + + if frame and frame.valid then + local score_table = frame.score_table + for score_name, textual_display in pairs(scores) do + score_table[score_name].caption = textual_display.caption + end + end + end + + memory.redraw_score_scheduled = false +end) + +local function schedule_redraw_score() + if memory.redraw_score_scheduled then + return + end + + -- throttle redraws + set_timeout_in_ticks(30, do_redraw_score) + memory.redraw_score_scheduled = true +end + +local function player_joined_game(event) local player = game.get_player(event.player_index) if not player then return @@ -38,37 +92,6 @@ local function create_score_gui(event) end end -local function refresh_score() - local players = game.connected_players - local count = game.forces.player.get_item_launched('satellite') - - local satellites_launched = concat {descriptions[1].icon .. ' ', count, ' '} - local biters_liberated = concat {descriptions[2].icon .. ' ', PlayerStats.get_total_biter_kills(), ' '} - local buildings_by_hand = concat {descriptions[3].icon .. ' ', PlayerStats.get_total_player_built_entities(), ' '} - local buildings_by_robot = concat {descriptions[4].icon .. ' ', PlayerStats.get_total_robot_built_entities(), ' '} - local trees_chopped = concat {descriptions[5].icon .. ' ', PlayerStats.get_total_player_trees_mined(), ' '} - local rocks_smashed = concat {descriptions[6].icon .. ' ', PlayerStats.get_total_player_rocks_mined(), ' '} - local kills_by_train = concat {descriptions[7].icon .. ' ', PlayerStats.get_total_train_kills(), ' '} - local coins_spent = concat {descriptions[8].icon .. ' ', PlayerStats.get_total_coins_spent(), ' '} - - for i = 1, #players do - local player = players[i] - local frame = player.gui.top[main_frame_name] - - if frame and frame.valid then - local score_table = frame.score_table - score_table.label_satellites_launched.caption = satellites_launched - score_table.label_biters_killed.caption = biters_liberated - score_table.label_player_built_entities.caption = buildings_by_hand - score_table.label_robot_built_entities.caption = buildings_by_robot - score_table.label_player_mined_trees.caption = trees_chopped - score_table.label_player_mined_stones.caption = rocks_smashed - score_table.label_kills_by_train.caption = kills_by_train - score_table.label_coins_spent.caption = coins_spent - end - end -end - local function score_label_style(label, color) local style = label.style style.font = 'default-bold' @@ -76,105 +99,47 @@ local function score_label_style(label, color) end local function score_show(top) - local count = game.forces.player.get_item_launched('satellite') - + local scores = get_global_score_labels() local frame = top.add {type = 'frame', name = main_frame_name} local score_table = frame.add {type = 'table', name = 'score_table', column_count = 8} local style = score_table.style style.vertical_spacing = 4 style.horizontal_spacing = 16 - local label = - score_table.add { - type = 'label', - name = 'label_satellites_launched', - caption = concat {descriptions[1].icon .. ' ', count, ' '}, - tooltip = descriptions[1].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_biters_killed', - caption = concat {descriptions[2].icon .. ' ', PlayerStats.get_total_biter_kills(), ' '}, - tooltip = descriptions[2].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_player_built_entities', - caption = concat {descriptions[3].icon .. ' ', PlayerStats.get_total_player_built_entities(), ' '}, - tooltip = descriptions[3].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_robot_built_entities', - caption = concat {descriptions[4].icon .. ' ', PlayerStats.get_total_robot_built_entities(), ' '}, - tooltip = descriptions[4].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_player_mined_trees', - caption = concat {descriptions[5].icon .. ' ', PlayerStats.get_total_player_trees_mined(), ' '}, - tooltip = descriptions[5].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_player_mined_stones', - caption = concat {descriptions[6].icon .. ' ', PlayerStats.get_total_player_rocks_mined(), ' '}, - tooltip = descriptions[6].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_kills_by_train', - caption = concat {descriptions[7].icon .. ' ', PlayerStats.get_total_train_kills(), ' '}, - tooltip = descriptions[7].disc - } - score_label_style(label, Color.white) - - label = - score_table.add { - type = 'label', - name = 'label_coins_spent', - caption = concat {descriptions[8].icon .. ' ', PlayerStats.get_total_coins_spent(), ' '}, - tooltip = descriptions[8].disc - } - score_label_style(label, Color.white) + for score_name, textual_display in pairs(scores) do + local label = score_table.add({ + type = 'label', + name = score_name, + caption = textual_display.caption, + tooltip = textual_display.tooltip + }) + score_label_style(label, Color.white) + end end -local function rocket_launched(event) - local entity = event.rocket - - if not entity or not entity.valid or not entity.force == 'player' then +local function global_score_changed(event) + if not event.value_changed then return end - local inventory = entity.get_inventory(defines.inventory.rocket) - if not inventory or not inventory.valid then + local found = false + for index = 1, #scores_to_show do + if scores_to_show[index] then + found = true + end + end + + if not found then return end - local count = inventory.get_item_count('satellite') - if count == 0 then + schedule_redraw_score() + + if event.score_name ~= 'satellites-launched' then return end - count = game.forces.player.get_item_launched('satellite') + count = event.new_value if (count < 10) or ((count < 50) and ((count % 5) == 0)) or ((count % 25) == 0) then local message = 'A satellite has been launched! Total count: ' .. count @@ -182,8 +147,6 @@ local function rocket_launched(event) game.print(message) Server.to_discord_bold(message) end - - refresh_score() end Gui.on_click( @@ -204,6 +167,5 @@ Gui.on_click( Gui.allow_player_to_toggle_top_element_visibility(main_button_name) -Event.add(defines.events.on_player_joined_game, create_score_gui) -Event.add(defines.events.on_rocket_launched, rocket_launched) -Event.on_nth_tick(300, refresh_score) +Event.add(defines.events.on_player_joined_game, player_joined_game) +Event.add(ScoreTracker.events.on_global_score_changed, global_score_changed) diff --git a/features/player_stats.lua b/features/player_stats.lua index 0f12260a..36fd1b30 100644 --- a/features/player_stats.lua +++ b/features/player_stats.lua @@ -1,12 +1,12 @@ -local Event = require 'utils.event' local Global = require 'utils.global' +local Event = require 'utils.event' local ScoreTracker = require 'utils.score_tracker' require 'utils.table' local pairs = pairs local sqrt = math.sqrt local rocks_smashed_name = 'rocks-smashed' -local trees_cut_name = 'trees-cut' +local trees_cut_down_name = 'trees-cut' local player_count_name = 'player-count' local kills_by_trains_name = 'kills-by-trains' local built_by_robots_name = 'built-by-robots' @@ -17,24 +17,23 @@ local coins_earned_name = 'coins-earned' local player_deaths_name = 'player-deaths' local player_console_chats_name = 'player-console-chats' local player_items_crafted_name = 'player-items-crafted' -local player_distance_walked_name = 'player-distance_walked' +local player_distance_walked_name = 'player-distance-walked' +local satellites_launched_name = 'satellites-launched' -ScoreTracker.register(rocks_smashed_name, {'Rocks smashed'}, '[img=entity.rock-huge]') -ScoreTracker.register(trees_cut_name, {'Trees cut down'}, '[img=entity.tree-02]') -ScoreTracker.register(player_count_name, {'Total players'}) -ScoreTracker.register(kills_by_trains_name, {'Kills by trains'}, '[img=item.locomotive]') -ScoreTracker.register(built_by_players_name, {'Built by hand'}, '[img=utility.hand]') -ScoreTracker.register(built_by_robots_name, {'Built by robots'}, '[img=item.construction-robot]') -ScoreTracker.register(aliens_killed_name, {'Aliens liberated'}, '[img=entity.medium-biter]') -ScoreTracker.register(coins_earned_name, {'Coins earned'}, '[img=item.coin]') -ScoreTracker.register(coins_spent_name, {'Coins spent'}, '[img=item.coin]') -ScoreTracker.register(player_deaths_name, {'Player deaths'}) -ScoreTracker.register(player_console_chats_name, {'Player console chats'}) -ScoreTracker.register(player_items_crafted_name, {'Player items crafted'}) -ScoreTracker.register(player_distance_walked_name, {'Player distance walked'}) - -local player_last_position = {} -local player_death_causes = {} +ScoreTracker.register(rocks_smashed_name, {'player_stats.rocks_smashed'}, '[img=entity.rock-huge]') +ScoreTracker.register(trees_cut_down_name, {'player_stats.trees_cut_down'}, '[img=entity.tree-02]') +ScoreTracker.register(player_count_name, {'player_stats.player_count'}) +ScoreTracker.register(kills_by_trains_name, {'player_stats.kills_by_trains'}, '[img=item.locomotive]') +ScoreTracker.register(built_by_players_name, {'player_stats.built_by_players'}, '[img=utility.hand]') +ScoreTracker.register(built_by_robots_name, {'player_stats.built_by_robots'}, '[img=item.construction-robot]') +ScoreTracker.register(aliens_killed_name, {'player_stats.aliens_killed'}, '[img=entity.medium-biter]') +ScoreTracker.register(coins_earned_name, {'player_stats.coins_earned'}, '[img=item.coin]') +ScoreTracker.register(coins_spent_name, {'player_stats.coins_spent'}, '[img=item.coin]') +ScoreTracker.register(player_deaths_name, {'player_stats.player_deaths'}) +ScoreTracker.register(player_console_chats_name, {'player_stats.player_console_chats'}) +ScoreTracker.register(player_items_crafted_name, {'player_stats.player_items_crafted'}) +ScoreTracker.register(player_distance_walked_name, {'player_stats.player_distance_walked'}) +ScoreTracker.register(satellites_launched_name, {'player_stats.satellites_launched'}, '[img=item.satellite]') local train_kill_causes = { ['locomotive'] = true, @@ -43,24 +42,20 @@ local train_kill_causes = { ['artillery-wagon'] = true } -Global.register( - { - player_last_position = player_last_position, - player_death_causes = player_death_causes, - }, - function(tbl) - player_last_position = tbl.player_last_position - player_death_causes = tbl.player_death_causes - end -) +local memory = { + player_last_position = {}, + player_death_causes = {} +} + +Global.register(memory, function(tbl) memory = tbl end) --- When the player first logs on, initialize their stats and pull their former playtime local function player_created(event) local index = event.player_index - player_last_position[index] = game.get_player(index).position - player_death_causes[index] = {} - ScoreTracker.changeForGlobal(player_count_name, 1) + memory.player_last_position[index] = game.get_player(index).position + memory.player_death_causes[index] = {} + ScoreTracker.change_for_global(player_count_name, 1) end local function get_cause_name(cause) @@ -75,77 +70,97 @@ local function get_cause_name(cause) return name end end - return 'No cause' + return 'unspecified' end local function player_died(event) local player_index = event.player_index local cause = get_cause_name(event.cause) - local causes = player_death_causes[player_index] + local causes = memory.player_death_causes[player_index] local cause_count = causes[cause] or 0 causes[cause] = cause_count + 1 - ScoreTracker.changeForPlayer(player_index, player_deaths_name, 1) + ScoreTracker.change_for_player(player_index, player_deaths_name, 1) if train_kill_causes[cause] then - ScoreTracker.changeForGlobal(kills_by_trains_name, 1) + ScoreTracker.change_for_global(kills_by_trains_name, 1) end end local function picked_up_item(event) local stack = event.item_stack if stack.name == 'coin' then - ScoreTracker.changeForPlayer(event.player_index, coins_earned_name, stack.count) + ScoreTracker.change_for_player(event.player_index, coins_earned_name, stack.count) end end local function player_mined_item(event) if event.entity.type == 'simple-entity' then -- Cheap check for rock, may have other side effects - ScoreTracker.changeForGlobal(rocks_smashed_name, 1) + ScoreTracker.change_for_global(rocks_smashed_name, 1) return end if event.entity.type == 'tree' then - ScoreTracker.changeForGlobal(trees_cut_name, 1) + ScoreTracker.change_for_global(trees_cut_down_name, 1) end end local function player_crafted_item(event) - ScoreTracker.changeForPlayer(event.player_index, player_items_crafted_name, event.item_stack.count) + ScoreTracker.change_for_player(event.player_index, player_items_crafted_name, event.item_stack.count) end local function player_console_chat(event) local player_index = event.player_index if player_index then - ScoreTracker.changeForPlayer(player_index, player_console_chats_name, 1) + ScoreTracker.change_for_player(player_index, player_console_chats_name, 1) end end local function player_built_entity() - ScoreTracker.changeForGlobal(built_by_players_name, 1) + ScoreTracker.change_for_global(built_by_players_name, 1) end local function robot_built_entity() - ScoreTracker.changeForGlobal(built_by_robots_name, 1) + ScoreTracker.change_for_global(built_by_robots_name, 1) end local function biter_kill_counter(event) if event.entity.force.name == 'enemy' then - ScoreTracker.changeForGlobal(aliens_killed_name, 1) + ScoreTracker.change_for_global(aliens_killed_name, 1) end end +local function rocket_launched(event) + local entity = event.rocket + + if not entity or not entity.valid or not entity.force == 'player' then + return + end + + local inventory = entity.get_inventory(defines.inventory.rocket) + if not inventory or not inventory.valid then + return + end + + local count = inventory.get_item_count('satellite') + if count == 0 then + return + end + + ScoreTracker.change_for_global(satellites_launched_name, 1) +end + local function tick() for _, p in pairs(game.connected_players) do if (p.afk_time < 30 or p.walking_state.walking) and p.vehicle == nil then local index = p.index - local last_pos = player_last_position[index] + local last_pos = memory.player_last_position[index] local pos = p.position local d_x = last_pos.x - pos.x local d_y = last_pos.y - pos.y - player_last_position[index] = pos - ScoreTracker.changeForPlayer(index, player_distance_walked_name, sqrt(d_x * d_x + d_y * d_y)) + memory.player_last_position[index] = pos + ScoreTracker.change_for_player(index, player_distance_walked_name, sqrt(d_x * d_x + d_y * d_y)) end end end @@ -160,79 +175,80 @@ Event.add(defines.events.on_console_chat, player_console_chat) Event.add(defines.events.on_built_entity, player_built_entity) Event.add(defines.events.on_robot_built_entity, robot_built_entity) Event.add(defines.events.on_entity_died, biter_kill_counter) +Event.add(defines.events.on_rocket_launched, rocket_launched) Event.on_nth_tick(62, tick) local Public = {} function Public.get_walk_distance(player_index) - return ScoreTracker.getForPlayer(player_index, player_distance_walked_name) + return ScoreTracker.get_for_player(player_index, player_distance_walked_name) end function Public.get_coin_earned(player_index) - return ScoreTracker.getForPlayer(player_index, coins_earned_name) + return ScoreTracker.get_for_player(player_index, coins_earned_name) end function Public.change_coin_earned(player_index, amount) - ScoreTracker.changeForPlayer(player_index, coins_earned_name, amount) + ScoreTracker.change_for_player(player_index, coins_earned_name, amount) end function Public.get_coin_spent(player_index) - return ScoreTracker.getForPlayer(player_index, coins_spent_name) + return ScoreTracker.get_for_player(player_index, coins_spent_name) end function Public.change_coin_spent(player_index, amount) - ScoreTracker.changeForPlayer(player_index, coins_spent_name, amount) - ScoreTracker.changeForGlobal(coins_spent_name, amount) + ScoreTracker.change_for_player(player_index, coins_spent_name, amount) + ScoreTracker.change_for_global(coins_spent_name, amount) end function Public.get_death_count(player_index) - return ScoreTracker.getForPlayer(player_index, player_deaths_name) + return ScoreTracker.get_for_player(player_index, player_deaths_name) end function Public.get_crafted_item(player_index) - return ScoreTracker.getForPlayer(player_index, player_items_crafted_name) + return ScoreTracker.get_for_player(player_index, player_items_crafted_name) end function Public.get_console_chat(player_index) - return ScoreTracker.getForPlayer(player_index, player_console_chats_name) + return ScoreTracker.get_for_player(player_index, player_console_chats_name) end -- Returns a dictionary of cause_name -> count function Public.get_all_death_causes_by_player(player_index) - return player_death_causes[player_index] or {} + return memory.player_death_causes[player_index] or {} end function Public.get_total_player_count() - return ScoreTracker.getForGlobal(player_count_name) + return ScoreTracker.get_for_global(player_count_name) end function Public.get_total_train_kills() - return ScoreTracker.getForGlobal(kills_by_trains_name) + return ScoreTracker.get_for_global(kills_by_trains_name) end function Public.get_total_player_trees_mined() - return ScoreTracker.getForGlobal(trees_cut_name) + return ScoreTracker.get_for_global(trees_cut_down_name) end function Public.get_total_player_rocks_mined() - return ScoreTracker.getForGlobal(rocks_smashed_name) + return ScoreTracker.get_for_global(rocks_smashed_name) end function Public.get_total_robot_built_entities() - return ScoreTracker.getForGlobal(built_by_robots_name) + return ScoreTracker.get_for_global(built_by_robots_name) end function Public.get_total_player_built_entities() - return ScoreTracker.getForGlobal(built_by_players_name) + return ScoreTracker.get_for_global(built_by_players_name) end function Public.get_total_biter_kills() - return ScoreTracker.getForGlobal(aliens_killed_name) + return ScoreTracker.get_for_global(aliens_killed_name) end function Public.get_total_coins_spent() - return ScoreTracker.getForGlobal(coins_spent_name) + return ScoreTracker.get_for_global(coins_spent_name) end return Public diff --git a/features/redmew_settings_sync.lua b/features/redmew_settings_sync.lua index 6b6a82d2..a1653fbd 100644 --- a/features/redmew_settings_sync.lua +++ b/features/redmew_settings_sync.lua @@ -35,18 +35,10 @@ local memory = { locked = false, } -local do_sync_settings_to_server -- token Global.register(memory, function (tbl) memory = tbl end) -local function schedule_sync_to_server(player_index) - set_timeout_in_ticks(1, do_sync_settings_to_server, { - player_index = player_index - }) - memory.sync_scheduled[player_index] = true -end - -do_sync_settings_to_server = Token.register(function(params) +local do_sync_settings_to_server = Token.register(function(params) local player_index = params.player_index; local player = game.get_player(player_index) if not player or not player.valid then @@ -67,6 +59,13 @@ do_sync_settings_to_server = Token.register(function(params) }) end) +local function schedule_sync_to_server(player_index) + set_timeout_in_ticks(1, do_sync_settings_to_server, { + player_index = player_index + }) + memory.sync_scheduled[player_index] = true +end + local function setting_set(event) local player_index = event.player_index if memory.locked or memory.sync_scheduled[player_index] then diff --git a/locale/en/redmew_features.cfg b/locale/en/redmew_features.cfg index be78890c..251a9e2e 100644 --- a/locale/en/redmew_features.cfg +++ b/locale/en/redmew_features.cfg @@ -119,3 +119,18 @@ load_bars=Attempting to load bars from server... delete_bars=Saved data has been removed from the server. incompatible_item=Incompatible item found in saved date and will not be loaded: __1__ +[player_stats] +rocks_smashed=Rocks smashed +trees_cut_down=Trees cut down +player_count=Total players +kills_by_trains=Kills by trains +built_by_players=Built by hand +built_by_robots=Built by robots +aliens_killed=Aliens liberated +coins_earned=Coins earned +coins_spent=Coins spent +player_deaths=Player deaths +player_console_chats=Player console chats +player_items_crafted=Player items crafted +player_distance_walked=Distance walked +satellites_launched=satellites launched diff --git a/map_gen/shared/hail_hydra.lua b/map_gen/shared/hail_hydra.lua index d8ef70a1..29481978 100644 --- a/map_gen/shared/hail_hydra.lua +++ b/map_gen/shared/hail_hydra.lua @@ -4,11 +4,11 @@ local CreateParticles = require 'features.create_particles' local Token = require 'utils.token' local Global = require 'utils.global' local table = require 'utils.table' - local random = math.random local floor = math.floor local ceil = math.ceil local pairs = pairs +local type = type local clear_table = table.clear_table local compound = defines.command.compound local logical_or = defines.compound_command.logical_or diff --git a/utils/score_tracker.lua b/utils/score_tracker.lua index 62fd7024..d8794ae5 100644 --- a/utils/score_tracker.lua +++ b/utils/score_tracker.lua @@ -20,12 +20,14 @@ Public.events = { -- old_value = old_value -- new_value = new_value -- player_index = player_index + -- value_changed = value_changed -- } on_player_score_changed = Event.generate_event_name('on_player_score_changed'), -- Event { -- score_name = score_name -- old_value = old_value -- new_value = new_value + -- value_changed = value_changed -- } on_global_score_changed = Event.generate_event_name('on_global_score_changed'), } @@ -62,7 +64,7 @@ end ---@param player_index number ---@param score_name string ---@param value number|nil number to subtract or add -function Public.changeForPlayer(player_index, score_name, value) +function Public.change_for_player(player_index, score_name, value) local setting = score_metadata[score_name] if not setting then if _DEBUG then @@ -85,7 +87,8 @@ function Public.changeForPlayer(player_index, score_name, value) score_name = score_name, old_value = old_value, new_value = new_value, - player_index = player_index + player_index = player_index, + value_changed = old_value ~= new_value }) end @@ -93,7 +96,7 @@ end --- ---@param score_name string ---@param value number|nil number to subtract or add -function Public.changeForGlobal(score_name, value) +function Public.change_for_global(score_name, value) local setting = score_metadata[score_name] if not setting then if _DEBUG then @@ -109,7 +112,8 @@ function Public.changeForGlobal(score_name, value) raise_event(Public.events.on_global_score_changed, { score_name = score_name, old_value = old_value, - new_value = new_value + new_value = new_value, + value_changed = old_value ~= new_value }) end @@ -117,7 +121,7 @@ end --- ---@param player_index number ---@param score_name string -function Public.getForPlayer(player_index, score_name) +function Public.get_for_player(player_index, score_name) local setting = score_metadata[score_name] if not setting then return nil @@ -134,7 +138,7 @@ end ---Returns the value of the game score. --- ---@param score_name string -function Public.getForGlobal(score_name) +function Public.get_for_global(score_name) local setting = score_metadata[score_name] if not setting then return 0