diff --git a/modules/ChatPopup/control.lua b/modules/ChatPopup/control.lua new file mode 100644 index 00000000..798af9a9 --- /dev/null +++ b/modules/ChatPopup/control.lua @@ -0,0 +1,56 @@ +--- Creates flying text above player when they send a message. +-- @module ChatPopup@4.0.0 +-- @author badgamernl +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE +-- @alais ChatPopup + +-- Module Require +local Game = require('FactorioStdLib.Game@^0.8.0') +local Color = require('FactorioStdLib.Color@^0.8.0') + +local ChatPopup = {} + +function ChatPopup.sendFlyingText(player, text) + local _player = Game.get_player(player) + if not _player then return end + -- Split long text in chunks + local chunkSize = 40 + local chunks = {} + for i=1, #text, chunkSize do + chunks[#chunks+1] = text:sub(i,i+chunkSize - 1) + end + -- Itterate over text chunks and create them as floating text centered above the player + -- Disabled false centering because of not being able to disable scaling: (1 / 7.9 * #value) + for i,value in ipairs(chunks) do + _player.surface.create_entity{ + name="flying-text", + color=_player.chat_color, + text=value, + position={_player.position.x, _player.position.y-(2 - (1 * i))} + } + end +end + +Event.register(defines.events.on_console_chat, function(event) + local player = game.players[event.player_index] + if not player then return end + if not event.message then return end + + -- Send message player send to player itself + local message = player.name .. ': ' .. event.message + ChatPopup.sendFlyingText(player, message) + + -- parse message for players and if it includes player, send him a notification that he has been mentioned in the chat + local player_message = event.message:lower():gsub("%s+", "") + + for i,_player in ipairs(game.connected_players) do + if _player.index ~= player.index then + if player_message:match(_player.name:lower()) then + ChatPopup.sendFlyingText(_player, 'You\'ve been mentioned by: ' ..player.name .. ' in chat!') + end + end + end + +end) + +return ChatPopup \ No newline at end of file diff --git a/modules/ChatPopup/softmod.json b/modules/ChatPopup/softmod.json new file mode 100644 index 00000000..63950b1a --- /dev/null +++ b/modules/ChatPopup/softmod.json @@ -0,0 +1,15 @@ +{ + "name": "ChatPopup", + "version": "4.0.0", + "type": "Module", + "description": "Creates flying text above player when they send a message.", + "location": "", + "keywords": ["Chat", "Popup", "Mention", "Floating", "Text"], + "author": "badgamernl", + "contact": "badgamernl@gmail.com", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "dependencies": { + "FactorioStdLib.Game": "0.8.0", + "FactorioStdLib.Color": "^0.8.0" + } +} diff --git a/modules/DamagePopup/control.lua b/modules/DamagePopup/control.lua new file mode 100644 index 00000000..0d58802a --- /dev/null +++ b/modules/DamagePopup/control.lua @@ -0,0 +1,45 @@ +--- When a entibty is damaged y a player it will show how much damage you've dealth, When a player gets attacked by a entity it will popup the player's health in color. +-- @module DamagePopup@4.0.0 +-- @author badgamernl +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE +-- @alais DamagePopup + +-- Module Require +local Color = require('FactorioStdLib.Color@^0.8.0') + +local DamagePopup = {} + +Event.register(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 pre_attack_health = health + damage -- Didn't use it after all, maybe usefull later + + local color = defines.textcolor.crit + + if entity.name == 'player' then + if health > 100 then + if health > 200 then + color = defines.textcolor.low + else + color = defines.textcolor.med + end + end + entity.surface.create_entity{ + name="flying-text", + color=color, + text=math.floor(health), + position=entity.position + } + elseif cause and cause.name == 'player' then + entity.surface.create_entity{ + name="flying-text", + color=defines.textcolor.med, + text='-'..damage, + position=entity.position + } + end +end) + +return DamagePopup \ No newline at end of file diff --git a/modules/DamagePopup/softmod.json b/modules/DamagePopup/softmod.json new file mode 100644 index 00000000..e0a482db --- /dev/null +++ b/modules/DamagePopup/softmod.json @@ -0,0 +1,14 @@ +{ + "name": "DamagePopup", + "version": "4.0.0", + "type": "Module", + "description": "When a entibty is damaged y a player it will show how much damage you've dealth, When a player gets attacked by a entity it will popup the player's health in color.", + "location": "", + "keywords": ["Damage", "Popup", "Floating", "Text"], + "author": "badgamernl", + "contact": "badgamernl@gmail.com", + "license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE", + "dependencies": { + "FactorioStdLib.Color": "^0.8.0" + } +} diff --git a/modules/index.lua b/modules/index.lua index d9548eaf..84e0b35f 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -47,5 +47,7 @@ return { ['ExpGamingAdmin.Jail@4.0.0']='./modules/ExpGamingAdmin/Jail', ['ExpGamingAdmin.Commands@4.0.0']='./modules/ExpGamingAdmin/Commands', ['ExpGamingAdmin.Ban@4.0.0']='./modules/ExpGamingAdmin/Ban', + ['ChatPopup@4.0.0']='./modules/ChatPopup', + ['DamagePopup@4.0.0']='./modules/DamagePopup', ['ExpGamingCore.Group@4.0.0']='./modules/ExpGamingCore/Group', } \ No newline at end of file