diff --git a/PHI-CL/control.lua b/PHI-CL/control.lua index b9a3082..7ad7a88 100644 --- a/PHI-CL/control.lua +++ b/PHI-CL/control.lua @@ -57,15 +57,23 @@ script.on_configuration_changed(function() end end) +script.on_event(defines.events.on_player_created, function(event) + if not event.player_index or not game.players[event.player_index] then + return + end + + local player = game.players[event.player_index] + + if (settings.startup['PHI-MI'].value and settings.startup['PHI-MI-GENERIC'].value) or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then + gui_create(player) + end + + if settings.startup['PHI-CT'].value then + editor.available(player) + end +end) + if (settings.startup['PHI-MI'].value and settings.startup['PHI-MI-GENERIC'].value) or (settings.startup['PHI-GM'].value and settings.startup['PHI-GM'].value ~= '') then - script.on_event(defines.events.on_player_created, function(event) - if not event.player_index or not game.players[event.player_index] then - return - end - - gui_create(game.players[event.player_index]) - end) - script.on_event(defines.events.on_gui_opened, function(event) if not event.player_index or not game.players[event.player_index] then return @@ -105,4 +113,12 @@ end if settings.startup['PHI-CT'].value then script.on_event(defines.events.on_lua_shortcut, editor.toggle) script.on_event(defines.events.on_player_toggled_map_editor, editor.toggle_editor) + + script.on_event({defines.events.on_player_promoted, defines.events.on_player_demoted}, function(event) + if not event.player_index or not game.players[event.player_index] then + return + end + + editor.available(game.players[event.player_index]) + end) end diff --git a/PHI-CL/control/editor.lua b/PHI-CL/control/editor.lua index 39f79df..9297620 100644 --- a/PHI-CL/control/editor.lua +++ b/PHI-CL/control/editor.lua @@ -5,13 +5,13 @@ function main.toggle(event) return end - local player = game.players[event.player_index] - - if player.permission_group and not player.permission_group.allows_action(defines.input_action.toggle_map_editor) then + if not event.player_index then return end - if not player.admin then + local player = game.players[event.player_index] + + if not player then return end @@ -24,4 +24,8 @@ function main.toggle_editor(event) game.tick_paused = false end +function main.available(player) + player.set_shortcut_available('phi-cl-toggle-editor', player.admin and player.permission_group and player.permission_group.allows_action(defines.input_action.toggle_map_editor)) +end + return main