Skip to content

Commit

Permalink
fix: Check all parameters in events in Statistics module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajick2013 committed Jun 11, 2023
1 parent 0cb8dac commit 951dd5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Fed1sServerMod",
"version": "1.1.1",
"version": "1.1.2",
"title": "Fed1sServerMod",
"author": "danbka33",
"contact": "",
Expand Down
2 changes: 1 addition & 1 deletion locale/ru/strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ crafters=Топ Крафтеров
crafters-info=Количество скрафченных в кармане предметов.
repairemans=Топ Ремонтников
repairemans-info=Количество восстановленных очков здоровья у объектов.
wariors=Топ войнов
wariors=Топ Войнов
wariors-info=Количество убитых местных жителей.
tree_haters=Топ Ненавистников деревьев
tree_haters-info=Количество убитых деревьев.
Expand Down
30 changes: 27 additions & 3 deletions scripts/statistics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 951dd5d

Please sign in to comment.