Godot 4.4.1
The rpc(“authority”) is not doing what it should, in the game player 2 presses the button and calls p.rpc_id(1) lost for player 1 to execute the function but it is player 2 who executes it and gets excluded. And in ready, player 1 shows 1 in everything and true in the tree, for player 2 the same thing. And I am spawning them through the multiplayer spawn node and each player can control themselves. Does anyone know why this is happening?
func _enter_tree() -> void:
set_multiplayer_authority(int(name))
func _ready() -> void:
print("id: ", multiplayer.get_unique_id())
print("autoridade2: ", get_multiplayer_authority())
print("autoridade: ", is_multiplayer_authority())
print("Arvore:", is_inside_tree())
@rpc("authority","reliable")
func p():
print("RECEBEU DE QUEM: ", multiplayer.get_remote_sender_id())
print("OLA ID: ",multiplayer.get_unique_id(), " Name: ", get_name(), " id2: " , get_multiplayer_authority())
queue_free()
func _physics_process(_delta: float) -> void:
if !is_multiplayer_authority():return
if Input.is_action_just_pressed("B2"):
p.rpc_id(1)
Print1(2)
Print2(1,2,2)
Multiplayer
extends Node
const IPPRADRAO = "WIFI"
const PORTA = 6007
const MAXPLAYER = 5
var par = null
signal JogadorConectado
func criarServe():
par = ENetMultiplayerPeer.new()
par.create_server(PORTA, MAXPLAYER)
multiplayer.multiplayer_peer = par
multiplayer.peer_connected.connect(self.parConectado)
func entraServe():
par = ENetMultiplayerPeer.new()
par.create_client(IPPRADRAO, PORTA)
multiplayer.multiplayer_peer = par
func parConectado(parID):
emit_signal("JogadorConectado", parID)
Spawn
@onready var jogador = preload("res://Cenas/jogador.tscn")
func _ready() -> void:
if multiplayer.is_server():
spawn(multiplayer.get_unique_id())
MultiMundo.JogadorConectado.connect(self.spawn)
func spawn(paID):
var obj = jogador.instantiate()
obj.name = str(paID)
add_child(obj)