First Map Tests, Player + Movement and Spawning.
This commit is contained in:
parent
1351ce3178
commit
c483a438c7
7 changed files with 145 additions and 8 deletions
|
@ -14,6 +14,7 @@ var max_clients: int = 1024
|
|||
|
||||
var roomname: String = "sample"
|
||||
var username: String = "sample"
|
||||
var mapname: String = "Testmap"
|
||||
|
||||
func _ready() -> void:
|
||||
var args: PackedStringArray = OS.get_cmdline_args()
|
||||
|
|
|
@ -240,15 +240,40 @@ func send_playerlist(status: int, newPeers: Dictionary) -> void:
|
|||
## General Game RPCs
|
||||
|
||||
# Does RPCs to all clients.
|
||||
func send_rpcs(method: String, args: Array) -> void:
|
||||
func get_ids() -> Array:
|
||||
var ret: Array = []
|
||||
for peer: String in peers:
|
||||
var id: int = peers[peer]
|
||||
if rpc_id(id, method, args) != OK:
|
||||
Log.warning("Failed to send the rpc %s to %d." % [method, id])
|
||||
ret.append(peers[peer])
|
||||
return ret
|
||||
|
||||
func verify_id(id: int) -> bool:
|
||||
if id in get_ids():
|
||||
return true
|
||||
return false
|
||||
|
||||
func start_game_call() -> void:
|
||||
for peer: int in Networking.get_ids():
|
||||
if rpc_id(peer, "start_game") != OK:
|
||||
Log.warning("Couldn't send RPC to %d!" % peer)
|
||||
|
||||
# Starts the game.
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func start_game() -> void:
|
||||
if multiplayer.get_remote_sender_id() == managerID:
|
||||
if !get_tree().change_scene_to_file("res://scenes/maps/testmap.tscn"):
|
||||
if get_tree().change_scene_to_file("res://scenes/maps/testmap.tscn") != OK:
|
||||
Log.warning("Couldn't load the map!")
|
||||
|
||||
func player_sync_call(position: Vector3, rotation: Vector3) -> void:
|
||||
for peer: int in Networking.get_ids():
|
||||
if rpc_id(peer, "player_sync", position, rotation) != OK:
|
||||
Log.warning("Couldn't send RPC to %d!" % peer)
|
||||
|
||||
# Starts the game.
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func player_sync(position: Vector3, rotation: Vector3) -> void:
|
||||
if verify_id(multiplayer.get_remote_sender_id()):
|
||||
for peer: String in peers:
|
||||
if peers[peer] == multiplayer.get_remote_sender_id() and has_node("/root/"+Game.mapname+"/"+peer):
|
||||
var player: CharacterBody3D = get_node("/root/"+Game.mapname+"/"+peer)
|
||||
player.position = position
|
||||
player.rotation = rotation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue