project_teddy/scripts/networking.gd
2023-02-21 12:53:13 -07:00

35 lines
1.1 KiB
GDScript

extends Node
var peer = ENetMultiplayerPeer.new()
var SCENE = "res://scenes/playground.tscn"
func create_server(port, maxPlayers):
var result = peer.create_server(port, maxPlayers) # Second paramater specifies the player limit. Can be anything between 1 and 4095
multiplayer.multiplayer_peer = peer
prints("Creating server result:", result)
if result == OK:
print("Server should be listening on port: ", port)
elif result == ERR_ALREADY_IN_USE:
printerr("Port is being used by something else!")
else:
printerr("Server can't start, and idk the problem")
peer.peer_connected.connect(
func(new_peer_id):
print("NEW CONNECTION FROM ", new_peer_id)
#await get_tree().create_timer(1).timeout ## Might not be required anymore...
#add_newly_connected_player_character()
rpc("add_newly_connected_player_character")
)
func load_map(map):
Global.multiplayerCurrent = true
get_tree().change_scene_to_file(map)
@rpc("any_peer", "call_remote")
func add_newly_connected_player_character():
print("add_newly_connected_player_character() has been run!")
load_map(SCENE)