forked from unfa/liblast
Fixed player names not being set.
parent
25f5fbc1e9
commit
e35849899a
60
Game/Main.gd
60
Game/Main.gd
|
@ -31,11 +31,11 @@ class PlayerInfo:
|
|||
var score: int
|
||||
|
||||
func _init():#name: String, team: int, color: Color):
|
||||
var player_name = ""
|
||||
for i in range(0, 4):
|
||||
player_name += ['a','b','c', 'd', 'e', 'f'][randi() % 5]
|
||||
self.name = player_name
|
||||
self.color = Color(randf(),randf(),randf())
|
||||
# var player_name = ""
|
||||
# for i in range(0, 4):
|
||||
# player_name += ['a','b','c', 'd', 'e', 'f'][randi() % 5]
|
||||
self.name = ""#player_name
|
||||
self.color = Color.WHITE #Color(randf(),randf(),randf())
|
||||
self.team = 0
|
||||
self.focus = 999
|
||||
self.health = 100
|
||||
|
@ -257,7 +257,6 @@ func update_hud():
|
|||
|
||||
func push_local_player_info(): #
|
||||
var pid = get_tree().multiplayer.get_unique_id()
|
||||
|
||||
rpc(&'player_list_update', player_list.get(pid).serialize(), pid)
|
||||
|
||||
@rpc(sync, any, reliable) func destroy_player(pid: int):
|
||||
|
@ -297,7 +296,7 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
|
|||
var player_node
|
||||
if $Players.has_node(str(pid)): # if this is a respawn
|
||||
player_node = $Players.get_node(str(pid))
|
||||
print("Setting player ", pid, " as ALIVE")
|
||||
#print("Setting player ", pid, " as ALIVE")
|
||||
player_node.set_dead(false)
|
||||
|
||||
var spawnpoint = $Map/SpawnPoints.get_children()[randi() % len($Map/SpawnPoints.get_children())]
|
||||
|
@ -318,16 +317,29 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
|
|||
new_player.set_multiplayer_authority(pid)
|
||||
$Players.add_child(new_player)
|
||||
|
||||
var new_info: PlayerInfo
|
||||
|
||||
if not respawn: # first spawn
|
||||
new_info = PlayerInfo.new() # generate name, color etc
|
||||
else: # respawn
|
||||
new_info = player_list.players[pid] # reuse previous name, color etc
|
||||
new_info.health = 100 # give the respawned player full health
|
||||
focus = GameFocus.GAME # make sure the player has no menu displayed when they respawn
|
||||
|
||||
if not respawn and is_local:
|
||||
var new_info = PlayerInfo.new()
|
||||
new_info.name = $GUI.settings["username"]
|
||||
new_info.color = $GUI.settings["player color"]
|
||||
player_list.set(pid, new_info)
|
||||
push_local_player_info()
|
||||
|
||||
if is_local:
|
||||
local_player = new_player
|
||||
|
||||
|
||||
|
||||
# if not respawn: # first spawn
|
||||
# new_info = PlayerInfo.new()
|
||||
# if is_local:
|
||||
# new_info.name = $GUI.settings["username"]
|
||||
# new_info.color = $GUI.settings["player color"]
|
||||
# else: # respawn
|
||||
# new_info = player_list.players[pid] # reuse previous name, color etc
|
||||
# new_info.health = 100 # give the respawned player full health
|
||||
# focus = GameFocus.GAME # make sure the player has no menu displayed when they respawn
|
||||
|
||||
|
||||
|
||||
# superfluous and harmful code that messes up player data:
|
||||
# if get_tree().multiplayer.get_multiplayer_unique_id() != 1: # if we're not the server - update the server
|
||||
|
@ -335,18 +347,10 @@ func create_player(pid: int, is_local:= false, respawn:= false) -> void:
|
|||
# else: # if we're the server, update the clients
|
||||
# rpc(&'player_list_update', new_info.serialize(), pid)
|
||||
|
||||
if is_local:
|
||||
local_player = new_player #$Players.get_node(str(id))
|
||||
# local_player.get_node("Head/Camera").current = true
|
||||
$NetworkTesting/TextEdit.text = new_info.name
|
||||
$NetworkTesting/ColorPickerButton.color = new_info.color
|
||||
#local_player.rpc(&'set_color', new_info.color)
|
||||
# elif local_player: # if there is a local player, make sure we keep using it's camera
|
||||
# new_player.get_node("Head/Camera").current = false
|
||||
# local_player.get_node("Head/Camera").current = true
|
||||
#new_player.rpc(&'set_color', player_list.get(pid).color)
|
||||
|
||||
#update_hud()
|
||||
# if is_local:
|
||||
# local_player = new_player
|
||||
# if not get_tree().multiplayer.is_server():
|
||||
# push_local_player_info()
|
||||
|
||||
func start_dedicated_server(): # start server without creating a local player
|
||||
role = MultiplayerRole.DEDICATED_SERVER
|
||||
|
|
Loading…
Reference in New Issue