Merge branch 'feature/damage-popups' into dev

This commit is contained in:
Cooldude2606
2019-03-22 23:34:11 +00:00
8 changed files with 65 additions and 3 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -1,3 +1,7 @@
[chat-popup]
message=__1__: __2__
ping=You have been mentioned in chat by __1__.
ping=You have been mentioned in chat by __1__.
[damage-popup]
player-health=__1__
player-damage=__1__

View File

@@ -1,3 +1,7 @@
[chat-popup]
message=__1__: __2__
ping=You have been mentioned in chat by __1__.
ping=You have been mentioned in chat by __1__.
[damage-popup]
player-health=__1__
player-damage=__1__

View File

@@ -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+", "")

View File

@@ -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)