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..bee5b53c --- /dev/null +++ b/config/popup_messages.lua @@ -0,0 +1,8 @@ +--- 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 + 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/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 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..4233ac1d --- /dev/null +++ b/modules/addons/damage-popups.lua @@ -0,0 +1,40 @@ +--- 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 = 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} + + -- 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 + 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 + + -- 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 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