Heal command on RPG Battle Engine

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
User avatar
Coren
Mindscrew Driver
Posts: 1691
Joined: Fri Sep 18, 2009 9:24 am
Completed: Dear Mariko, Six Rules, Ribbon of Green, RE: Prince of Nigeria, Doppelganger, Cole's Gate Demo, Crimson Rafflesia Demo, Mica: Apoptosis Demo
Projects: Crimson Rafflesia, Mica: Apoptosis, Fantasy Euthanasia
Organization: Soyasushi Productions
Tumblr: CorenBaili
Deviantart: CorenB
Skype: coren.baili
Contact:

Heal command on RPG Battle Engine

#1 Post by Coren »

Hi guys, I was just wondering if it's possible to create a Heal command in this script:

viewtopic.php?f=51&t=30095

Currently, I've managed to make it possible to perform an action which allows a party member or members to gain HP, but it won't show up as a message e.g. "T uses Heal! The party gains 50 HP!" How should I do that? Thanks!

User avatar
SypherZent
Veteran
Posts: 362
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

Re: Heal command on RPG Battle Engine

#2 Post by SypherZent »

Hello,

I came to this section to search for an answer to a question.
Ended up answering other questions instead. xD

Ok so I checked the scripts. It's not a very complex system.

It seems like you'd first want to create a Heal Skill for one of the characters.
Look for the label playerX_skills: where X is the player for whom you want to add the skill.

Then, add the skill like this:

Code: Select all

label player4_skills:
    hide screen battle_overlay_players
    call screen luna_skills
    if p_skill == "Magic Attack 1":
        $ damage = player4_attack * 2
    elif p_skill == "Magic Attack 2":
        $ damage = player4_attack*4
    elif p_skill == "Magic Attack 3":
        $ damage = player4_attack * 6
    elif p_skill == "Magic Attack 4":
        $ damage = player4_attack*5
        $ target = "all"
    elif p_skill == "Magic Attack 5":
        $ damage = player4_attack * 10
        $ target = "all"
    elif p_skill == "Magic Attack 6":
        $ damage = player4_attack*3
        $ target = "all"
    elif p_skill == "Magic Attack 7":
        $ damage = player4_attack * 5
    elif p_skill == "Heal Spell 1":
        $ damage = player4_attack * 2 #you can tweak the amount here, later
    show screen battle_overlay_players
    return

Note that this label is calling another screen called luna_skills, so let's search for that next.

Code: Select all

screen luna_skills:
    add "battle/battlebox2.png" xalign 0.2 yalign .99
    textbutton "Magic Attack 1" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.1 yalign 0.8 action Return("Magic Attack 1")  
    textbutton "Magic Attack 2" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.7 yalign 0.8 action Return("Magic Attack 2") 
    textbutton "Magic Attack 3" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.1 yalign 0.85 action Return("Magic Attack 3") 
    textbutton "Magic Attack 4" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.7 yalign 0.85 action Return("Magic Attack 4")
    textbutton "Magic Attack 5" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.1 yalign 0.9 action Return("Magic Attack 5")
    textbutton "Magic Attack 6" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.7 yalign 0.9 action Return("Magic Attack 6")
    textbutton "Magic Attack 7" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.1 yalign 0.95 action Return("Magic Attack 7") 
    textbutton "Heal Spell 1" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.7 yalign 0.95 action Return("Heal Spell 1")

Now that we've added a new entry and adjusted the xalign and yalign to match the pattern already defined, we can see what is the next thing that is supposed to happen in this code. In the previous code block, the next screen to be displayed is show screen battle_overlay_players, so we go there...which leads to a dead end.

Now what?

Not having seen the system in action, I just go back to top of script and verify once again.
I notice that there is a label player_turn: which calls a screen player_actions.
Following this route, we can find that screen:

Code: Select all

screen player_actions: #returns for player action
    textbutton "Attack" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.95 yalign 0.81 action Return("attack") 
    textbutton "Skills" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.95 yalign 0.86 action Return("skills") 
    textbutton "Defend" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.95 yalign 0.91 action Return("defend") #damage from monster is lowered depending on player's defense
    #textbutton "Items" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.95 yalign 0.96 action Return("items") #not implemented yet
Now we notice that Heal could technically be added as an option in the battle menu, rather than as a player skill.
However, let's continue with this route for now, as we're attempting to implement a skill (should be simpler).

Back in player_turn, we notice that $ p_action = _return so p_action will be 'skills' since the Heal ability is a player 4 skill.
Next player_dealt_damage label is called. We see that this leads to player4_skills, which we already modified, so we follow it further:

