From 29c542f391bd33234fe29a4e17bdb664161964a2 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 23:02:10 +0000 Subject: [PATCH] Added Damage Popups --- config/file_loader.lua | 1 + config/popup_messages.lua | 7 ++++++ modules/addons/addons.cfg | 6 ++++- modules/addons/chat-popups.lua | 7 +++++- modules/addons/damage-popups.lua | 25 +++++++++++++++++++ .../{ => DONE}/DamagePopup/control.lua | 0 .../{ => DONE}/DamagePopup/softmod.json | 0 7 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 config/popup_messages.lua create mode 100644 modules/addons/damage-popups.lua rename old/modules/{ => DONE}/DamagePopup/control.lua (100%) rename old/modules/{ => DONE}/DamagePopup/softmod.json (100%) diff --git a/config/file_loader.lua b/config/file_loader.lua index 8eb1c26a..79f42801 100644 --- a/config/file_loader.lua +++ b/config/file_loader.lua @@ -16,6 +16,7 @@ return { 'modules.commands.help', -- QoL Addons 'modules.addons.chat-popups', + 'modules.addons.damage-popups', -- Config Files 'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins 'config.permission_groups', -- loads some predefined permission groups diff --git a/config/popup_messages.lua b/config/popup_messages.lua new file mode 100644 index 00000000..a733c30a --- /dev/null +++ b/config/popup_messages.lua @@ -0,0 +1,7 @@ +--- A combination of config settings for different popup values like chat and damage +return { + show_player_messages=true, -- weather a message in chat will make a popup above them + show_player_mentions=true, -- weather a mentioned player will have a popup when mentioned in chat + show_player_damage=true, -- weather to show damage done by players + show_player_health=true -- weather to show player health when attacked +} \ No newline at end of file diff --git a/modules/addons/addons.cfg b/modules/addons/addons.cfg index 409e71a0..a4bb08a6 100644 --- a/modules/addons/addons.cfg +++ b/modules/addons/addons.cfg @@ -1,3 +1,7 @@ [chat-popup] message=__1__: __2__ -ping=You have been mentioned in chat by __1__. \ No newline at end of file +ping=You have been mentioned in chat by __1__. + +[damage-popup] +player-health=__1__ +player-damage=__1__ \ No newline at end of file diff --git a/modules/addons/chat-popups.lua b/modules/addons/chat-popups.lua index 3a0592d3..7c75dbf7 100644 --- a/modules/addons/chat-popups.lua +++ b/modules/addons/chat-popups.lua @@ -2,6 +2,7 @@ -- also displays a ping above users who are named in the message local Game = require 'utils.game' local Event = require 'utils.event' +local config = require 'config.popup_messages' local send_text = Game.print_player_floating_text -- (player_index, text, color) @@ -13,7 +14,11 @@ Event.add(defines.events.on_console_chat,function(event) if not event.message then return end -- Sends the message as text above them - send_text(player.index,{'chat-popup.message',player.name,event.message},player.chat_color) + if config.show_player_messages then + send_text(player.index,{'chat-popup.message',player.name,event.message},player.chat_color) + end + + if not config.show_player_mentions then return end -- Makes lower and removes white space from the message local search_string = event.message:lower():gsub("%s+", "") diff --git a/modules/addons/damage-popups.lua b/modules/addons/damage-popups.lua new file mode 100644 index 00000000..bb365ac9 --- /dev/null +++ b/modules/addons/damage-popups.lua @@ -0,0 +1,25 @@ +--- Displays the amount of dmg that is done by players to entities +-- also shows player health when a player is attacked +local Game = require 'utils.game' +local Event = require 'utils.event' +local config = require 'config.popup_messages' + +Event.add(defines.events.on_entity_damaged, function(event) + local entity = event.entity + local cause = event.cause + local damage = event.original_damage_amount + local health = entity.health + local health_percentage = entity.get_health_ratio() + local text_colour = {r=1-health_percentage,g=health_percentage,b=0} + + -- Checks if its a player and show player health is enabled + if entity.name == 'player' and config.show_player_health then + Game.print_player_floating_text(entity.index,{'damage-popup.player-health',health},text_colour) + end + + -- Checks if the source was a player and the entity was not a player + if entity.name ~= 'player' and cause and cause.name == 'player' and config.show_player_damage then + Game.print_floating_text(entity.surface,entity.position,{'damage-popup.player-damage',damage},text_colour) + end + +end) \ No newline at end of file diff --git a/old/modules/DamagePopup/control.lua b/old/modules/DONE/DamagePopup/control.lua similarity index 100% rename from old/modules/DamagePopup/control.lua rename to old/modules/DONE/DamagePopup/control.lua diff --git a/old/modules/DamagePopup/softmod.json b/old/modules/DONE/DamagePopup/softmod.json similarity index 100% rename from old/modules/DamagePopup/softmod.json rename to old/modules/DONE/DamagePopup/softmod.json