Fixed ammo count not showing correctly

remotes/1699310152913738325/tmp_refs/heads/legacy
Jan Heemstra 2021-04-12 22:55:42 +02:00
parent 054f9ee56a
commit f352500096
6 changed files with 16 additions and 9 deletions

View File

@ -1,6 +1,7 @@
extends Control
func update_ammo(var weapon, var amount):
func update_ammo(var weapon):
var amount = weapon.current_rounds
$Weapon/VBoxContainer/RoundsClips.text = str(amount)
func updateHealth(health: int):

View File

@ -409,8 +409,10 @@ func set_local_player():
func _ready():
$HUD/Health/HealthBar.max_value = max_health
for weapon in $Camera/Hand/Weapons.get_children():
print($Camera/Hand/Weapons.get_child_count())
for weapon in $Camera/Hand/Weapons.weapons:
weapon.connect("damage_dealt", $HUD, "update_crosshair")
weapon.connect("ammo_changed", $HUD, "update_ammo")
# Set player class
var path = get_script().get_path()

View File

@ -221,7 +221,7 @@ script = ExtResource( 8 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 )
[node name="Hand" type="Spatial" parent="Camera"]
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.399991, -0.559 )
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.394656, -0.559 )
[node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"]
tree_root = SubResource( 12 )

View File

@ -28,6 +28,7 @@ func _activate_weapon(index):
# Activate the requested weapon.
active_weapon = weapons[index]
add_child(active_weapon)
active_weapon.switched_to_weapon()
func switch_to_weapon(index):
# Take a modulo here as a quick and easy way to have a valid index.

View File

@ -1,7 +1,7 @@
extends Spatial
signal damage_dealt(kill)
signal ammo_changed(type, amount)
signal ammo_changed(weapon)
export(bool) var Hitscan = false
export(int) var Damage = 100
@ -31,6 +31,9 @@ var tracer = preload("res://Assets/Effects/BulletTracer.tscn")
func _ready():
$Sounds.global_transform.origin = camera.global_transform.origin
func switched_to_weapon():
emit_signal("ammo_changed", self)
func shoot(camera):
if cached_fire == true:
return
@ -48,7 +51,6 @@ func shoot(camera):
rpc("compute_bullet_flyby")
current_rounds -= 1
emit_signal("ammo_changed", "handgun", current_rounds)
var space_state = get_world().direct_space_state
@ -61,14 +63,16 @@ func shoot(camera):
if "collider" in result:
var hit = result.collider
if hit.has_method("on_hit"):
hit.rpc("on_hit", 30, result.position)
if hit is Player:
var kill = hit.health <= 0
emit_signal("damage_dealt", kill)
print(get_signal_connection_list("damage_dealt")[0]["target"].name)
#print(get_signal_connection_list("ammo_changed")[0]["target"].name)
emit_signal("ammo_changed", self)
else:
reload()
@ -152,7 +156,7 @@ func reload():
current_rounds = Rounds
emit_signal("ammo_changed", "handgun", current_rounds)
emit_signal("ammo_changed", self)
sync func play_reload_animation():
$Model/AnimationPlayer.play("Reload", 0.5, 1)

View File

@ -344,7 +344,6 @@ func on_connection_failed():
func _on_TextChat_typing_toggled(is_typing) -> void:
if is_typing:
GAME_MODE = "MENU"
else:
GAME_MODE = "PLAYING"
pass