From 40fba426767803251ebf3c2a2ec34b269edae167 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 19 Feb 2019 18:51:31 +0000 Subject: [PATCH 1/2] Fixed Chat Popup --- modules/ChatPopup/control.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ChatPopup/control.lua b/modules/ChatPopup/control.lua index c22c1564..6ab99fd3 100644 --- a/modules/ChatPopup/control.lua +++ b/modules/ChatPopup/control.lua @@ -32,6 +32,7 @@ function ChatPopup.sendFlyingText(player, text) end script.on_event(defines.events.on_console_chat, function(event) + if not event.player_index then return end local player = game.players[event.player_index] if not player then return end if not event.message then return end From 17875f2fafc3a807586a6dde119919d1ed4a07be Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 19 Feb 2019 19:11:32 +0000 Subject: [PATCH 2/2] =?UTF-8?q?If=20this=20still=20breaks=20i=20guess=20no?= =?UTF-8?q?=20rcon=20=C2=AF\=5F(=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ExpGamingCore/Command/control.lua | 2 +- modules/ExpGamingLib/control.lua | 39 ++++++++++++++--------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/ExpGamingCore/Command/control.lua b/modules/ExpGamingCore/Command/control.lua index 70b23fed..84b00e49 100644 --- a/modules/ExpGamingCore/Command/control.lua +++ b/modules/ExpGamingCore/Command/control.lua @@ -235,7 +235,7 @@ local function run_custom_command(command) -- runs the command local success, err = pcall(data.callback,command,args) if not success then error(err) end - if err ~= commands.error and player ~= SERVER then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end + if err ~= commands.error then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end logMessage(player.name,command,'Used command',args) end diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index 67d5731d..77b4685c 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -82,7 +82,7 @@ end -- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil -- @treturn boolean is v of type test_type function ExpLib.is_type(v,test_type) - return test_type and v and type(v) == test_type or not test_type and not v or false + return test_type and v and type(v) == test_type or not test_type and not v or false end --- Compare types faster for faster validation of prams, including giving an error if incorrect @@ -115,26 +115,35 @@ end function ExpLib.player_return(rtn,colour,player) colour = ExpLib.is_type(colour,'table') and colour or defines.textcolor[colour] ~= defines.color.white and defines.textcolor[colour] or defines.color[colour] player = player or game.player - local function returnWith(callback) - if ExpLib.is_type(rtn,'table') then - -- test for: userdata, locale string, table with __tostring meta method, any other table - if ExpLib.is_type(rtn.__self,'userdata') then callback('Cant Display Userdata') - elseif ExpLib.is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then callback(rtn) - elseif getmetatable(rtn) ~= nil and not tostring(rtn):find('table: 0x') then callback(tostring(rtn)) - else callback(table.tostring(rtn)) end - -- test for: function - elseif ExpLib.is_type(rtn,'function') then callback('Cant Display Functions') - -- else just call tostring - else callback(tostring(rtn)) end - end + -- converts the value to a string + local returnAsString + if ExpLib.is_type(rtn,'table') then + if ExpLib.is_type(rtn.__self,'userdata') then + -- value is userdata + returnAsString = 'Cant Display Userdata' + elseif ExpLib.is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then + -- value is a locale string + returnAsString = rtn + elseif getmetatable(rtn) ~= nil and not tostring(rtn):find('table: 0x') then + -- value has a tostring meta method + returnAsString = tostring(rtn) + else + -- value is a table + returnAsString = table.tostring(rtn) + end + elseif ExpLib.is_type(rtn,'function') then + -- value is a function + returnAsString = 'Cant Display Functions' + else returnAsString = tostring(rtn) end + -- returns to the player or the server if player then -- allows any valid player identifier to be used player = Game.get_player(player) if not player then error('Invalid Player given to player_return',2) end -- plays a nice sound that is different to normal message sound player.play_sound{path='utility/scenario_message'} - returnWith(function(newRtn) player.print(newRtn,colour) end) - else returnWith(function(newRtn) rcon.print(newRtn) end) end + player.print(returnAsString,colour) + else rcon.print(returnAsString) end end --- Convert ticks to hours