Skip to content

Commit

Permalink
Store just the name for now when registering but pass an ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makosai committed Jan 1, 2024
1 parent 974bdcc commit 0eb8475
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/managers/multiplayer/multiplayer_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ var _players = {}
#endregion

#region Core Funcs
class TestPlayer:
var name: String

func _init(_name: String):
name = _name
# ...
#endregion


#region Server only
## When a player connects, tell all of the other players
## their information.
@rpc("authority", "reliable")
func register_player(player_name: String):
func register_player(id: int, player_name: String):
var player_id = multiplayer.get_remote_sender_id()
_players[player_id] = TestPlayer.new(player_name)
_players[player_id] = player_name # Store the ID and name and spawn a player with the ID to match.
player_connected.emit()
#endregion

#region Client -> Server
@rpc("any_peer", "call_local", "reliable")
func update_name(player_name: String):
if multiplayer.is_server():
register_player.rpc_id(1, player_name) # Tell the server... SAY MY NAME!
var player_id = multiplayer.get_remote_sender_id()
register_player.rpc(player_id, player_name)
else:
update_name.rpc_id(1, player_name) # Tell the server... SAY MY NAME!
#endregion

0 comments on commit 0eb8475

Please sign in to comment.