Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Newby |
I have a Script for my player scene and enemy scene in a turn base game and i want it so i dont have to call the scene to be attack every time because the damage doesnt sync up with the attack animation
here is the code for the player and enemy
extends Control
export(int) var MAX_HP=10
export(int) var STR=0
export(int) var DEF=0
var dead=false
var HP
func _ready():
HP=MAX_HP
get_node("HPnum").set_text(str(HP))
get_node("Name").set_text(str(Next_Level.player_name))
#YOUR ATTACK
func attack(enemy):
var strdamage=STR
get_node("Animate").play("Attack")
enemy.takedamage(strdamage)
#ENEMY ATTACK
func takedamage(amount):
get_node("Animate").play("Hurt")
HP=HP-amount
if HP>0:
get_node("HPnum").set_text(str(HP))
else:
get_node("Animate").play("Dead")
dead()
return HP
func dead():
get_node("Animate").play("Hurt")
get_node("HPnum").set_text("Downed")
func _on_Animate_animation_finished(anim):
if dead!=true:
get_node("Animate").play("Idle")
if anim=="Hurt" and HP<=0:
get_node("Animate").play("Dead")
if anim=="Dead":
dead=true
i call the attack with buttons on the main scene
func answerlocation():
get_node("Question").set_text(QnA.questions())
randomize()
num=randi()%4
if num==0:
if Anim.current_animation!="Hurt" or Anim.current_animation!="Dead" or Anim1.current_animation!="Hurt" or Anim1.current_animation!="Dead":
get_node("Choice1").connect("pressed",get_node("Player"),"attack",[get_node("Enemy")])
get_node("Choice1").set_text(QnA.answers())
get_node("Choice2").set_text(QnA.wrong1())
get_node("Choice3").set_text(QnA.wrong2())
get_node("Choice4").set_text(QnA.wrong3())
else:
if Anim.current_animation!="Hurt" or Anim.current_animation!="Dead" or Anim1.current_animation!="Hurt" or Anim1.current_animation!="Dead":
get_node("Choice1").connect("pressed",get_node("Enemy"),"attack", [get_node("Player")])