Code: Select all

    if damage < 0:
        return
# we know damage is not 0 because we defined it as player_attack * 2
    else:
        call screen player_target
So it seems next up is the player_target screen. Which, unfortunately does not allow us to select a player target!
So let's create a menu that allows us to target players.

Code: Select all

screen player_target: #returns monster player wants to attack
    if target == "all":
        textbutton "All Enemies" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.4 action Return("all")
    else:
        if monster1 != "none":
            textbutton "[monster1]" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.4 action Return("monster1") 
        if monster2 != "none":
            textbutton "[monster2]" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.2 yalign 0.4 action Return("monster2") 
        if monster3 != "none":
            textbutton "[monster3]" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.8 yalign 0.4 action Return("monster3") 
        
        textbutton "Ally" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.0 action Return("ally") #note, you'll have to adjust the x and y align values for positioning


Back to where we were earlier (can do a CTRL+F and search for call screen player_target, there is only 1 instance).
Over here we can add this new target called ally to the ifchecks list with some code to call a new screen.

Code: Select all

        elif target == "all":
            $ monster1_hp = monster1_hp - damage
            $ monster2_hp = monster2_hp - damage
            $ monster3_hp = monster3_hp - damage
        elif target == "ally":
            call screen player_target_ally
            $ target = _return

Let's make that screen just like the other screen:

Code: Select all

screen player_target_ally: #returns ally player wants to target (heal only option currently that uses this)
    textbutton "Player 1" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.2 action Return("player1")
    textbutton "Player 2" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.4 action Return("player2")
    textbutton "Player 3" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.6 action Return("player3")
    textbutton "Player 4" style "battlebutton" text_style "battlebutton_text" background "battle/transparent.png" xalign 0.5 yalign 0.8 action Return("player4")
Once again, you'll have to adjust these x and y align values, as I am not seeing the actual result, nor the image sizes and styles.
At this point it takes a bit of searching again, because the player_dealt_damage screen ends.
We need to add the healing in this label (player_dealt_damage), so we need to see how player damage is calculated.

We can go to the monster_dealt_damage label and examine it.
$ player4_hp = player4_hp - m_damage
So now we see the variables for the HP and damage.
We go back to our little setup in the player_dealt_damage area and add more code:

Code: Select all

        elif target == "ally":
            call screen player_target_ally
            $ target = _return
            # target here is redefined as our return labels from the player_target_ally screen
            if target == "player1":
                $ player1_hp = player1_hp + damage
            elif target == "player2":
                $ player2_hp = player2_hp + damage
            elif target == "player3":
                $ player3_hp = player3_hp + damage
            elif target == "player4":
                $ player4_hp = player4_hp + damage
            $ message = "player_heal"
                
        if p_action == "attack":
            $ message = "player_attack"
        elif p_action == "skills":
            $ message = "player_skill"
Note how the $ message (for the battle messages) only has player_attack and player_skill.
We want to differentiate this. So in the above example, we have made the correction before we reach the p_action section.

Finally, let's go to battle messages.

Code: Select all

screen battle_message:
    add "battle/messagebox.png" xalign 0 yalign 0
...
...
    if message == "player_attack":
        text "[player_turn] attacks! Dealt [damage] damage!" xalign 0.02 yalign 0.05
    if message == "player_skill":
        text "[player_turn] used [p_skill]! Dealt [damage] damage!" xalign 0.02 yalign 0.05
    if message == "player_heal":
        text "[player_turn] used [p_skill]! Healed [target] for [damage]! xalign 0.02 yalign 0.05
Note, here you can format the message as you want. If target displays as "player1" then you can redefine it above in the ifchecks for every target...like this:

Code: Select all

            elif target == "player2":
                $ player2_hp = player2_hp + damage
                $ target = "Player 2" # Set the target name for the battle message here

I think that's it! After performing the above changes, you can test the code and see if it all works and nothing is missing.
This was pretty entertaining, to be honest. Needed a change of pace. xD

P.S. I hope this explanation helps you to see how you can tinker with the code and also find what you need.
Hopefully one day you will be able to code your own full-fledged battle engine from scratch! :)

Edit to Add: You will probably be able to overheal allies with the current modifications.
To prevent this, in the section where you do hp = hp + damage, you can verify the respective player's hp against their max HP (there are variables defined for the maximums) and then set it to equal if it's greater right in the same section, after adding the damage.
Creator of Multiverse Heroes & Space Hamster in Turmoil

Want me to code your game?
Check my services thread!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]