mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Added Damage Popups
This commit is contained in:
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