Defending in my battle system...

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
frytkosz-555
Newbie
Posts: 11
Joined: Mon May 31, 2021 12:09 pm
Contact:

Defending in my battle system...

#1 Post by frytkosz-555 »

I am making a battle system and am trying to figure out how to make enable the player character and the enemy to be able to defend from the upcoming attack so here is what i need to figure out:

1. How to subtract the defence value from the attack value.
2. How to make the defence "Stay" up until the defending characters next move.

Here is the code:
Image

Thank you for your help.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Defending in my battle system...

#2 Post by Alex »

frytkosz-555 wrote: Sun Jun 13, 2021 8:22 am ...1. How to subtract the defence value from the attack value.
2. How to make the defence "Stay" up until the defending characters next move. ...
You can make a variable to store enemy's defense.
Try

Code: Select all

default enemy_defense = 0
label battle:
    while (enemy_hp >0) and (hero_hp > 0):
        menu:
            "Attack":
                $ dmg = renpy.random.randint(2.5)
                $ enemy_hp -= max(0, dmg - enemy_defense)
                # if enemy_defense is greater than hero's dmg
                # then enemy_hp will be reduced by 0
                # (make the same for all attacks)

        $ enemy_defense = 0 # defense is working for 1 move only

        if enemy_hp > 0:
            $ randaction = renpy.random.choice(["attack", "defend"]):
            if randaction == "defend":
                $ enemy_defense = 4

frytkosz-555
Newbie
Posts: 11
Joined: Mon May 31, 2021 12:09 pm
Contact:

Re: Defending in my battle system...

#3 Post by frytkosz-555 »

So I implemented some of the stuff from the post above, now the enemy can defend themselves but when the value of defence exceeds the value of the MC's attack then the enemy heals themselves by the value of the difference betweent he two and I don't want them to do that, how can I fix that?

Image

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Defending in my battle system...

#4 Post by Alex »

Code: Select all

$ enemy_hp -= max(0, dmg - enemy_defense)

frytkosz-555
Newbie
Posts: 11
Joined: Mon May 31, 2021 12:09 pm
Contact:

Re: Defending in my battle system...

#5 Post by frytkosz-555 »

Thanks Alex I applied that and now it works perfectly.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]