From cb9f87a608ceac53950a06181fe0665855c30837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agnis=20Aldi=C5=86=C5=A1=20=22NeZv=C4=93rs?= Date: Wed, 16 Oct 2024 19:37:14 +0300 Subject: [PATCH] Reset players health --- .../ReferenceNodeResource/ReferenceNodeResource.gd | 2 +- addons/top_down/scenes/actors/player.tscn | 7 ++++++- addons/top_down/scripts/actor/Player/ResetHealth.gd | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 addons/top_down/scripts/actor/Player/ResetHealth.gd diff --git a/addons/nezvers_library/resources/ReferenceNodeResource/ReferenceNodeResource.gd b/addons/nezvers_library/resources/ReferenceNodeResource/ReferenceNodeResource.gd index dae4b04a..7193fcee 100644 --- a/addons/nezvers_library/resources/ReferenceNodeResource/ReferenceNodeResource.gd +++ b/addons/nezvers_library/resources/ReferenceNodeResource/ReferenceNodeResource.gd @@ -1,4 +1,4 @@ -## Resource to reference the same Node and receive notification when the reference is changed. +## Resource to reference a Node and receive notification when the reference is changed. class_name ReferenceNodeResource extends Resource diff --git a/addons/top_down/scenes/actors/player.tscn b/addons/top_down/scenes/actors/player.tscn index 3f29a132..beaae40a 100644 --- a/addons/top_down/scenes/actors/player.tscn +++ b/addons/top_down/scenes/actors/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=42 format=3 uid="uid://bmp0g88dtijqw"] +[gd_scene load_steps=43 format=3 uid="uid://bmp0g88dtijqw"] [ext_resource type="PackedScene" uid="uid://botai66n8rwt3" path="res://addons/top_down/scenes/actors/actor.tscn" id="1_mvls6"] [ext_resource type="Script" path="res://addons/nezvers_library/nodes/ResourceNode/ResourceNodeItem.gd" id="2_20qkb"] @@ -23,6 +23,7 @@ [ext_resource type="Resource" uid="uid://diqvd4u0lbw7h" path="res://addons/top_down/resources/CommandNodeResource/color_flash.tres" id="18_5jtne"] [ext_resource type="Resource" uid="uid://ddpkkj7j7ync6" path="res://addons/top_down/resources/CameraShakeResource/enemy_damage_shake.tres" id="18_7uk1v"] [ext_resource type="Resource" uid="uid://dkb7r2v362yj" path="res://addons/top_down/resources/CameraShakeResource/player_damage_shake.tres" id="19_d25rq"] +[ext_resource type="Script" path="res://addons/top_down/scripts/actor/Player/ResetHealth.gd" id="24_xfk7a"] [sub_resource type="Resource" id="Resource_u7p0r"] resource_name = "movement properties" @@ -265,3 +266,7 @@ player_damage_shake = ExtResource("19_d25rq") [node name="ActorDamage" parent="." index="15"] sound_resource_dead = ExtResource("6_wov6i") dead_vfx_scene = ExtResource("8_s8ofx") + +[node name="ResetHealth" type="Node" parent="." index="17" node_paths=PackedStringArray("resource_node")] +script = ExtResource("24_xfk7a") +resource_node = NodePath("../ResourceNode") diff --git a/addons/top_down/scripts/actor/Player/ResetHealth.gd b/addons/top_down/scripts/actor/Player/ResetHealth.gd new file mode 100644 index 00000000..81a864eb --- /dev/null +++ b/addons/top_down/scripts/actor/Player/ResetHealth.gd @@ -0,0 +1,8 @@ +class_name ResetHealth +extends Node + +@export var resource_node:ResourceNode + +func _ready()->void: + var _health_resource:HealthResource = resource_node.get_resource("health") + _health_resource.reset_resource()