From 4cfe885df6d537e3f34d955e5220daf1af2ac158 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Fri, 10 Jul 2020 16:08:50 +0200 Subject: [PATCH] minor changes --- antigrief.lua | 166 +++++++++++++++++++++++-- comfy_panel/admin.lua | 4 + comfy_panel/player_list.lua | 18 ++- locale/en/mtn_fortress_v3.cfg | 4 +- maps/fish_defender/commands.lua | 2 +- maps/mountain_fortress_v3/entities.lua | 9 ++ maps/mountain_fortress_v3/main.lua | 1 + 7 files changed, 187 insertions(+), 17 deletions(-) diff --git a/antigrief.lua b/antigrief.lua index 933b4b7f..aae79023 100644 --- a/antigrief.lua +++ b/antigrief.lua @@ -6,10 +6,14 @@ local Event = require 'utils.event' local session = require 'utils.session_data' local Global = require 'utils.global' local Utils = require 'utils.core' +local Color = require 'utils.color_presets' local Server = require 'utils.server' local Public = {} local match = string.match +local capsule_bomb_threshold = 8 + +local format = string.format local this = { landfill_history = {}, @@ -19,8 +23,12 @@ local this = { corpse_history = {}, cancel_crafting_history = {}, whitelist_types = {}, + players_warned = {}, log_tree_harvest = false, - do_not_check_trusted = true + do_not_check_trusted = true, + protect_entities = false, + enable_autokick = true, + enable_autoban = false } local blacklisted_types = { @@ -36,6 +44,7 @@ local blacklisted_types = { } local ammo_names = { + ['artillery-targeting-remote'] = true, ['poison-capsule'] = true, ['cluster-grenade'] = true, ['grenade'] = true, @@ -44,6 +53,12 @@ local ammo_names = { ['rocket'] = true } +local not_protected = { + ['wall'] = true, + ['container'] = true, + ['logistic-container'] = true +} + Global.register( this, function(t) @@ -55,8 +70,47 @@ local function increment(t, k, v) t[k][#t[k] + 1] = (v or 1) end -local function damage_player(player) +local function get_entities(item_name, entities) + local set = {} + for i = 1, #entities do + local e = entities[i] + local name = e.name + + if name ~= item_name and name ~= 'entity-ghost' then + local count = set[name] + if count then + set[name] = count + 1 + else + set[name] = 1 + end + end + end + + local list = {} + local i = 1 + for k, v in pairs(set) do + list[i] = v + i = i + 1 + list[i] = ' ' + i = i + 1 + list[i] = k + i = i + 1 + list[i] = ', ' + i = i + 1 + end + list[i - 1] = nil + + return table.concat(list) +end + +local function damage_player(player, kill) + local msg = ' tried to destroy our base, but it backfired!' if player.character then + if kill then + player.character.die('enemy') + game.print(player.name .. msg, Color.yellow) + return + end player.character.health = player.character.health - math.random(50, 100) player.character.surface.create_entity({name = 'water-splash', position = player.position}) local messages = { @@ -64,10 +118,10 @@ local function damage_player(player) 'Just a fleshwound.', 'Better keep those hands to yourself or you might loose them.' } - player.print(messages[math.random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0}) + player.print(messages[math.random(1, #messages)], Color.yellow) if player.character.health <= 0 then player.character.die('enemy') - game.print(player.name .. ' should have obeyed the law.', {r = 0.75, g = 0.0, b = 0.0}) + game.print(player.name .. msg, Color.yellow) return end end @@ -197,8 +251,6 @@ local function on_player_used_capsule(event) if trusted[player.name] and this.do_not_check_trusted then return end - local position = event.position - local item = event.item if not item then @@ -207,7 +259,58 @@ local function on_player_used_capsule(event) local name = item.name + local position = event.position + local x, y = position.x, position.y + local surface = player.surface + if ammo_names[name] then + if + surface.count_entities_filtered({force = 'enemy', area = {{x - 10, y - 10}, {x + 10, y + 10}}, limit = 1}) > + 0 + then + return + end + + local count = 0 + local entities = + player.surface.find_entities_filtered {force = player.force, area = {{x - 5, y - 5}, {x + 5, y + 5}}} + + for i = 1, #entities do + local e = entities[i] + local entity_name = e.name + if entity_name ~= name and entity_name ~= 'entity-ghost' and not blacklisted_types[e.type] then + count = count + 1 + end + end + + if count <= capsule_bomb_threshold then + return + end + + local msg = format(player.name .. ' damaged: %s with: %s', get_entities(name, entities), name) + + if this.players_warned[event.player_index] == 2 then + if this.enable_autoban then + Server.ban_sync( + player.name, + format( + 'Damaged: %s with: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness', + get_entities(name, entities), + name + ), + '