try to fix some stuff
This commit is contained in:
@@ -139,6 +139,10 @@ func _detect_trap(detecting_player: Node) -> void:
|
||||
# Make trap visible
|
||||
sprite.modulate.a = 1.0
|
||||
|
||||
# Notify the detecting player to show alert and play sound
|
||||
if detecting_player and is_instance_valid(detecting_player) and detecting_player.has_method("_on_trap_detected"):
|
||||
detecting_player._on_trap_detected()
|
||||
|
||||
# Sync detection to all clients (including server with call_local)
|
||||
# CRITICAL: Validate trap is still valid before sending RPC
|
||||
# Use GameWorld RPC to avoid node path issues
|
||||
@@ -260,15 +264,18 @@ func _complete_disarm() -> void:
|
||||
# Change trap visual to show it's disarmed (optional - could fade out or change color)
|
||||
sprite.modulate = Color(0.5, 0.5, 0.5, 0.5)
|
||||
|
||||
# Sync disarm to all clients
|
||||
# CRITICAL: Validate trap is still valid before sending RPC
|
||||
# Use GameWorld RPC to avoid node path issues
|
||||
# Sync disarm to all clients (including host when joiner disarms)
|
||||
if multiplayer.has_multiplayer_peer() and is_inside_tree() and is_instance_valid(self):
|
||||
if multiplayer.is_server():
|
||||
# Use GameWorld RPC with trap name instead of path
|
||||
var game_world = get_tree().get_first_node_in_group("game_world")
|
||||
if game_world and game_world.has_method("_sync_trap_state_by_name"):
|
||||
game_world._sync_trap_state_by_name.rpc(name, true, true) # detected=true, disarmed=true
|
||||
var game_world = get_tree().get_first_node_in_group("game_world")
|
||||
if game_world:
|
||||
if multiplayer.is_server():
|
||||
# Host disarmed: broadcast to clients
|
||||
if game_world.has_method("_sync_trap_state_by_name"):
|
||||
game_world._sync_trap_state_by_name.rpc(name, true, true) # detected=true, disarmed=true
|
||||
else:
|
||||
# Joiner disarmed: request host to apply locally and broadcast to all
|
||||
if game_world.has_method("_request_trap_disarm"):
|
||||
game_world._request_trap_disarm.rpc_id(1, name)
|
||||
|
||||
print("Trap disarmed!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user