From 44880ffe87ae409c299722c8d1aba6ea0a321ef6 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 23:34:02 +0000 Subject: [PATCH] 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