mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Added Damage Popups
This commit is contained in:
@@ -16,6 +16,7 @@ return {
|
|||||||
'modules.commands.help',
|
'modules.commands.help',
|
||||||
-- QoL Addons
|
-- QoL Addons
|
||||||
'modules.addons.chat-popups',
|
'modules.addons.chat-popups',
|
||||||
|
'modules.addons.damage-popups',
|
||||||
-- Config Files
|
-- Config Files
|
||||||
'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins
|
'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins
|
||||||
'config.permission_groups', -- loads some predefined permission groups
|
'config.permission_groups', -- loads some predefined permission groups
|
||||||
|
|||||||
7
config/popup_messages.lua
Normal file
7
config/popup_messages.lua
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
[chat-popup]
|
[chat-popup]
|
||||||
message=__1__: __2__
|
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__
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
-- also displays a ping above users who are named in the message
|
-- also displays a ping above users who are named in the message
|
||||||
local Game = require 'utils.game'
|
local Game = require 'utils.game'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
|
local config = require 'config.popup_messages'
|
||||||
|
|
||||||
local send_text = Game.print_player_floating_text -- (player_index, text, color)
|
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
|
if not event.message then return end
|
||||||
|
|
||||||
-- Sends the message as text above them
|
-- 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
|
-- Makes lower and removes white space from the message
|
||||||
local search_string = event.message:lower():gsub("%s+", "")
|
local search_string = event.message:lower():gsub("%s+", "")
|
||||||
|
|||||||
25
modules/addons/damage-popups.lua
Normal file
25
modules/addons/damage-popups.lua
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user