From f51fcce5097554d5df18310ac4de2582490cbaf3 Mon Sep 17 00:00:00 2001 From: grilledham Date: Fri, 29 Jun 2018 00:44:20 +0100 Subject: [PATCH] more rewrite --- player_list.lua | 12 +++++++++--- player_stats.lua | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/player_list.lua b/player_list.lua index a2493771..eb1fcf30 100644 --- a/player_list.lua +++ b/player_list.lua @@ -287,7 +287,7 @@ local column_builders = { create_data = function(player) local index = player.index return { - fish_earnt = PlayerStats.get_fish_earned(index), + fish_earned = PlayerStats.get_fish_earned(index), fish_spent = PlayerStats.get_fish_spent(index) } end, @@ -300,7 +300,13 @@ local column_builders = { end end, draw_heading = function(parent) - local label = parent.add {type = 'label', name = fish_heading_name, caption = 'Fish'} + local label = + parent.add { + type = 'label', + name = fish_heading_name, + caption = 'Fish', + tooltip = 'Fish earned / spent.' + } local label_style = label.style apply_heading_style(label_style) label_style.width = 80 @@ -308,7 +314,7 @@ local column_builders = { return label end, draw_cell = function(parent, cell_data) - local text = table.concat({cell_data.fish_earnt, '/', cell_data.fish_spent}) + local text = table.concat({cell_data.fish_earned, '/', cell_data.fish_spent}) local label = parent.add {type = 'label', name = fish_cell_name, caption = text} local label_style = label.style diff --git a/player_stats.lua b/player_stats.lua index 03e823e7..480b7b68 100644 --- a/player_stats.lua +++ b/player_stats.lua @@ -66,6 +66,15 @@ local function player_died(event) causes[cause] = cause_count + 1 end +local function picked_up_item(event) + local stack = event.item_stack + + if stack.name == 'raw-fish' then + local player_index = event.player_index + player_fish_earned[player_index] = player_fish_earned[player_index] + stack.count + end +end + local function tick() for _, p in ipairs(game.connected_players) do if (p.afk_time < 30 or p.walking_state.walking) and p.vehicle == nil then @@ -84,6 +93,7 @@ end Event.add(defines.events.on_player_created, player_created) Event.add(defines.events.on_player_died, player_died) +Event.add(defines.events.on_picked_up_item, picked_up_item) Event.on_nth_tick(62, tick) local Public = {}