Dev modules, Popup additions (#82)

* Chat/Mention popup

* Damage Popup

* fixed config dep
This commit is contained in:
badgamernl
2018-09-21 22:33:59 +02:00
committed by Cooldude2606
parent b947c80667
commit aac04e4562
5 changed files with 132 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,15 @@
{
"name": "ChatPopup",
"version": "4.0.0",
"type": "Module",
"description": "Creates flying text above player when they send a message.",
"location": "<blank>",
"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"
}
}

View File

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

View File

@@ -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": "<blank>",
"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"
}
}

View File

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