fix bot issues : Prevent bot creation when enable_bots is false

This commit is contained in:
2025-04-22 10:34:08 +08:00
parent d397ef0931
commit f8521a78ff
2 changed files with 68 additions and 27 deletions
+13 -12
View File
@@ -385,10 +385,10 @@ func _on_host_pressed():
# Sync goals to all clients after host is set up
rpc("sync_preset_goals", preset_goals)
# Only add bots if enable_bots is true
# Only add bots if enable_bots is true and we need them
if enable_bots:
# Add bots with their own goals
for i in range(2, max_players + 1):
var needed_bots = max_players - 1 # -1 for the host
for i in range(2, needed_bots + 2): # +2 because we start from ID 2
add_bot(i)
start_game()
@@ -644,7 +644,9 @@ func _on_peer_disconnected(peer_id):
if multiplayer.is_server():
connected_peer_ids.erase(peer_id)
players.erase(peer_id)
add_bot(get_next_available_bot_id())
# Only add replacement bot if bots are enabled
if enable_bots:
add_bot(get_next_available_bot_id())
@rpc("any_peer", "call_local")
func add_player_character(peer_id):
@@ -735,6 +737,13 @@ func add_bot(bot_id):
@rpc("call_local")
func create_bot(bot_id):
# First check if bots are enabled
if not enable_bots:
print("Attempted to create bot while bots are disabled")
return
# Ensure we're not duplicating bots
if has_node(str(bot_id)):
push_error("Bot already exists: " + str(bot_id))
@@ -755,14 +764,6 @@ func create_bot(bot_id):
bot_character.add_to_group("Players", true)
bot_character.add_to_group("Bots", true)
if not enable_bots:
bot_character.set_process(false)
bot_character.set_physics_process(false)
# Disable Beehave tree if it exists
var behavior_tree = bot_character.get_node_or_null("BehaviorTree")
if behavior_tree:
behavior_tree.enabled = false
if multiplayer.is_server():
bots.append(bot_id)
players.append(bot_id)