mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-16 08:55:33 +00:00
Fix damage/health client/server desynchnorization
This commit is contained in:
parent
8221b323aa
commit
49ffa397e7
1 changed files with 15 additions and 7 deletions
|
|
@ -11,20 +11,28 @@ signal health_zeroed
|
||||||
signal health_changed(value : int)
|
signal health_changed(value : int)
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
health = max_health
|
heal_full()
|
||||||
area_entered.connect(_on_area_entered)
|
area_entered.connect(_on_area_entered)
|
||||||
|
|
||||||
func damage(amount : int):
|
@rpc("call_local")
|
||||||
|
func _damage(amount : int) -> void:
|
||||||
health = clampf(health - amount, 0.0, max_health)
|
health = clampf(health - amount, 0.0, max_health)
|
||||||
if health == 0.0:
|
if health == 0.0:
|
||||||
health_zeroed.emit()
|
health_zeroed.emit()
|
||||||
|
|
||||||
func heal_full():
|
@rpc("call_local")
|
||||||
health = max_health
|
func _heal(amount : int):
|
||||||
|
|
||||||
func heal(amount : int):
|
|
||||||
health = clampf(health + amount, 0.0, max_health)
|
health = clampf(health + amount, 0.0, max_health)
|
||||||
|
|
||||||
|
func heal_full():
|
||||||
|
if not is_multiplayer_authority():
|
||||||
|
return
|
||||||
|
|
||||||
|
_heal.rpc(max_health)
|
||||||
|
|
||||||
func _on_area_entered(area : Area3D):
|
func _on_area_entered(area : Area3D):
|
||||||
|
if not is_multiplayer_authority():
|
||||||
|
return
|
||||||
|
|
||||||
if area is AreaDamageComponent:
|
if area is AreaDamageComponent:
|
||||||
damage(area.damage)
|
_damage.rpc(area.damage)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue