Changed what is called via rpc on death. Now die() is called via rpc on all instances of Player's node, instead of previously destroy_player() being called this way for ma single die() call on a killer's local Player puppet

This commit is contained in:
unfa 2021-09-19 20:51:47 +02:00
parent 614d6a3b80
commit 36343d2d92
3 changed files with 30 additions and 17 deletions

View file

@ -127,7 +127,11 @@ func _input(event) -> void:
if not input_active:
return
assert(is_multiplayer_authority() == true, "input_active is true, even though the node is not multiplayer_authority")
#assert(is_multiplayer_authority() == true, "input_active is true, even though the node is not multiplayer_authority")
if is_multiplayer_authority() == false:
print("Input is active, but we're not the authority. WTF?!")
input_active = false
return
if Input.is_action_just_pressed("view_zoom"):
# tween.remove_all()
@ -167,7 +171,12 @@ func _process(delta):
if not input_active:
return
assert(is_multiplayer_authority() == true, "input_active is true, even though the node is not multiplayer_authority")
#assert(is_multiplayer_authority() == true, "input_active is true, even though the node is not multiplayer_authority")
if is_multiplayer_authority() == false:
print("input_active is true, while we're not the authority. WTF?")
input_active = false
return
if view_zoom_direction and view_zoom < view_zoom_target:
view_zoom = min(view_zoom_target, view_zoom + delta * 4)
@ -179,18 +188,19 @@ func damage(hp: int):
var target = main.player_list.players[self.get_multiplayer_authority()]
target.health -= hp
func die(killer_pid: int):
@rpc(any, nosync, reliable) func die(killer_pid: int):
var gibs = gibs_vfx.instantiate()
get_tree().root.add_child(gibs)
gibs.global_transform = self.global_transform#
gibs.global_transform = self.global_transform
#if get_tree().get_rpc_sender_id() != get_multiplayer_authority():
# print ("Death requested by a non-master. Ignoring")
# return
main.rpc(&'destroy_player', self.get_multiplayer_authority())
#main.rpc(&'destroy_player', self.get_multiplayer_authority())
main.destroy_player(self.get_multiplayer_authority())
#main.chat.rpc(&'chat_notification', "Player [/i][b][color=" + main.player_list.players[self.get_multiplayer_authority()].color.to_html() + "]" + main.player_list.players[self.get_multiplayer_authority()].name + "[/color][/b][i] was killed by " + main.player_list.players[killer_pid].name )
main.chat.chat_notification("Player [/i][b][color=" + main.player_list.players[self.get_multiplayer_authority()].color.to_html() + "]" + main.player_list.players[self.get_multiplayer_authority()].name + "[/color][/b][i] was killed by " + main.player_list.players[killer_pid].name )
main.chat.rpc(&'chat_notification', "Player [/i][b][color=" + main.player_list.players[self.get_multiplayer_authority()].color.to_html() + "]" + main.player_list.players[self.get_multiplayer_authority()].name + "[/color][/b][i] was killed by " + main.player_list.players[killer_pid].name )
#queue_free()
func update_player(info) -> void:

View file

@ -19,7 +19,7 @@ var impact_player = preload("res://Assets/Effects/ImpactBlood.tscn")
#enum Trigger {TRIGGER_PRIMARY, TRIGGER_SECONDARY}
@rpc(sync) func shoot():
@rpc(any, sync, reliable) func shoot():
#print("SHOOT from PID ", get_tree().multiplayer.get_multiplayer_unique_id(), " controlled by ", player.get_multiplayer_authority())
var space_state = get_world_3d().direct_space_state
@ -39,7 +39,7 @@ var impact_player = preload("res://Assets/Effects/ImpactBlood.tscn")
#print("SHOT HIT ", ray['collider'])
ray['collider'].damage(20) # apply damage
if main.player_list.get(ray['collider'].get_multiplayer_authority()).health <= 0: # if he ded
ray['collider'].die(self.get_multiplayer_authority())
ray['collider'].rpc(&'die', self.get_multiplayer_authority())
main.player_list.players[player.get_multiplayer_authority()].score += 1 # give the killer a point
main.rpc(&'player_list_update', main.player_list.get(player.get_multiplayer_authority()).serialize(), player.get_multiplayer_authority())
@ -63,9 +63,8 @@ var impact_player = preload("res://Assets/Effects/ImpactBlood.tscn")
#print(ray)
@rpc(sync, auth) func trigger(index: int, active: bool) -> void:
func trigger(index: int, active: bool) -> void:
#print("Weapon " + str(name) + ", Trigger " + str(index) + ", active: " + str(active))
if index == 0 and active and $Handgun/AnimationPlayer.is_playing() == false:
rpc(&'shoot')

View file

@ -203,16 +203,20 @@ func push_local_player_info(): #
rpc(&'player_list_update', player_list.get(id).serialize(), get_tree().multiplayer.get_unique_id())
@rpc(sync,auth,reliable) func destroy_player(pid: int):
assert($Players.has_node(str(pid)), "Attempting to destroy a player that does not exist")
@rpc func destroy_player(pid: int):
print("DESTROY_PLAYER called on ", get_tree().multiplayer.get_unique_id(), " by ", get_tree().multiplayer.get_remote_sender_id(), " regarding ", pid)
var player_node = $Players.get_node(str(pid))
#assert($Players.has_node(str(pid)), "Attempting to destroy a player that does not exist")
var player_node
if not player_node: # TODO find the reason for hitting the assert - thsi is a temporary workaround
if $Players.has_node(str(pid)):
player_node = $Players.get_node(str(pid))
else:
print("Destroying a player node that's not there")
return
assert(player_node != null, "Attempting to delete a player node that does not exist")
#assert(player_node != null, "Attempting to delete a player node that does not exist")
player_node.name = str(player_node.name) + "_dead" # avoids name collision when instancing another player scene
player_node.queue_free()