fix loot mesage for joiner

This commit is contained in:
2026-01-11 04:41:05 +01:00
parent 464f499b36
commit 3adf6660bb

View File

@@ -364,6 +364,9 @@ func _process_pickup_on_server(player: Node):
# Show floating text with item graphic and text # Show floating text with item graphic and text
var coin_texture = load("res://assets/gfx/pickups/gold_coin.png") var coin_texture = load("res://assets/gfx/pickups/gold_coin.png")
_show_floating_text(player, "+" + str(coin_value) + " COIN", Color(1.0, 0.84, 0.0), 0.5, 0.5, coin_texture, 6, 1, 0) _show_floating_text(player, "+" + str(coin_value) + " COIN", Color(1.0, 0.84, 0.0), 0.5, 0.5, coin_texture, 6, 1, 0)
# Sync floating text to client
if multiplayer.has_multiplayer_peer() and player.get_multiplayer_authority() != 1:
_sync_show_floating_text.rpc_id(player.get_multiplayer_authority(), loot_type, "+" + str(coin_value) + " COIN", Color(1.0, 0.84, 0.0), coin_value, 0, player.get_multiplayer_authority())
self.visible = false self.visible = false
@@ -382,6 +385,9 @@ func _process_pickup_on_server(player: Node):
# Show floating text with item graphic and heal amount # Show floating text with item graphic and heal amount
var items_texture = load("res://assets/gfx/pickups/items_n_shit.png") var items_texture = load("res://assets/gfx/pickups/items_n_shit.png")
_show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 10) _show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 10)
# Sync floating text to client
if multiplayer.has_multiplayer_peer() and player.get_multiplayer_authority() != 1:
_sync_show_floating_text.rpc_id(player.get_multiplayer_authority(), loot_type, "+" + str(int(actual_heal)) + " HP", Color.GREEN, int(actual_heal), (8 * 20) + 10, player.get_multiplayer_authority())
self.visible = false self.visible = false
@@ -400,6 +406,9 @@ func _process_pickup_on_server(player: Node):
# Show floating text with item graphic and heal amount # Show floating text with item graphic and heal amount
var items_texture = load("res://assets/gfx/pickups/items_n_shit.png") var items_texture = load("res://assets/gfx/pickups/items_n_shit.png")
_show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 11) _show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 11)
# Sync floating text to client
if multiplayer.has_multiplayer_peer() and player.get_multiplayer_authority() != 1:
_sync_show_floating_text.rpc_id(player.get_multiplayer_authority(), loot_type, "+" + str(int(actual_heal)) + " HP", Color.GREEN, int(actual_heal), (8 * 20) + 11, player.get_multiplayer_authority())
self.visible = false self.visible = false
@@ -418,6 +427,9 @@ func _process_pickup_on_server(player: Node):
# Show floating text with item graphic and heal amount # Show floating text with item graphic and heal amount
var items_texture = load("res://assets/gfx/pickups/items_n_shit.png") var items_texture = load("res://assets/gfx/pickups/items_n_shit.png")
_show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 12) _show_floating_text(player, "+" + str(int(actual_heal)) + " HP", Color.GREEN, 0.5, 0.5, items_texture, 20, 14, (8 * 20) + 12)
# Sync floating text to client
if multiplayer.has_multiplayer_peer() and player.get_multiplayer_authority() != 1:
_sync_show_floating_text.rpc_id(player.get_multiplayer_authority(), loot_type, "+" + str(int(actual_heal)) + " HP", Color.GREEN, int(actual_heal), (8 * 20) + 12, player.get_multiplayer_authority())
self.visible = false self.visible = false
@@ -434,6 +446,9 @@ func _process_pickup_on_server(player: Node):
# Show floating text with item graphic and text # Show floating text with item graphic and text
var items_texture = load("res://assets/gfx/pickups/items_n_shit.png") var items_texture = load("res://assets/gfx/pickups/items_n_shit.png")
_show_floating_text(player, "+1 KEY", Color.YELLOW, 0.5, 0.5, items_texture, 20, 14, (13 * 20) + 10) _show_floating_text(player, "+1 KEY", Color.YELLOW, 0.5, 0.5, items_texture, 20, 14, (13 * 20) + 10)
# Sync floating text to client
if multiplayer.has_multiplayer_peer() and player.get_multiplayer_authority() != 1:
_sync_show_floating_text.rpc_id(player.get_multiplayer_authority(), loot_type, "+1 KEY", Color.YELLOW, 0, (13 * 20) + 10, player.get_multiplayer_authority())
self.visible = false self.visible = false
@@ -536,6 +551,41 @@ func _sync_remove():
if not is_queued_for_deletion(): if not is_queued_for_deletion():
queue_free() queue_free()
@rpc("any_peer", "reliable")
func _sync_show_floating_text(loot_type_value: int, text: String, color_value: Color, value: int, sprite_frame_value: int, player_peer_id: int):
# Client receives floating text sync from server
if multiplayer.is_server():
return # Server ignores this (it's the sender)
# Find player by peer ID
var player = null
var players = get_tree().get_nodes_in_group("player")
for p in players:
if p.get_multiplayer_authority() == player_peer_id:
player = p
break
if not player or not is_instance_valid(player):
return # Can't find player
# Determine texture and parameters based on loot type
var item_texture: Texture2D = null
var sprite_hframes: int = 1
var sprite_vframes: int = 1
match loot_type_value:
LootType.COIN:
item_texture = load("res://assets/gfx/pickups/gold_coin.png")
sprite_hframes = 6
sprite_vframes = 1
LootType.APPLE, LootType.BANANA, LootType.CHERRY, LootType.KEY:
item_texture = load("res://assets/gfx/pickups/items_n_shit.png")
sprite_hframes = 20
sprite_vframes = 14
# Show floating text on client
_show_floating_text(player, text, color_value, 0.5, 0.5, item_texture, sprite_hframes, sprite_vframes, sprite_frame_value)
func _show_floating_text(player: Node, text: String, color: Color, show_time: float = 0.5, fade_time: float = 0.5, item_texture: Texture2D = null, sprite_hframes: int = 1, sprite_vframes: int = 1, sprite_frame: int = 0): func _show_floating_text(player: Node, text: String, color: Color, show_time: float = 0.5, fade_time: float = 0.5, item_texture: Texture2D = null, sprite_hframes: int = 1, sprite_vframes: int = 1, sprite_frame: int = 0):
# Create floating text and item graphic above player's head # Create floating text and item graphic above player's head
# Shows for show_time seconds, then fades out over fade_time seconds # Shows for show_time seconds, then fades out over fade_time seconds
@@ -545,5 +595,5 @@ func _show_floating_text(player: Node, text: String, color: Color, show_time: fl
var parent = player.get_parent() var parent = player.get_parent()
if parent: if parent:
parent.add_child(floating_text) parent.add_child(floating_text)
floating_text.global_position = Vector2(player.global_position.x, player.global_position.y) floating_text.global_position = Vector2(player.global_position.x, player.global_position.y - 20)
floating_text.setup(text, color, show_time, fade_time, item_texture, sprite_hframes, sprite_vframes, sprite_frame) floating_text.setup(text, color, show_time, fade_time, item_texture, sprite_hframes, sprite_vframes, sprite_frame)