1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Merge pull request #667 from grilledham/corpse_looting_message

Corpse looting message
This commit is contained in:
Matthew 2019-01-21 11:04:48 -05:00 committed by GitHub
commit e88c72f972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 217 additions and 162 deletions

View File

@ -3,6 +3,8 @@ local Global = require 'utils.global'
local Task = require 'utils.task' local Task = require 'utils.task'
local Token = require 'utils.token' local Token = require 'utils.token'
local Game = require 'utils.game' local Game = require 'utils.game'
local Server = require 'features.server'
local Color = require 'resources.color_presets'
local player_corpses = {} local player_corpses = {}
@ -43,7 +45,11 @@ local function player_died(event)
local text = player.name .. "'s corpse" local text = player.name .. "'s corpse"
local position = entity.position local position = entity.position
local tag = player.force.add_chart_tag(player.surface, {icon = {type = 'item', name = 'power-armor-mk2'}, position = position, text = text}) local tag =
player.force.add_chart_tag(
player.surface,
{icon = {type = 'item', name = 'power-armor-mk2'}, position = position, text = text}
)
if not tag then if not tag then
return return
@ -85,21 +91,67 @@ local corpse_util_mined_entity =
local function mined_entity(event) local function mined_entity(event)
local entity = event.entity local entity = event.entity
if entity and entity.valid and entity.name == 'character-corpse' then if not entity or not entity.valid or entity.name ~= 'character-corpse' then
-- The corpse may be mined but not removed (if player doesn't have inventory space) return
-- so we wait one tick to see if the corpse is gone. end
Task.set_timeout_in_ticks(
1, -- The corpse may be mined but not removed (if player doesn't have inventory space)
corpse_util_mined_entity, -- so we wait one tick to see if the corpse is gone.
{ Task.set_timeout_in_ticks(
entity = entity, 1,
player_index = entity.character_corpse_player_index, corpse_util_mined_entity,
tick = entity.character_corpse_tick_of_death {
} entity = entity,
) player_index = entity.character_corpse_player_index,
tick = entity.character_corpse_tick_of_death
}
)
local player_index = event.player_index
local corpse_owner_index = entity.character_corpse_player_index
if player_index == corpse_owner_index then
return
end
local player = Game.get_player_by_index(player_index)
local corpse_owner = Game.get_player_by_index(corpse_owner_index)
if player and corpse_owner then
local message = table.concat {'## - ', player.name, ' has looted ', corpse_owner.name, "'s corpse"}
game.print(message, Color.yellow)
log('[Corpse] ' .. message)
Server.to_discord_bold(message)
end
end
local function on_gui_opened(event)
local entity = event.entity
if not entity or not entity.valid or entity.name ~= 'character-corpse' then
return
end
local player_index = event.player_index
local corpse_owner_index = entity.character_corpse_player_index
if player_index == corpse_owner_index then
return
end
local player = Game.get_player_by_index(player_index)
local corpse_owner = Game.get_player_by_index(corpse_owner_index)
if player and corpse_owner then
local message = table.concat {player.name, ' is looting ', corpse_owner.name, "'s corpse"}
game.print(message, Color.yellow)
log('[Corpse] ' .. message)
Server.to_discord_bold(message)
end end
end end
Event.add(defines.events.on_player_died, player_died) Event.add(defines.events.on_player_died, player_died)
Event.add(defines.events.on_character_corpse_expired, corpse_expired) Event.add(defines.events.on_character_corpse_expired, corpse_expired)
Event.add(defines.events.on_pre_player_mined_item, mined_entity) Event.add(defines.events.on_pre_player_mined_item, mined_entity)
Event.add(defines.events.on_gui_opened, on_gui_opened)

View File

@ -1,150 +1,150 @@
-- source: https://www.rapidtables.com/web/color/RGB_Color.html -- source: https://www.rapidtables.com/web/color/RGB_Color.html
return { return {
['maroon'] = {r = 128, g = 0, b = 0}, maroon = {r = 128, g = 0, b = 0},
['dark_red'] = {r = 139, g = 0, b = 0}, dark_red = {r = 139, g = 0, b = 0},
['brown'] = {r = 165, g = 42, b = 42}, brown = {r = 165, g = 42, b = 42},
['firebrick'] = {r = 178, g = 34, b = 34}, firebrick = {r = 178, g = 34, b = 34},
['crimson'] = {r = 220, g = 20, b = 60}, crimson = {r = 220, g = 20, b = 60},
['red'] = {r = 255, g = 0, b = 0}, red = {r = 255, g = 0, b = 0},
['tomato'] = {r = 255, g = 99, b = 71}, tomato = {r = 255, g = 99, b = 71},
['coral'] = {r = 255, g = 127, b = 80}, coral = {r = 255, g = 127, b = 80},
['indian_red'] = {r = 205, g = 92, b = 92}, indian_red = {r = 205, g = 92, b = 92},
['light_coral'] = {r = 240, g = 128, b = 128}, light_coral = {r = 240, g = 128, b = 128},
['dark_salmon'] = {r = 233, g = 150, b = 122}, dark_salmon = {r = 233, g = 150, b = 122},
['salmon'] = {r = 250, g = 128, b = 114}, salmon = {r = 250, g = 128, b = 114},
['light_salmon'] = {r = 255, g = 160, b = 122}, light_salmon = {r = 255, g = 160, b = 122},
['orange_red'] = {r = 255, g = 69, b = 0}, orange_red = {r = 255, g = 69, b = 0},
['dark_orange'] = {r = 255, g = 140, b = 0}, dark_orange = {r = 255, g = 140, b = 0},
['orange'] = {r = 255, g = 165, b = 0}, orange = {r = 255, g = 165, b = 0},
['gold'] = {r = 255, g = 215, b = 0}, gold = {r = 255, g = 215, b = 0},
['dark_golden_rod'] = {r = 184, g = 134, b = 11}, dark_golden_rod = {r = 184, g = 134, b = 11},
['golden_rod'] = {r = 218, g = 165, b = 32}, golden_rod = {r = 218, g = 165, b = 32},
['pale_golden_rod'] = {r = 238, g = 232, b = 170}, pale_golden_rod = {r = 238, g = 232, b = 170},
['dark_khaki'] = {r = 189, g = 183, b = 107}, dark_khaki = {r = 189, g = 183, b = 107},
['khaki'] = {r = 240, g = 230, b = 140}, khaki = {r = 240, g = 230, b = 140},
['olive'] = {r = 128, g = 128, b = 0}, olive = {r = 128, g = 128, b = 0},
['yellow'] = {r = 255, g = 255, b = 0}, yellow = {r = 255, g = 255, b = 0},
['yellow_green'] = {r = 154, g = 205, b = 50}, yellow_green = {r = 154, g = 205, b = 50},
['dark_olive_green'] = {r = 85, g = 107, b = 47}, dark_olive_green = {r = 85, g = 107, b = 47},
['olive_drab'] = {r = 107, g = 142, b = 35}, olive_drab = {r = 107, g = 142, b = 35},
['lawn_green'] = {r = 124, g = 252, b = 0}, lawn_green = {r = 124, g = 252, b = 0},
['chart_reuse'] = {r = 127, g = 255, b = 0}, chart_reuse = {r = 127, g = 255, b = 0},
['green_yellow'] = {r = 173, g = 255, b = 47}, green_yellow = {r = 173, g = 255, b = 47},
['dark_green'] = {r = 0, g = 100, b = 0}, dark_green = {r = 0, g = 100, b = 0},
['green'] = {r = 0, g = 128, b = 0}, green = {r = 0, g = 128, b = 0},
['forest_green'] = {r = 34, g = 139, b = 34}, forest_green = {r = 34, g = 139, b = 34},
['lime'] = {r = 0, g = 255, b = 0}, lime = {r = 0, g = 255, b = 0},
['lime_green'] = {r = 50, g = 205, b = 50}, lime_green = {r = 50, g = 205, b = 50},
['light_green'] = {r = 144, g = 238, b = 144}, light_green = {r = 144, g = 238, b = 144},
['pale_green'] = {r = 152, g = 251, b = 152}, pale_green = {r = 152, g = 251, b = 152},
['dark_sea_green'] = {r = 143, g = 188, b = 143}, dark_sea_green = {r = 143, g = 188, b = 143},
['medium_spring_green'] = {r = 0, g = 250, b = 154}, medium_spring_green = {r = 0, g = 250, b = 154},
['spring_green'] = {r = 0, g = 255, b = 127}, spring_green = {r = 0, g = 255, b = 127},
['sea_green'] = {r = 46, g = 139, b = 87}, sea_green = {r = 46, g = 139, b = 87},
['medium_aqua_marine'] = {r = 102, g = 205, b = 170}, medium_aqua_marine = {r = 102, g = 205, b = 170},
['medium_sea_green'] = {r = 60, g = 179, b = 113}, medium_sea_green = {r = 60, g = 179, b = 113},
['light_sea_green'] = {r = 32, g = 178, b = 170}, light_sea_green = {r = 32, g = 178, b = 170},
['dark_slate_gray'] = {r = 47, g = 79, b = 79}, dark_slate_gray = {r = 47, g = 79, b = 79},
['teal'] = {r = 0, g = 128, b = 128}, teal = {r = 0, g = 128, b = 128},
['dark_cyan'] = {r = 0, g = 139, b = 139}, dark_cyan = {r = 0, g = 139, b = 139},
['aqua'] = {r = 0, g = 255, b = 255}, aqua = {r = 0, g = 255, b = 255},
['cyan'] = {r = 0, g = 255, b = 255}, cyan = {r = 0, g = 255, b = 255},
['light_cyan'] = {r = 224, g = 255, b = 255}, light_cyan = {r = 224, g = 255, b = 255},
['dark_turquoise'] = {r = 0, g = 206, b = 209}, dark_turquoise = {r = 0, g = 206, b = 209},
['turquoise'] = {r = 64, g = 224, b = 208}, turquoise = {r = 64, g = 224, b = 208},
['medium_turquoise'] = {r = 72, g = 209, b = 204}, medium_turquoise = {r = 72, g = 209, b = 204},
['pale_turquoise'] = {r = 175, g = 238, b = 238}, pale_turquoise = {r = 175, g = 238, b = 238},
['aqua_marine'] = {r = 127, g = 255, b = 212}, aqua_marine = {r = 127, g = 255, b = 212},
['powder_blue'] = {r = 176, g = 224, b = 230}, powder_blue = {r = 176, g = 224, b = 230},
['cadet_blue'] = {r = 95, g = 158, b = 160}, cadet_blue = {r = 95, g = 158, b = 160},
['steel_blue'] = {r = 70, g = 130, b = 180}, steel_blue = {r = 70, g = 130, b = 180},
['corn_flower_blue'] = {r = 100, g = 149, b = 237}, corn_flower_blue = {r = 100, g = 149, b = 237},
['deep_sky_blue'] = {r = 0, g = 191, b = 255}, deep_sky_blue = {r = 0, g = 191, b = 255},
['dodger_blue'] = {r = 30, g = 144, b = 255}, dodger_blue = {r = 30, g = 144, b = 255},
['light_blue'] = {r = 173, g = 216, b = 230}, light_blue = {r = 173, g = 216, b = 230},
['sky_blue'] = {r = 135, g = 206, b = 235}, sky_blue = {r = 135, g = 206, b = 235},
['light_sky_blue'] = {r = 135, g = 206, b = 250}, light_sky_blue = {r = 135, g = 206, b = 250},
['midnight_blue'] = {r = 25, g = 25, b = 112}, midnight_blue = {r = 25, g = 25, b = 112},
['navy'] = {r = 0, g = 0, b = 128}, navy = {r = 0, g = 0, b = 128},
['dark_blue'] = {r = 0, g = 0, b = 139}, dark_blue = {r = 0, g = 0, b = 139},
['medium_blue'] = {r = 0, g = 0, b = 205}, medium_blue = {r = 0, g = 0, b = 205},
['blue'] = {r = 0, g = 0, b = 255}, blue = {r = 0, g = 0, b = 255},
['royal_blue'] = {r = 65, g = 105, b = 225}, royal_blue = {r = 65, g = 105, b = 225},
['blue_violet'] = {r = 138, g = 43, b = 226}, blue_violet = {r = 138, g = 43, b = 226},
['indigo'] = {r = 75, g = 0, b = 130}, indigo = {r = 75, g = 0, b = 130},
['dark_slate_blue'] = {r = 72, g = 61, b = 139}, dark_slate_blue = {r = 72, g = 61, b = 139},
['slate_blue'] = {r = 106, g = 90, b = 205}, slate_blue = {r = 106, g = 90, b = 205},
['medium_slate_blue'] = {r = 123, g = 104, b = 238}, medium_slate_blue = {r = 123, g = 104, b = 238},
['medium_purple'] = {r = 147, g = 112, b = 219}, medium_purple = {r = 147, g = 112, b = 219},
['dark_magenta'] = {r = 139, g = 0, b = 139}, dark_magenta = {r = 139, g = 0, b = 139},
['dark_violet'] = {r = 148, g = 0, b = 211}, dark_violet = {r = 148, g = 0, b = 211},
['dark_orchid'] = {r = 153, g = 50, b = 204}, dark_orchid = {r = 153, g = 50, b = 204},
['medium_orchid'] = {r = 186, g = 85, b = 211}, medium_orchid = {r = 186, g = 85, b = 211},
['purple'] = {r = 128, g = 0, b = 128}, purple = {r = 128, g = 0, b = 128},
['thistle'] = {r = 216, g = 191, b = 216}, thistle = {r = 216, g = 191, b = 216},
['plum'] = {r = 221, g = 160, b = 221}, plum = {r = 221, g = 160, b = 221},
['violet'] = {r = 238, g = 130, b = 238}, violet = {r = 238, g = 130, b = 238},
['magenta'] = {r = 255, g = 0, b = 255}, magenta = {r = 255, g = 0, b = 255},
['fuchsia'] = {r = 255, g = 0, b = 255}, fuchsia = {r = 255, g = 0, b = 255},
['orchid'] = {r = 218, g = 112, b = 214}, orchid = {r = 218, g = 112, b = 214},
['medium_violet_red'] = {r = 199, g = 21, b = 133}, medium_violet_red = {r = 199, g = 21, b = 133},
['pale_violet_red'] = {r = 219, g = 112, b = 147}, pale_violet_red = {r = 219, g = 112, b = 147},
['deep_pink'] = {r = 255, g = 20, b = 147}, deep_pink = {r = 255, g = 20, b = 147},
['hot_pink'] = {r = 255, g = 105, b = 180}, hot_pink = {r = 255, g = 105, b = 180},
['light_pink'] = {r = 255, g = 182, b = 193}, light_pink = {r = 255, g = 182, b = 193},
['pink'] = {r = 255, g = 192, b = 203}, pink = {r = 255, g = 192, b = 203},
['antique_white'] = {r = 250, g = 235, b = 215}, antique_white = {r = 250, g = 235, b = 215},
['beige'] = {r = 245, g = 245, b = 220}, beige = {r = 245, g = 245, b = 220},
['bisque'] = {r = 255, g = 228, b = 196}, bisque = {r = 255, g = 228, b = 196},
['blanched_almond'] = {r = 255, g = 235, b = 205}, blanched_almond = {r = 255, g = 235, b = 205},
['wheat'] = {r = 245, g = 222, b = 179}, wheat = {r = 245, g = 222, b = 179},
['corn_silk'] = {r = 255, g = 248, b = 220}, corn_silk = {r = 255, g = 248, b = 220},
['lemon_chiffon'] = {r = 255, g = 250, b = 205}, lemon_chiffon = {r = 255, g = 250, b = 205},
['light_golden_rod_yellow'] = {r = 250, g = 250, b = 210}, light_golden_rod_yellow = {r = 250, g = 250, b = 210},
['light_yellow'] = {r = 255, g = 255, b = 224}, light_yellow = {r = 255, g = 255, b = 224},
['saddle_brown'] = {r = 139, g = 69, b = 19}, saddle_brown = {r = 139, g = 69, b = 19},
['sienna'] = {r = 160, g = 82, b = 45}, sienna = {r = 160, g = 82, b = 45},
['chocolate'] = {r = 210, g = 105, b = 30}, chocolate = {r = 210, g = 105, b = 30},
['peru'] = {r = 205, g = 133, b = 63}, peru = {r = 205, g = 133, b = 63},
['sandy_brown'] = {r = 244, g = 164, b = 96}, sandy_brown = {r = 244, g = 164, b = 96},
['burly_wood'] = {r = 222, g = 184, b = 135}, burly_wood = {r = 222, g = 184, b = 135},
['tan'] = {r = 210, g = 180, b = 140}, tan = {r = 210, g = 180, b = 140},
['rosy_brown'] = {r = 188, g = 143, b = 143}, rosy_brown = {r = 188, g = 143, b = 143},
['moccasin'] = {r = 255, g = 228, b = 181}, moccasin = {r = 255, g = 228, b = 181},
['navajo_white'] = {r = 255, g = 222, b = 173}, navajo_white = {r = 255, g = 222, b = 173},
['peach_puff'] = {r = 255, g = 218, b = 185}, peach_puff = {r = 255, g = 218, b = 185},
['misty_rose'] = {r = 255, g = 228, b = 225}, misty_rose = {r = 255, g = 228, b = 225},
['lavender_blush'] = {r = 255, g = 240, b = 245}, lavender_blush = {r = 255, g = 240, b = 245},
['linen'] = {r = 250, g = 240, b = 230}, linen = {r = 250, g = 240, b = 230},
['old_lace'] = {r = 253, g = 245, b = 230}, old_lace = {r = 253, g = 245, b = 230},
['papaya_whip'] = {r = 255, g = 239, b = 213}, papaya_whip = {r = 255, g = 239, b = 213},
['sea_shell'] = {r = 255, g = 245, b = 238}, sea_shell = {r = 255, g = 245, b = 238},
['mint_cream'] = {r = 245, g = 255, b = 250}, mint_cream = {r = 245, g = 255, b = 250},
['slate_gray'] = {r = 112, g = 128, b = 144}, slate_gray = {r = 112, g = 128, b = 144},
['light_slate_gray'] = {r = 119, g = 136, b = 153}, light_slate_gray = {r = 119, g = 136, b = 153},
['light_steel_blue'] = {r = 176, g = 196, b = 222}, light_steel_blue = {r = 176, g = 196, b = 222},
['lavender'] = {r = 230, g = 230, b = 250}, lavender = {r = 230, g = 230, b = 250},
['floral_white'] = {r = 255, g = 250, b = 240}, floral_white = {r = 255, g = 250, b = 240},
['alice_blue'] = {r = 240, g = 248, b = 255}, alice_blue = {r = 240, g = 248, b = 255},
['ghost_white'] = {r = 248, g = 248, b = 255}, ghost_white = {r = 248, g = 248, b = 255},
['honeydew'] = {r = 240, g = 255, b = 240}, honeydew = {r = 240, g = 255, b = 240},
['ivory'] = {r = 255, g = 255, b = 240}, ivory = {r = 255, g = 255, b = 240},
['azure'] = {r = 240, g = 255, b = 255}, azure = {r = 240, g = 255, b = 255},
['snow'] = {r = 255, g = 250, b = 250}, snow = {r = 255, g = 250, b = 250},
['black'] = {r = 0, g = 0, b = 0}, black = {r = 0, g = 0, b = 0},
['silver'] = {r = 192, g = 192, b = 192}, silver = {r = 192, g = 192, b = 192},
['dim_grey'] = {r = 105, g = 105, b = 105}, dim_grey = {r = 105, g = 105, b = 105},
['dim_gray'] = {r = 105, g = 105, b = 105}, dim_gray = {r = 105, g = 105, b = 105},
['grey'] = {r = 128, g = 128, b = 128}, grey = {r = 128, g = 128, b = 128},
['gray'] = {r = 128, g = 128, b = 128}, gray = {r = 128, g = 128, b = 128},
['dark_grey'] = {r = 169, g = 169, b = 169}, dark_grey = {r = 169, g = 169, b = 169},
['dark_gray'] = {r = 169, g = 169, b = 169}, dark_gray = {r = 169, g = 169, b = 169},
['light_grey'] = {r = 211, g = 211, b = 211}, light_grey = {r = 211, g = 211, b = 211},
['light_gray'] = {r = 211, g = 211, b = 211}, light_gray = {r = 211, g = 211, b = 211},
['gainsboro'] = {r = 220, g = 220, b = 220}, gainsboro = {r = 220, g = 220, b = 220},
['white_smoke'] = {r = 245, g = 245, b = 245}, white_smoke = {r = 245, g = 245, b = 245},
['white'] = {r = 255, g = 255, b = 255}, white = {r = 255, g = 255, b = 255},
['regular'] = {r = 0.155, g = 0.540, b = 0.898}, regular = {r = 0.155, g = 0.540, b = 0.898},
['donator'] = {r = 172.6, g = 70.2, b = 215.8}, donator = {r = 172.6, g = 70.2, b = 215.8},
['admin'] = {r = 0.093, g = 0.768, b = 0.172} admin = {r = 0.093, g = 0.768, b = 0.172}
} }

View File

@ -30,7 +30,11 @@ function Game.get_player_by_index(index)
p = bad_name_players[index] p = bad_name_players[index]
if p then if p then
return p if p.valid then
return p
else
return nil
end
end end
for k, v in pairs(game.players) do for k, v in pairs(game.players) do
@ -77,7 +81,6 @@ end
@return the created entity @return the created entity
]] ]]
function Game.print_player_floating_text_position(player_index, text, color, x_offset, y_offset) function Game.print_player_floating_text_position(player_index, text, color, x_offset, y_offset)
local player = Game.get_player_by_index(player_index) local player = Game.get_player_by_index(player_index)
if not player or not player.valid then if not player or not player.valid then