From ba27be74332358b608dcf3a87c77dfb413db4741 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 21 Jan 2019 15:54:14 +0000 Subject: [PATCH 1/3] add messages on looting corpse --- features/corpse_util.lua | 78 +++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/features/corpse_util.lua b/features/corpse_util.lua index 60cff348..6f810d72 100644 --- a/features/corpse_util.lua +++ b/features/corpse_util.lua @@ -3,6 +3,8 @@ local Global = require 'utils.global' local Task = require 'utils.task' local Token = require 'utils.token' local Game = require 'utils.game' +local Server = require 'features.server' +local Color = require 'resources.color_presets' local player_corpses = {} @@ -43,7 +45,11 @@ local function player_died(event) local text = player.name .. "'s corpse" 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 return @@ -85,21 +91,67 @@ local corpse_util_mined_entity = local function mined_entity(event) local entity = event.entity - if entity and entity.valid and entity.name == 'character-corpse' then - -- The corpse may be mined but not removed (if player doesn't have inventory space) - -- so we wait one tick to see if the corpse is gone. - Task.set_timeout_in_ticks( - 1, - corpse_util_mined_entity, - { - entity = entity, - player_index = entity.character_corpse_player_index, - tick = entity.character_corpse_tick_of_death - } - ) + if not entity or not entity.valid or entity.name ~= 'character-corpse' then + return + end + + -- The corpse may be mined but not removed (if player doesn't have inventory space) + -- so we wait one tick to see if the corpse is gone. + Task.set_timeout_in_ticks( + 1, + corpse_util_mined_entity, + { + 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 Event.add(defines.events.on_player_died, player_died) 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_gui_opened, on_gui_opened) From 9a7a697bef729c441882041710f387ee75cbebe7 Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 21 Jan 2019 15:54:34 +0000 Subject: [PATCH 2/3] return nil is player invalid --- utils/game.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/game.lua b/utils/game.lua index 3b4d84e9..864b2a9d 100644 --- a/utils/game.lua +++ b/utils/game.lua @@ -30,7 +30,11 @@ function Game.get_player_by_index(index) p = bad_name_players[index] if p then - return p + if p.valid then + return p + else + return nil + end end for k, v in pairs(game.players) do @@ -77,7 +81,6 @@ end @return the created entity ]] - function Game.print_player_floating_text_position(player_index, text, color, x_offset, y_offset) local player = Game.get_player_by_index(player_index) if not player or not player.valid then From 44427c6944c1fff091e52e84ebaf25a6dbd720ac Mon Sep 17 00:00:00 2001 From: grilledham Date: Mon, 21 Jan 2019 15:55:07 +0000 Subject: [PATCH 3/3] changed format to provide auto complete in vs code --- resources/color_presets.lua | 294 ++++++++++++++++++------------------ 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/resources/color_presets.lua b/resources/color_presets.lua index 0717daaf..2e489bc6 100644 --- a/resources/color_presets.lua +++ b/resources/color_presets.lua @@ -1,150 +1,150 @@ -- source: https://www.rapidtables.com/web/color/RGB_Color.html return { - ['maroon'] = {r = 128, g = 0, b = 0}, - ['dark_red'] = {r = 139, g = 0, b = 0}, - ['brown'] = {r = 165, g = 42, b = 42}, - ['firebrick'] = {r = 178, g = 34, b = 34}, - ['crimson'] = {r = 220, g = 20, b = 60}, - ['red'] = {r = 255, g = 0, b = 0}, - ['tomato'] = {r = 255, g = 99, b = 71}, - ['coral'] = {r = 255, g = 127, b = 80}, - ['indian_red'] = {r = 205, g = 92, b = 92}, - ['light_coral'] = {r = 240, g = 128, b = 128}, - ['dark_salmon'] = {r = 233, g = 150, b = 122}, - ['salmon'] = {r = 250, g = 128, b = 114}, - ['light_salmon'] = {r = 255, g = 160, b = 122}, - ['orange_red'] = {r = 255, g = 69, b = 0}, - ['dark_orange'] = {r = 255, g = 140, b = 0}, - ['orange'] = {r = 255, g = 165, b = 0}, - ['gold'] = {r = 255, g = 215, b = 0}, - ['dark_golden_rod'] = {r = 184, g = 134, b = 11}, - ['golden_rod'] = {r = 218, g = 165, b = 32}, - ['pale_golden_rod'] = {r = 238, g = 232, b = 170}, - ['dark_khaki'] = {r = 189, g = 183, b = 107}, - ['khaki'] = {r = 240, g = 230, b = 140}, - ['olive'] = {r = 128, g = 128, b = 0}, - ['yellow'] = {r = 255, g = 255, b = 0}, - ['yellow_green'] = {r = 154, g = 205, b = 50}, - ['dark_olive_green'] = {r = 85, g = 107, b = 47}, - ['olive_drab'] = {r = 107, g = 142, b = 35}, - ['lawn_green'] = {r = 124, g = 252, b = 0}, - ['chart_reuse'] = {r = 127, g = 255, b = 0}, - ['green_yellow'] = {r = 173, g = 255, b = 47}, - ['dark_green'] = {r = 0, g = 100, b = 0}, - ['green'] = {r = 0, g = 128, b = 0}, - ['forest_green'] = {r = 34, g = 139, b = 34}, - ['lime'] = {r = 0, g = 255, b = 0}, - ['lime_green'] = {r = 50, g = 205, b = 50}, - ['light_green'] = {r = 144, g = 238, b = 144}, - ['pale_green'] = {r = 152, g = 251, b = 152}, - ['dark_sea_green'] = {r = 143, g = 188, b = 143}, - ['medium_spring_green'] = {r = 0, g = 250, b = 154}, - ['spring_green'] = {r = 0, g = 255, b = 127}, - ['sea_green'] = {r = 46, g = 139, b = 87}, - ['medium_aqua_marine'] = {r = 102, g = 205, b = 170}, - ['medium_sea_green'] = {r = 60, g = 179, b = 113}, - ['light_sea_green'] = {r = 32, g = 178, b = 170}, - ['dark_slate_gray'] = {r = 47, g = 79, b = 79}, - ['teal'] = {r = 0, g = 128, b = 128}, - ['dark_cyan'] = {r = 0, g = 139, b = 139}, - ['aqua'] = {r = 0, g = 255, b = 255}, - ['cyan'] = {r = 0, g = 255, b = 255}, - ['light_cyan'] = {r = 224, g = 255, b = 255}, - ['dark_turquoise'] = {r = 0, g = 206, b = 209}, - ['turquoise'] = {r = 64, g = 224, b = 208}, - ['medium_turquoise'] = {r = 72, g = 209, b = 204}, - ['pale_turquoise'] = {r = 175, g = 238, b = 238}, - ['aqua_marine'] = {r = 127, g = 255, b = 212}, - ['powder_blue'] = {r = 176, g = 224, b = 230}, - ['cadet_blue'] = {r = 95, g = 158, b = 160}, - ['steel_blue'] = {r = 70, g = 130, b = 180}, - ['corn_flower_blue'] = {r = 100, g = 149, b = 237}, - ['deep_sky_blue'] = {r = 0, g = 191, b = 255}, - ['dodger_blue'] = {r = 30, g = 144, b = 255}, - ['light_blue'] = {r = 173, g = 216, b = 230}, - ['sky_blue'] = {r = 135, g = 206, b = 235}, - ['light_sky_blue'] = {r = 135, g = 206, b = 250}, - ['midnight_blue'] = {r = 25, g = 25, b = 112}, - ['navy'] = {r = 0, g = 0, b = 128}, - ['dark_blue'] = {r = 0, g = 0, b = 139}, - ['medium_blue'] = {r = 0, g = 0, b = 205}, - ['blue'] = {r = 0, g = 0, b = 255}, - ['royal_blue'] = {r = 65, g = 105, b = 225}, - ['blue_violet'] = {r = 138, g = 43, b = 226}, - ['indigo'] = {r = 75, g = 0, b = 130}, - ['dark_slate_blue'] = {r = 72, g = 61, b = 139}, - ['slate_blue'] = {r = 106, g = 90, b = 205}, - ['medium_slate_blue'] = {r = 123, g = 104, b = 238}, - ['medium_purple'] = {r = 147, g = 112, b = 219}, - ['dark_magenta'] = {r = 139, g = 0, b = 139}, - ['dark_violet'] = {r = 148, g = 0, b = 211}, - ['dark_orchid'] = {r = 153, g = 50, b = 204}, - ['medium_orchid'] = {r = 186, g = 85, b = 211}, - ['purple'] = {r = 128, g = 0, b = 128}, - ['thistle'] = {r = 216, g = 191, b = 216}, - ['plum'] = {r = 221, g = 160, b = 221}, - ['violet'] = {r = 238, g = 130, b = 238}, - ['magenta'] = {r = 255, g = 0, b = 255}, - ['fuchsia'] = {r = 255, g = 0, b = 255}, - ['orchid'] = {r = 218, g = 112, b = 214}, - ['medium_violet_red'] = {r = 199, g = 21, b = 133}, - ['pale_violet_red'] = {r = 219, g = 112, b = 147}, - ['deep_pink'] = {r = 255, g = 20, b = 147}, - ['hot_pink'] = {r = 255, g = 105, b = 180}, - ['light_pink'] = {r = 255, g = 182, b = 193}, - ['pink'] = {r = 255, g = 192, b = 203}, - ['antique_white'] = {r = 250, g = 235, b = 215}, - ['beige'] = {r = 245, g = 245, b = 220}, - ['bisque'] = {r = 255, g = 228, b = 196}, - ['blanched_almond'] = {r = 255, g = 235, b = 205}, - ['wheat'] = {r = 245, g = 222, b = 179}, - ['corn_silk'] = {r = 255, g = 248, b = 220}, - ['lemon_chiffon'] = {r = 255, g = 250, b = 205}, - ['light_golden_rod_yellow'] = {r = 250, g = 250, b = 210}, - ['light_yellow'] = {r = 255, g = 255, b = 224}, - ['saddle_brown'] = {r = 139, g = 69, b = 19}, - ['sienna'] = {r = 160, g = 82, b = 45}, - ['chocolate'] = {r = 210, g = 105, b = 30}, - ['peru'] = {r = 205, g = 133, b = 63}, - ['sandy_brown'] = {r = 244, g = 164, b = 96}, - ['burly_wood'] = {r = 222, g = 184, b = 135}, - ['tan'] = {r = 210, g = 180, b = 140}, - ['rosy_brown'] = {r = 188, g = 143, b = 143}, - ['moccasin'] = {r = 255, g = 228, b = 181}, - ['navajo_white'] = {r = 255, g = 222, b = 173}, - ['peach_puff'] = {r = 255, g = 218, b = 185}, - ['misty_rose'] = {r = 255, g = 228, b = 225}, - ['lavender_blush'] = {r = 255, g = 240, b = 245}, - ['linen'] = {r = 250, g = 240, b = 230}, - ['old_lace'] = {r = 253, g = 245, b = 230}, - ['papaya_whip'] = {r = 255, g = 239, b = 213}, - ['sea_shell'] = {r = 255, g = 245, b = 238}, - ['mint_cream'] = {r = 245, g = 255, b = 250}, - ['slate_gray'] = {r = 112, g = 128, b = 144}, - ['light_slate_gray'] = {r = 119, g = 136, b = 153}, - ['light_steel_blue'] = {r = 176, g = 196, b = 222}, - ['lavender'] = {r = 230, g = 230, b = 250}, - ['floral_white'] = {r = 255, g = 250, b = 240}, - ['alice_blue'] = {r = 240, g = 248, b = 255}, - ['ghost_white'] = {r = 248, g = 248, b = 255}, - ['honeydew'] = {r = 240, g = 255, b = 240}, - ['ivory'] = {r = 255, g = 255, b = 240}, - ['azure'] = {r = 240, g = 255, b = 255}, - ['snow'] = {r = 255, g = 250, b = 250}, - ['black'] = {r = 0, g = 0, b = 0}, - ['silver'] = {r = 192, g = 192, b = 192}, - ['dim_grey'] = {r = 105, g = 105, b = 105}, - ['dim_gray'] = {r = 105, g = 105, b = 105}, - ['grey'] = {r = 128, g = 128, b = 128}, - ['gray'] = {r = 128, g = 128, b = 128}, - ['dark_grey'] = {r = 169, g = 169, b = 169}, - ['dark_gray'] = {r = 169, g = 169, b = 169}, - ['light_grey'] = {r = 211, g = 211, b = 211}, - ['light_gray'] = {r = 211, g = 211, b = 211}, - ['gainsboro'] = {r = 220, g = 220, b = 220}, - ['white_smoke'] = {r = 245, g = 245, b = 245}, - ['white'] = {r = 255, g = 255, b = 255}, - ['regular'] = {r = 0.155, g = 0.540, b = 0.898}, - ['donator'] = {r = 172.6, g = 70.2, b = 215.8}, - ['admin'] = {r = 0.093, g = 0.768, b = 0.172} + maroon = {r = 128, g = 0, b = 0}, + dark_red = {r = 139, g = 0, b = 0}, + brown = {r = 165, g = 42, b = 42}, + firebrick = {r = 178, g = 34, b = 34}, + crimson = {r = 220, g = 20, b = 60}, + red = {r = 255, g = 0, b = 0}, + tomato = {r = 255, g = 99, b = 71}, + coral = {r = 255, g = 127, b = 80}, + indian_red = {r = 205, g = 92, b = 92}, + light_coral = {r = 240, g = 128, b = 128}, + dark_salmon = {r = 233, g = 150, b = 122}, + salmon = {r = 250, g = 128, b = 114}, + light_salmon = {r = 255, g = 160, b = 122}, + orange_red = {r = 255, g = 69, b = 0}, + dark_orange = {r = 255, g = 140, b = 0}, + orange = {r = 255, g = 165, b = 0}, + gold = {r = 255, g = 215, b = 0}, + dark_golden_rod = {r = 184, g = 134, b = 11}, + golden_rod = {r = 218, g = 165, b = 32}, + pale_golden_rod = {r = 238, g = 232, b = 170}, + dark_khaki = {r = 189, g = 183, b = 107}, + khaki = {r = 240, g = 230, b = 140}, + olive = {r = 128, g = 128, b = 0}, + yellow = {r = 255, g = 255, b = 0}, + yellow_green = {r = 154, g = 205, b = 50}, + dark_olive_green = {r = 85, g = 107, b = 47}, + olive_drab = {r = 107, g = 142, b = 35}, + lawn_green = {r = 124, g = 252, b = 0}, + chart_reuse = {r = 127, g = 255, b = 0}, + green_yellow = {r = 173, g = 255, b = 47}, + dark_green = {r = 0, g = 100, b = 0}, + green = {r = 0, g = 128, b = 0}, + forest_green = {r = 34, g = 139, b = 34}, + lime = {r = 0, g = 255, b = 0}, + lime_green = {r = 50, g = 205, b = 50}, + light_green = {r = 144, g = 238, b = 144}, + pale_green = {r = 152, g = 251, b = 152}, + dark_sea_green = {r = 143, g = 188, b = 143}, + medium_spring_green = {r = 0, g = 250, b = 154}, + spring_green = {r = 0, g = 255, b = 127}, + sea_green = {r = 46, g = 139, b = 87}, + medium_aqua_marine = {r = 102, g = 205, b = 170}, + medium_sea_green = {r = 60, g = 179, b = 113}, + light_sea_green = {r = 32, g = 178, b = 170}, + dark_slate_gray = {r = 47, g = 79, b = 79}, + teal = {r = 0, g = 128, b = 128}, + dark_cyan = {r = 0, g = 139, b = 139}, + aqua = {r = 0, g = 255, b = 255}, + cyan = {r = 0, g = 255, b = 255}, + light_cyan = {r = 224, g = 255, b = 255}, + dark_turquoise = {r = 0, g = 206, b = 209}, + turquoise = {r = 64, g = 224, b = 208}, + medium_turquoise = {r = 72, g = 209, b = 204}, + pale_turquoise = {r = 175, g = 238, b = 238}, + aqua_marine = {r = 127, g = 255, b = 212}, + powder_blue = {r = 176, g = 224, b = 230}, + cadet_blue = {r = 95, g = 158, b = 160}, + steel_blue = {r = 70, g = 130, b = 180}, + corn_flower_blue = {r = 100, g = 149, b = 237}, + deep_sky_blue = {r = 0, g = 191, b = 255}, + dodger_blue = {r = 30, g = 144, b = 255}, + light_blue = {r = 173, g = 216, b = 230}, + sky_blue = {r = 135, g = 206, b = 235}, + light_sky_blue = {r = 135, g = 206, b = 250}, + midnight_blue = {r = 25, g = 25, b = 112}, + navy = {r = 0, g = 0, b = 128}, + dark_blue = {r = 0, g = 0, b = 139}, + medium_blue = {r = 0, g = 0, b = 205}, + blue = {r = 0, g = 0, b = 255}, + royal_blue = {r = 65, g = 105, b = 225}, + blue_violet = {r = 138, g = 43, b = 226}, + indigo = {r = 75, g = 0, b = 130}, + dark_slate_blue = {r = 72, g = 61, b = 139}, + slate_blue = {r = 106, g = 90, b = 205}, + medium_slate_blue = {r = 123, g = 104, b = 238}, + medium_purple = {r = 147, g = 112, b = 219}, + dark_magenta = {r = 139, g = 0, b = 139}, + dark_violet = {r = 148, g = 0, b = 211}, + dark_orchid = {r = 153, g = 50, b = 204}, + medium_orchid = {r = 186, g = 85, b = 211}, + purple = {r = 128, g = 0, b = 128}, + thistle = {r = 216, g = 191, b = 216}, + plum = {r = 221, g = 160, b = 221}, + violet = {r = 238, g = 130, b = 238}, + magenta = {r = 255, g = 0, b = 255}, + fuchsia = {r = 255, g = 0, b = 255}, + orchid = {r = 218, g = 112, b = 214}, + medium_violet_red = {r = 199, g = 21, b = 133}, + pale_violet_red = {r = 219, g = 112, b = 147}, + deep_pink = {r = 255, g = 20, b = 147}, + hot_pink = {r = 255, g = 105, b = 180}, + light_pink = {r = 255, g = 182, b = 193}, + pink = {r = 255, g = 192, b = 203}, + antique_white = {r = 250, g = 235, b = 215}, + beige = {r = 245, g = 245, b = 220}, + bisque = {r = 255, g = 228, b = 196}, + blanched_almond = {r = 255, g = 235, b = 205}, + wheat = {r = 245, g = 222, b = 179}, + corn_silk = {r = 255, g = 248, b = 220}, + lemon_chiffon = {r = 255, g = 250, b = 205}, + light_golden_rod_yellow = {r = 250, g = 250, b = 210}, + light_yellow = {r = 255, g = 255, b = 224}, + saddle_brown = {r = 139, g = 69, b = 19}, + sienna = {r = 160, g = 82, b = 45}, + chocolate = {r = 210, g = 105, b = 30}, + peru = {r = 205, g = 133, b = 63}, + sandy_brown = {r = 244, g = 164, b = 96}, + burly_wood = {r = 222, g = 184, b = 135}, + tan = {r = 210, g = 180, b = 140}, + rosy_brown = {r = 188, g = 143, b = 143}, + moccasin = {r = 255, g = 228, b = 181}, + navajo_white = {r = 255, g = 222, b = 173}, + peach_puff = {r = 255, g = 218, b = 185}, + misty_rose = {r = 255, g = 228, b = 225}, + lavender_blush = {r = 255, g = 240, b = 245}, + linen = {r = 250, g = 240, b = 230}, + old_lace = {r = 253, g = 245, b = 230}, + papaya_whip = {r = 255, g = 239, b = 213}, + sea_shell = {r = 255, g = 245, b = 238}, + mint_cream = {r = 245, g = 255, b = 250}, + slate_gray = {r = 112, g = 128, b = 144}, + light_slate_gray = {r = 119, g = 136, b = 153}, + light_steel_blue = {r = 176, g = 196, b = 222}, + lavender = {r = 230, g = 230, b = 250}, + floral_white = {r = 255, g = 250, b = 240}, + alice_blue = {r = 240, g = 248, b = 255}, + ghost_white = {r = 248, g = 248, b = 255}, + honeydew = {r = 240, g = 255, b = 240}, + ivory = {r = 255, g = 255, b = 240}, + azure = {r = 240, g = 255, b = 255}, + snow = {r = 255, g = 250, b = 250}, + black = {r = 0, g = 0, b = 0}, + silver = {r = 192, g = 192, b = 192}, + dim_grey = {r = 105, g = 105, b = 105}, + dim_gray = {r = 105, g = 105, b = 105}, + grey = {r = 128, g = 128, b = 128}, + gray = {r = 128, g = 128, b = 128}, + dark_grey = {r = 169, g = 169, b = 169}, + dark_gray = {r = 169, g = 169, b = 169}, + light_grey = {r = 211, g = 211, b = 211}, + light_gray = {r = 211, g = 211, b = 211}, + gainsboro = {r = 220, g = 220, b = 220}, + white_smoke = {r = 245, g = 245, b = 245}, + white = {r = 255, g = 255, b = 255}, + regular = {r = 0.155, g = 0.540, b = 0.898}, + donator = {r = 172.6, g = 70.2, b = 215.8}, + admin = {r = 0.093, g = 0.768, b = 0.172} }