Created
February 27, 2026 23:07
-
-
Save twobob/2cfaafc320ee0fce2f00f64e03da215d to your computer and use it in GitHub Desktop.
if you need to pass extra stuff to spawn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends MultiplayerSpawner | |
| # Example of packing multiple data points into the single allowed argument | |
| func trigger_player_spawn(id: int, spawn_pos: Vector2, player_name: String): | |
| var spawn_data = { | |
| "id": id, | |
| "position": spawn_pos, | |
| "name": player_name | |
| } | |
| # Call spawn with the single dictionary argument | |
| self.spawn(spawn_data) | |
| # Cleanup logic with null checks | |
| func _on_player_disconnect(id: int): | |
| # Ensure the parent/container node exists before calling get_children() | |
| var player_container = get_node_or_null("/root/Main/Players") | |
| if player_container: | |
| for player in player_container.get_children(): | |
| if player.name == str(id): | |
| player.queue_free() | |
| break | |
| else: | |
| printerr("Error: player_container is null in _on_player_disconnect") | |
| # Implementation of the custom spawn processing | |
| func _init(): | |
| self.spawn_function = _custom_spawn_logic | |
| func _custom_spawn_logic(data: Variant) -> Node: | |
| # Unpack the dictionary passed from trigger_player_spawn | |
| var player_scene = preload("res://player.tscn").instantiate() | |
| player_scene.name = str(data["id"]) | |
| player_scene.position = data["position"] | |
| # Assign other data as needed | |
| return player_scene |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment