From 951dd5d1f592e8a34a4b14748444e4c71124e14d Mon Sep 17 00:00:00 2001 From: Ajick Date: Mon, 12 Jun 2023 00:03:46 +0500 Subject: [PATCH] fix: Check all parameters in events in Statistics module. --- info.json | 2 +- locale/ru/strings.cfg | 2 +- scripts/statistics.lua | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/info.json b/info.json index fbbe429..f228223 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "Fed1sServerMod", - "version": "1.1.1", + "version": "1.1.2", "title": "Fed1sServerMod", "author": "danbka33", "contact": "", diff --git a/locale/ru/strings.cfg b/locale/ru/strings.cfg index 49d11ef..fda0140 100644 --- a/locale/ru/strings.cfg +++ b/locale/ru/strings.cfg @@ -116,7 +116,7 @@ crafters=Топ Крафтеров crafters-info=Количество скрафченных в кармане предметов. repairemans=Топ Ремонтников repairemans-info=Количество восстановленных очков здоровья у объектов. -wariors=Топ войнов +wariors=Топ Войнов wariors-info=Количество убитых местных жителей. tree_haters=Топ Ненавистников деревьев tree_haters-info=Количество убитых деревьев. diff --git a/scripts/statistics.lua b/scripts/statistics.lua index 3921572..ee55ac3 100755 --- a/scripts/statistics.lua +++ b/scripts/statistics.lua @@ -557,7 +557,7 @@ end function Statistics.on_player_died(event) local deaths = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.deaths) - if event.cause then + if event.cause and event.cause.valid then if event.cause.name == "character" then local killed = Statistics.get_player_raw_data_type(event.cause.player.index, Statistics.types.killed) @@ -586,6 +586,10 @@ function Statistics.on_player_died(event) end function Statistics.on_built_entity(event) + if not event.created_entity or not event.created_entity.valid then + return + end + local builded = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.builded) if event.created_entity.valid then @@ -600,11 +604,19 @@ function Statistics.on_built_entity(event) end function Statistics.on_player_built_tile(event) + if not event.tile or not event.tile.valid then + return + end + local builded = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.builded) builded[event.tile.name] = (builded[event.tile.name] or 0) + #event.tiles end function Statistics.on_player_repaired_entity(event) + if not event.entity or not event.entity.valid then + return + end + -- Counting not precisely, but tssss! local repaired = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.repaired) @@ -617,11 +629,15 @@ function Statistics.on_player_repaired_entity(event) end function Statistics.on_entity_died(event) - if not event.cause or event.cause.name ~= "character" then + if not event.entity or not event.entity.valid or event.entity.name == "character" then return end - if event.entity.name == "character" then + if not event.cause or not event.cause.valid or event.cause.name ~= "character" then + return + end + + if not event.damage_type or not event.damage_type.valid then return end @@ -640,11 +656,19 @@ function Statistics.on_entity_died(event) end function Statistics.on_player_mined_item(event) + if not event.item_stack then + return + end + local mined = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.mined) mined[event.item_stack.name] = (mined[event.item_stack.name] or 0) + event.item_stack.count end function Statistics.on_player_crafted_item(event) + if not event.item_stack then + return + end + local crafted = Statistics.get_player_raw_data_type(event.player_index, Statistics.types.crafted) crafted[event.item_stack.name] = (crafted[event.item_stack.name] or 0) + event.item_stack.count end