1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/modules/custom_death_messages.lua

69 lines
3.0 KiB
Lua
Raw Normal View History

2019-02-05 09:42:45 +02:00
-- prints death messages to all forces with custom texts -- by mewmew
local event = require 'utils.event'
local math_random = math.random
2019-02-14 16:44:12 +02:00
local message_color = {r=0.9, g=0.9, b=0.9}
2019-02-05 09:42:45 +02:00
local messages = {
["small-biter"] = {" was nibbled to death.", " should not have played with the biters.", " is biter food."},
["medium-biter"] = {" lost their leg to a hungry biter.", " is biter food.", " was a tasty biter treat."},
2019-02-05 09:42:45 +02:00
["big-biter"] = {" had their head chomped off.", " is biter food.", " was a tasty biter treat."},
["behemoth-biter"] = {" was devoured by a behemoth biter.", " was crushed by a behemoth biter.", " is biter food."},
["small-spitter"] = {" melted away by acid spit!", " couldn't dodge the spit in time."},
["medium-spitter"] = {" melted away by acid spit!", " couldn't dodge the spit in time."},
["big-spitter"] = {" melted away by acid spit!", " couldn't dodge the spit in time.", " got blasted away by a spitter."},
["behemoth-spitter"] = {" melted away by acid spit!", " couldn't dodge the spit in time.", " got blasted away by a spitter."},
["small-worm-turret"] = {" melted away by acid spit!", " couldn't dodge the spit in time."},
["medium-worm-turret"] = {" melted away by acid spit!", " couldn't dodge the spit in time.", " got blasted away by a medium worm turret."},
["big-worm-turret"] = {" melted away by acid spit!", " couldn't dodge the spit in time.", " got blasted away by a big worm turret."},
["gun-turret"] = {" was mowed down by a barrage from a gun turret."},
2019-02-11 02:29:20 +02:00
["laser-turret"] = {" was fatally enlightened by a laser beam."},
["cargo-wagon"] = {" was flattened.", " was crushed."},
["locomotive"] = {" was flattened.", " was crushed."}
2019-02-05 09:42:45 +02:00
}
local function on_player_died(event)
local player = game.players[event.player_index]
2019-02-11 02:29:20 +02:00
local tag = ""
if player.tag then
if player.tag ~= "" then tag = " " .. player.tag end
end
if event.cause then
local cause = event.cause
if not cause.name then
2019-10-15 05:56:30 +02:00
game.print(player.name .. tag .. " was killed.", message_color)
2019-02-05 09:42:45 +02:00
return
end
2019-02-11 02:29:20 +02:00
if messages[cause.name] then
game.print(player.name .. messages[cause.name][math.random(1, #messages[cause.name])], message_color)
2019-02-05 09:42:45 +02:00
return
end
if cause.name == "character" then
2019-04-15 20:19:32 +02:00
if not player.name then return end
if not cause.player.name then return end
2019-02-11 02:29:20 +02:00
game.print(player.name .. tag .. " was killed by " .. cause.player.name " " .. cause.player.tag .. ".", message_color)
2019-02-05 09:42:45 +02:00
return
end
2019-02-11 02:29:20 +02:00
if cause.name == "tank" then
local driver = cause.get_driver()
if driver.player then
game.print(player.name .. tag .. " was killed by " .. driver.player.name .. " " .. player.tag .. ".", message_color)
return
2019-02-05 09:42:45 +02:00
end
end
2019-02-11 02:29:20 +02:00
game.print(player.name .. tag .. " was killed by " .. cause.name .. ".", message_color)
2019-02-05 09:42:45 +02:00
return
end
2019-02-05 16:27:28 +02:00
for _, p in pairs(game.connected_players) do
2019-02-11 02:29:20 +02:00
if player.force.name ~= p.force.name then
p.print(player.name .. tag .. " was killed.", message_color)
2019-02-05 16:27:28 +02:00
end
2019-02-05 09:42:45 +02:00
end
end
event.add(defines.events.on_player_died, on_player_died)