From 29c542f391bd33234fe29a4e17bdb664161964a2 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 23:02:10 +0000 Subject: [PATCH 1/3] 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 From 40de1fd59bd7b724059f1026691786b500d62d4d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 23:03:02 +0000 Subject: [PATCH 2/3] Fixed Locale --- locale/en/addons.cfg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/locale/en/addons.cfg b/locale/en/addons.cfg index 409e71a0..a4bb08a6 100644 --- a/locale/en/addons.cfg +++ b/locale/en/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 From 44880ffe87ae409c299722c8d1aba6ea0a321ef6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 23:34:02 +0000 Subject: [PATCH 3/3] Added some varience to the location --- config/popup_messages.lua | 3 ++- modules/addons/damage-popups.lua | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/config/popup_messages.lua b/config/popup_messages.lua index a733c30a..bee5b53c 100644 --- a/config/popup_messages.lua +++ b/config/popup_messages.lua @@ -3,5 +3,6 @@ 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 + show_player_health=true, -- weather to show player health when attacked + damage_location_variance=0.8 -- how close to the eade of an entity the popups will appear } \ No newline at end of file diff --git a/modules/addons/damage-popups.lua b/modules/addons/damage-popups.lua index bb365ac9..4233ac1d 100644 --- a/modules/addons/damage-popups.lua +++ b/modules/addons/damage-popups.lua @@ -7,19 +7,34 @@ 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 damage = math.floor(event.original_damage_amount) + local health = math.floor(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 + -- Gets the location of the text + local size = entity.get_radius() + if size < 1 then size = 1 end + local r = (math.random()-0.5)*size*config.damage_location_variance + local p = entity.position + local position = {x=p.x+r,y=p.y-size} + + -- Sets the message + local message if entity.name == 'player' and config.show_player_health then - Game.print_player_floating_text(entity.index,{'damage-popup.player-health',health},text_colour) + message = {'damage-popup.player-health',health} + elseif entity.name ~= 'player' and cause and cause.name == 'player' and config.show_player_damage then + message = {'damage-popup.player-damage',damage} 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) + -- Outputs the message as floating text + if message then + Game.print_floating_text( + entity.surface, + position, + message, + text_colour + ) end end) \ No newline at end of file