Merge branch 'hotfix/4.0.6'

This commit is contained in:
Cooldude2606
2019-02-19 19:11:41 +00:00
3 changed files with 26 additions and 16 deletions

View File

@@ -32,6 +32,7 @@ function ChatPopup.sendFlyingText(player, text)
end end
script.on_event(defines.events.on_console_chat, function(event) 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] local player = game.players[event.player_index]
if not player then return end if not player then return end
if not event.message then return end if not event.message then return end

View File

@@ -235,7 +235,7 @@ local function run_custom_command(command)
-- runs the command -- runs the command
local success, err = pcall(data.callback,command,args) local success, err = pcall(data.callback,command,args)
if not success then error(err) end 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) logMessage(player.name,command,'Used command',args)
end end

View File

@@ -115,26 +115,35 @@ end
function ExpLib.player_return(rtn,colour,player) 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] 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 player = player or game.player
local function returnWith(callback) -- converts the value to a string
if ExpLib.is_type(rtn,'table') then local returnAsString
-- test for: userdata, locale string, table with __tostring meta method, any other table if ExpLib.is_type(rtn,'table') then
if ExpLib.is_type(rtn.__self,'userdata') then callback('Cant Display Userdata') if ExpLib.is_type(rtn.__self,'userdata') then
elseif ExpLib.is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then callback(rtn) -- value is userdata
elseif getmetatable(rtn) ~= nil and not tostring(rtn):find('table: 0x') then callback(tostring(rtn)) returnAsString = 'Cant Display Userdata'
else callback(table.tostring(rtn)) end elseif ExpLib.is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then
-- test for: function -- value is a locale string
elseif ExpLib.is_type(rtn,'function') then callback('Cant Display Functions') returnAsString = rtn
-- else just call tostring elseif getmetatable(rtn) ~= nil and not tostring(rtn):find('table: 0x') then
else callback(tostring(rtn)) end -- value has a tostring meta method
end 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 if player then
-- allows any valid player identifier to be used -- allows any valid player identifier to be used
player = Game.get_player(player) player = Game.get_player(player)
if not player then error('Invalid Player given to player_return',2) end if not player then error('Invalid Player given to player_return',2) end
-- plays a nice sound that is different to normal message sound -- plays a nice sound that is different to normal message sound
player.play_sound{path='utility/scenario_message'} player.play_sound{path='utility/scenario_message'}
returnWith(function(newRtn) player.print(newRtn,colour) end) player.print(returnAsString,colour)
else returnWith(function(newRtn) rcon.print(newRtn) end) end else rcon.print(returnAsString) end
end end
--- Convert ticks to hours --- Convert ticks to hours