From 3df8b8af093e34e8a67a3917e3b986835beced3f Mon Sep 17 00:00:00 2001 From: Qatavin <108201496+Qatavin@users.noreply.github.com> Date: Wed, 11 Mar 2026 19:46:18 -0700 Subject: [PATCH 1/5] Fixes and features for Classes --- bobclasses/control.lua | 109 +++++++++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 31 deletions(-) diff --git a/bobclasses/control.lua b/bobclasses/control.lua index ef44905d8..4f7ba3e65 100644 --- a/bobclasses/control.lua +++ b/bobclasses/control.lua @@ -277,6 +277,9 @@ function init() if not storage.respawn_inventory then storage.respawn_inventory = {} end + if not storage.god_inventories then + storage.god_inventories = {} + end storage.classes["bob-ballanced"] = nil storage.classes["bob-balanced"] = nil @@ -592,6 +595,15 @@ end) script.on_event(defines.events.on_player_created, function(event) wlog("Entered event handler on_player_created(" .. serpent.line(event) .. ")") + + if not storage.god_start then + storage.god_start = false + end + + if game.players[event.player_index].controller_type == defines.controllers.god then + storage.god_start = true + end + create_button(event.player_index) storage.players[event.player_index] = { respawn = false, first_character = true } class_select(event.player_index) @@ -1061,7 +1073,7 @@ function draw_buttons_row(player_index) end if not game.is_multiplayer or player.admin then - if settings.global["bobmods-classes-god-mode"].value then + if settings.global["bobmods-classes-god-mode"].value or storage.god_start == true then gui.add({ type = "button", name = "bob_avatar_god", @@ -1393,14 +1405,24 @@ function create_character(player_index, class) if storage.players[player_index].first_character then for i, item in pairs(storage.starting_inventory) do - player.insert(item) + if prototypes.item[item.name] then + player.insert(item) + end end if class.starting_inventory then for i, item in pairs(class.starting_inventory.add) do - player.insert(item) + if prototypes.item[item.name] then + player.insert(item) + end end for i, item in pairs(class.starting_inventory.replace) do - if item.remove and item.add and player.get_item_count(item.remove.name) >= item.remove.count then + if + item.remove + and item.add + and prototypes.item[item.remove.name] + and prototypes.item[item.add.name] + and player.get_item_count(item.remove.name) >= item.remove.count + then player.remove_item(item.remove) player.insert(item.add) end @@ -1409,14 +1431,24 @@ function create_character(player_index, class) storage.players[player_index].first_character = false elseif storage.players[player_index].respawn then for i, item in pairs(storage.respawn_inventory) do - player.insert(item) + if prototypes.item[item.name] then + player.insert(item) + end end if class.respawn_inventory.replace then for i, item in pairs(class.respawn_inventory.add) do - player.insert(item) + if prototypes.item[item.name] then + player.insert(item) + end end for i, item in pairs(class.respawn_inventory.replace) do - if item.remove and item.add and player.get_item_count(item.remove.name) >= item.remove.count then + if + item.remove + and item.add + and prototypes.item[item.remove.name] + and prototypes.item[item.add.name] + and player.get_item_count(item.remove.name) >= item.remove.count + then player.remove_item(item.remove) player.insert(item.add) end @@ -1459,6 +1491,9 @@ function switch_character(player_index, new_character) if player.controller_type == defines.controllers.editor then player.toggle_map_editor() --safety restores the character entity. end + if player.controller_type == defines.controllers.god then + storage.god_inventories[player.name] = player.get_inventory(defines.inventory.god_main).get_contents() --Saves god controller's inventory in a table labeled with the player's user name to avoid multiplayer issues + end if remote.interfaces["space-exploration"] then remote.call("space-exploration", "remote_view_stop", { player = player }) --Attempt to safe exit SatNav mode end @@ -1522,32 +1557,44 @@ end function switch_to_god(player_index, old_char) wlog("Entered function switch_to_god(" .. player_index .. ")") - --~ local old_character = game.players[player_index].character - local old_character = old_char or game.players[player_index].character - game.players[player_index].set_controller({ type = defines.controllers.god }) - if old_character then - game.players[player_index].associate_character(old_character) - end + if game.players[player_index].controller_type ~= defines.controllers.god then --Do nothing if already using god controller. Avoids issues with inventory reset. - -- Skip this if called with old_char, i.e. if this function is called in response - -- to changes by another mod. If another mod toggled editor/god mode, it's their - -- responsibility to announce the change. - if not old_char then - -- Notify other mods that a character has been exchanged - --~ announce("minime", {old = old_character}) - announce("minime", { - old_character = old_character, - old_unit_number = old_character and old_character.unit_number, - player_index = player_index, - god_mode = true, - }) - announce("jetpack", { - old_character = old_character, - old_character_unit_number = old_character and old_character.unit_number, - }) - end + --~ local old_character = game.players[player_index].character + local old_character = old_char or game.players[player_index].character + game.players[player_index].set_controller({ type = defines.controllers.god }) + if old_character then + game.players[player_index].associate_character(old_character) + end - refresh_avatar_gui(player_index) + -- Skip this if called with old_char, i.e. if this function is called in response + -- to changes by another mod. If another mod toggled editor/god mode, it's their + -- responsibility to announce the change. + if not old_char then + -- Notify other mods that a character has been exchanged + --~ announce("minime", {old = old_character}) + announce("minime", { + old_character = old_character, + old_unit_number = old_character and old_character.unit_number, + player_index = player_index, + god_mode = true, + }) + announce("jetpack", { + old_character = old_character, + old_character_unit_number = old_character and old_character.unit_number, + }) + end + + if storage.god_inventories[game.players[player_index].name] then + for i, items in pairs(storage.god_inventories[game.players[player_index].name]) do + if prototypes.item[items.name] then + game.players[player_index].insert(items) + end + end + end + + refresh_avatar_gui(player_index) + + end end --Switches to the editor controller, then adds the connected character to the (end of the) association list. From 91ec802597fe892349c74a5ce339b42459a7ce7c Mon Sep 17 00:00:00 2001 From: Qatavin <108201496+Qatavin@users.noreply.github.com> Date: Wed, 11 Mar 2026 20:07:54 -0700 Subject: [PATCH 2/5] Update bobclasses.cfg --- bobclasses/locale/en/bobclasses.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bobclasses/locale/en/bobclasses.cfg b/bobclasses/locale/en/bobclasses.cfg index e1bec52fd..b53def73a 100644 --- a/bobclasses/locale/en/bobclasses.cfg +++ b/bobclasses/locale/en/bobclasses.cfg @@ -122,7 +122,7 @@ bob-avatar-minimap=Opens a minimap of this character's location. bob-avatar-seticon=Click here while holding an item to set it as a character's icon bob-avatar-god-mode=God mode -bob-avatar-god-mode-tooltip=God mode is where you have free camera movement without controlling a character.\nWarning: God mode inventory is lost when switching to another mode.\nWarning: if your body is killed while you are in god mode, it won't respawn. +bob-avatar-god-mode-tooltip=God mode is where you have free camera movement without controlling a character.\nWarning: if your body is killed while you are in god mode, it won't respawn. bob-avatar-editor-mode=Editor mode bob-avatar-editor-mode-tooltip=In editor mode, you are disconnected from a character and have full scenario editor controls.\nWarning: if your body is killed while you are in editor mode, it won't respawn. bob-avatar-class-select=Select class From 5ae183060a596a852e6295bd18ff46b9a049f098 Mon Sep 17 00:00:00 2001 From: Qatavin <108201496+Qatavin@users.noreply.github.com> Date: Sun, 29 Mar 2026 19:35:12 -0700 Subject: [PATCH 3/5] Remove editor mode from Classes --- bobclasses/control.lua | 64 +----------------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/bobclasses/control.lua b/bobclasses/control.lua index 4f7ba3e65..1fce89c6a 100644 --- a/bobclasses/control.lua +++ b/bobclasses/control.lua @@ -214,18 +214,13 @@ function minime_exchanged_characters(event) local player_index = event.player_index local old_character = event.old_character local new_character = event.new_character - local editor = event.editor_mode local god = event.god_mode -- Switch to another character - if new_character and not (editor or god) then + if new_character and not god then wlog("Calling refresh_avatar_gui(" .. player_index .. ")") refresh_avatar_gui(player_index) - -- Enter editor mode - elseif editor then - wlog("Calling switch_to_editor(" .. player_index .. ", " .. tostring(old_character and old_character.name) .. ")") - switch_to_editor(player_index, old_character) -- Enter god mode elseif god then wlog("Calling switch_to_god(" .. player_index .. ", " .. tostring(old_character and old_character.name) .. ")") @@ -681,7 +676,6 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) if event.setting_type == "runtime-global" then if event.setting == "bobmods-classes-god-mode" - or event.setting == "bobmods-classes-editor-mode" or event.setting == "bobmods-classes-class-select" or event.setting == "bobmods-classes-class-select-user" then @@ -771,9 +765,6 @@ script.on_event(defines.events.on_gui_click, function(event) if event.element.valid and event.element.name == "bob_avatar_god" then switch_to_god(event.player_index) end - if event.element.valid and event.element.name == "bob_avatar_editor" then - switch_to_editor(event.player_index) - end if event.element.valid and event.element.name == "bob_avatar_class_select" then draw_class_gui(event.player_index) end @@ -1082,15 +1073,6 @@ function draw_buttons_row(player_index) }) gui.bob_avatar_god.style.minimal_width = 56 end - if settings.global["bobmods-classes-editor-mode"].value then - gui.add({ - type = "button", - name = "bob_avatar_editor", - caption = { "gui.bob-avatar-editor-mode" }, - tooltip = { "gui.bob-avatar-editor-mode-tooltip" }, - }) - gui.bob_avatar_editor.style.minimal_width = 56 - end end if ((not game.is_multiplayer or player.admin) and settings.global["bobmods-classes-class-select"].value) @@ -1596,47 +1578,3 @@ function switch_to_god(player_index, old_char) end end - ---Switches to the editor controller, then adds the connected character to the (end of the) association list. --- Added optional argument old_char. Per default, the player's current character will be used, but --- if this function is called from a remote function, this allows to pass on a different character. ---~ function switch_to_editor(player_index) -function switch_to_editor(player_index, old_char) - wlog("Entered function switch_to_editor(" .. player_index .. ", " .. tostring(old_char and old_char.name) .. ")") - wlog( - string.format("Controller of player %s: %s", player_index, controllers[game.players[player_index].controller_type]) - ) - - --~ local old_character = game.players[player_index].character - local old_character = old_char or game.players[player_index].character - game.players[player_index].set_controller({ type = defines.controllers.editor }) - wlog( - string.format( - "Controller of player %s after change: %s", - player_index, - controllers[game.players[player_index].controller_type] - ) - ) - if old_character then - game.players[player_index].associate_character(old_character) - end - - -- Skip this if called with old_char, i.e. if this function is called in response - -- to changes by another mod. If another mod toggled editor/god mode, it's their - -- responsibility to announce the change. - if not old_char then - -- Notify other mods that a character has been exchanged - announce("minime", { - old_character = old_character, - old_unit_number = old_character and old_character.unit_number, - player_index = player_index, - editor_mode = true, - }) - announce("jetpack", { - old_character = old_character, - old_character_unit_number = old_character and old_character.unit_number, - }) - end - - refresh_avatar_gui(player_index) -end From f5b64e63ceacd81cfebda7f81151918e8e2e61c1 Mon Sep 17 00:00:00 2001 From: Qatavin <108201496+Qatavin@users.noreply.github.com> Date: Sun, 29 Mar 2026 19:35:41 -0700 Subject: [PATCH 4/5] Update settings.lua --- bobclasses/settings.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bobclasses/settings.lua b/bobclasses/settings.lua index 177a77516..cc666572b 100644 --- a/bobclasses/settings.lua +++ b/bobclasses/settings.lua @@ -5,12 +5,6 @@ data:extend({ setting_type = "runtime-global", default_value = false, }, - { - type = "bool-setting", - name = "bobmods-classes-editor-mode", - setting_type = "runtime-global", - default_value = false, - }, { type = "bool-setting", name = "bobmods-classes-class-select", From 3dbec6957fdd128b726432c5fa88191c611574f5 Mon Sep 17 00:00:00 2001 From: Qatavin <108201496+Qatavin@users.noreply.github.com> Date: Sun, 29 Mar 2026 19:38:31 -0700 Subject: [PATCH 5/5] Update bobclasses.cfg --- bobclasses/locale/en/bobclasses.cfg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bobclasses/locale/en/bobclasses.cfg b/bobclasses/locale/en/bobclasses.cfg index b53def73a..54ac73e1c 100644 --- a/bobclasses/locale/en/bobclasses.cfg +++ b/bobclasses/locale/en/bobclasses.cfg @@ -124,7 +124,7 @@ bob-avatar-seticon=Click here while holding an item to set it as a character's i bob-avatar-god-mode=God mode bob-avatar-god-mode-tooltip=God mode is where you have free camera movement without controlling a character.\nWarning: if your body is killed while you are in god mode, it won't respawn. bob-avatar-editor-mode=Editor mode -bob-avatar-editor-mode-tooltip=In editor mode, you are disconnected from a character and have full scenario editor controls.\nWarning: if your body is killed while you are in editor mode, it won't respawn. +bob-avatar-editor-mode-tooltip=In editor mode, you are disconnected from a character and have full scenario editor controls. bob-avatar-class-select=Select class bob-avatar-class-select-tooltip=Opens the class select window. @@ -135,13 +135,11 @@ bob-current-character=Current: [mod-setting-name] bobmods-classes-god-mode=Admin button "God mode" -bobmods-classes-editor-mode=Admin button "Editor mode" bobmods-classes-class-select=Admin button "Class select" bobmods-classes-class-select-user=User button "Class select" [mod-setting-description] bobmods-classes-god-mode=If enabled (requires being an admin if you're in multiplayer) then the button "God mode" will show on the Avatar switcher window -bobmods-classes-editor-mode=If enabled (requires being an admin if you're in multiplayer) then the button "Editor mode" will show on the Avatar switcher window bobmods-classes-class-select=If enabled (requires being an admin if you're in multiplayer) then the button "Class select" will show on the Avatar switcher window bobmods-classes-class-select-user=If enabled (all users) then the button "Class select" will show on the Avatar switcher window