[Solved] RPG style player stats and a 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
User avatar
Mehmed
Newbie
Posts: 23
Joined: Sat Jul 20, 2013 3:57 pm
Contact:

[Solved] RPG style player stats and a battle system

#1 Post by Mehmed »

I've looked thoroughly and haven't found anything very helpful. The cookbook's "framework" doesn't even work for me, and isn't exactly what I need.
I know Ren'py isn't exactly suited well for this but I know it's flexible enough to get it to work, since it's simple variable tracking and exchange. All stats would be is named variables. That's easy enough to do, but what I'm trying to do is implement a text based battle system and player tracking.
This comes with the full shebang of a stat affecting how much damage you do, how accurately you hit, your initiative, skill requirements, how much HP you have, what you can wield, and so on. I understand this can be done with some simple math and tracking, say something along the lines of "if the player has more than 15 STR they can wear this" would be simple addition.

I know all this, but I don't know exactly how to go about doing it. It's like trying to ride a bike for the first time; you know what it's suppose to look like when you do it but you still have trouble figuring out how exactly to sit to keep your balance.
Along with this I understand how a battle system should look, with damage again just being math and having the game terminate the player and show a game over or something when their health reaches below a variable.
I know how this should look but I don't know how to go about getting started on it.

I was wondering if there was any previous guides or something that could help me with this, or maybe a thread I missed? Any help on just where to get started and where to stop would be enough.
Last edited by Mehmed on Fri Sep 06, 2013 6:52 pm, edited 1 time in total.

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

Re: RPG style player stats and a battle system

#2 Post by Alex »

This should help a bit

Code: Select all

define r = Character('Red Hood', color="#CD0000")
define w = Character('mr.Wolf', color="#B5B5B5")

screen simple_stats_screen:
    frame:
        xalign 0.01 yalign 0.05
        vbox:
            text "Red Hood" size 22 xalign 0.5
            null height 5
            hbox:
                bar:
                    xmaximum 130
                    value red_hood_hp
                    range red_hood_max_hp
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[red_hood_hp] / [red_hood_max_hp]" size 16
                
                
    frame:
        xalign 0.99 yalign 0.05
        vbox:
            text "mr.Wolf" size 22 xalign 0.5
            null height 5
            hbox:
                bar:
                    xmaximum 130
                    value wolf_hp
                    range wolf_max_hp
                    left_gutter 0
                    right_gutter 0
                    thumb None
                    thumb_shadow None
                    
                null width 5
                
                text "[wolf_hp] / [wolf_max_hp]" size 16
                
    text "Red Hood vs. mr.Wolf" xalign 0.5 yalign 0.05 size 30
                
# The game starts here.
label start:
    $ wolf_max_hp = 30
    $ red_hood_max_hp = 50
    $ wolf_hp = wolf_max_hp
    $ red_hood_hp = red_hood_max_hp
    $ cookies_left = 13
    
    
    "Once upon a time there lived in a certain village a little country girl, the prettiest creature who was ever seen."
    "Her mother was excessively fond of her; and her grandmother doted on her still more."
    "This good woman had a little red riding hood made for her. It suited the girl so extremely well that everybody called her Little Red Riding Hood."
    "One day her mother, having made some cookies, said to her, \"Go, my dear, and see how your grandmother is doing, for I hear she has been very ill. Take her some cookies, and this little pot of butter."
    "Little Red Riding Hood set out immediately to go to her grandmother, who lived in another village."
    "As she was going through the wood, she met with a wolf, who had a very great mind to eat her up, but {w}suddenly..."



label battle:
    
    show screen simple_stats_screen
    
    while (wolf_hp > 0) and (red_hood_hp > 0):
        
        menu:
            "Atack!":
                $ wolf_hp -= 2
                r "K-y-aaa!!!11 (damage dealt - 2hp)"
                
            "Eat cookie (got [cookies_left] cookies left)" if cookies_left > 0:
                $ red_hood_hp = min(red_hood_hp+5, red_hood_max_hp)
                $ cookies_left -= 1
                r "Mmm, tasty... (restore 5hp)"
        
        $ wolf_damage = renpy.random.randint(1, 6)
        
        $ red_hood_hp -= wolf_damage
        
        w "RrrrrRRrrrr! {i}*wolf bites you*{/i} (damage dealt - [wolf_damage]hp)"
        
        
        
    hide screen simple_stats_screen
    
    if wolf_hp <= 0:
        if red_hood_hp <= 0:
            "Double KO"
            
        else:
            r "I wiiiin!!!!!111"
            r "Finally, mom sew me a grey hood."
            
    else:
        w "Om-nom-nom-nom {i}*wolf ate you all up*{/i} (along with the basket, of course...)"
        
label ending:
    "The end."
http://www.renpy.org/doc/html/screens.html
http://www.renpy.org/doc/html/menus.html
http://www.renpy.org/wiki/renpy/doc/ref ... _Functions (the bottom of the page)

User avatar
Mehmed
Newbie
Posts: 23
Joined: Sat Jul 20, 2013 3:57 pm
Contact:

Re: RPG style player stats and a battle system

#3 Post by Mehmed »

Alex wrote:This should help a bit
No that helped a lot, solved all my problems in one go thanks so much. I've been stuck on progress for almost a month now and it's put me into a major procrastinating mood, this just got me right up out of it.

Zidiane
Newbie
Posts: 7
Joined: Wed Aug 28, 2013 11:43 am
Contact:

Re: [Solved] RPG style player stats and a battle system

#4 Post by Zidiane »

I know the OP had his question solved, but I'm having some trouble. I want a battle system exactly like this, but a little different and I have some questions.

I need multiple characters, like 1-3 player characters against 1-3 enemy units. I figured out how to make multiple health bars and targets (Like I can have Red Hood and Grey Hood VS Mr. Wolf and Mrs. Wolf), but I can't figure out how to really have them all interact. I have an example that I tried... but it won't work right. I know how to give the player the choice who to attack, but I can't figure out how to have the enemies pick between targets. I'd also like to be able to make them choose between multiple random attacks. And finally, how to make certain attacks give special properties, like making them not take damage from the next attack, or to do a special action if attacked, or take reduced damage.
Last edited by Zidiane on Fri Sep 13, 2013 4:27 pm, edited 1 time in total.

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

Re: [Solved] RPG style player stats and a battle system

#5 Post by Alex »

Well, my example is rather primitive and was meant to show 1) the way to arrange a game loop and 2) the way to visualise all the variables.

If you need to make anything more complicated, you'd better check nyaatrap's "Dungeon crawling RPG frame" or Jake's "RPG Battle Engine". If this frameworks way too complicated for your needs, well... - another example of how messy the code looks without classes and all that fancy stuff.

Code: Select all

screen battle_screen:
    vbox:
        xalign 0.01 yalign 0.05
        xminimum 250 xmaximum 250
        spacing 5
        
        for each_party_member in party_list:
            frame:
                size_group "party"
                vbox:
                    text "[each_party_member[name]]" size 22 xalign 0.5
                    null height 5
                    hbox:
                        bar:
                            xmaximum 130
                            value each_party_member["current_hp"]
                            range each_party_member["max_hp"]
                            left_gutter 0
                            right_gutter 0
                            thumb None
                            thumb_shadow None
                            
                        null width 5
                        
                        text "[each_party_member[current_hp]] / [each_party_member[max_hp]]" size 16
        frame:
            size_group "party"
            text "Potions left - [potions_left]"
                        
                        
    vbox:
        xalign 0.99 yalign 0.05
        xminimum 250 xmaximum 250
        spacing 5
        
        if enemies_list != []:
            for each_enemy_member in enemies_list:
                frame:
                    size_group "enemies"
                    vbox:
                        text "[each_enemy_member[name]]" size 22 xalign 0.5
                        null height 5
                        hbox:
                            bar:
                                xmaximum 130
                                value each_enemy_member["current_hp"]
                                range each_enemy_member["max_hp"]
                                left_gutter 0
                                right_gutter 0
                                thumb None
                                thumb_shadow None
                                
                            null width 5
                            
                            text "[each_enemy_member[current_hp]] / [each_enemy_member[max_hp]]" size 16
            
            

init python:
    def check_party(x):
        # this function will check if at least one of X party members is alive
        
        for member in x:
            if member["current_hp"] > 0:
                return "ok"
                
        return "lost"



label start:
    
    $ party_list =[{"name":"Me", "max_hp":50, "current_hp":50, "min_damage":3, "max_damage":5}]
    $ potions_left = 10
    
    $ enemies_list = []
    
    show screen battle_screen
    
    
    menu:
        "Who do you take with you?"
        
        "Friend 1":
            $ party_list.append ( {"name":"Friend 1", "max_hp":30, "current_hp":30, "min_damage":5, "max_damage":6} )
            
        "Friend 2":
            $ party_list.append ( {"name":"Friend 2", "max_hp":60, "current_hp":60, "min_damage":1, "max_damage":4} )
            
        "Noone... :(":
            pass
            
    
    # enemies party can be set manually or automatically like
    python:
        for i in range ( 0, renpy.random.randint(1,4) ):
            enemy_name = "Enemy %d" %i
            enemy_max_hp = renpy.random.randint(10,20)
            enemy_current_hp = enemy_max_hp
            enemy_min_damage = renpy.random.randint(1,3)
            enemy_max_damage = renpy.random.randint(4,6)
            
            enemies_list.append ( {"name":enemy_name, "max_hp":enemy_max_hp, "current_hp":enemy_current_hp, "min_damage":enemy_min_damage, "max_damage":enemy_max_damage} )
            
    
    "Let the battle begins!"
    
    # main battle loop
    label battle_loop:
        
        # at first let's check if player's party is ok
        if check_party(party_list) == "lost":
            jump lose
                
        
        # all the party members will do their actions one after another
        $ party_index = 0
        
        while party_index < len(party_list):
            
            $ current_player = party_list[party_index]
            
            # current player will act only if he still alive
            if current_player["current_hp"] > 0:
                
                # let's check if enemies party is ok
                if check_party(enemies_list) == "lost":
                    jump win
            
                "[current_player[name]], who do you want to attack?"
                
                #####
                # let the player choose the enemy to attack
                $ list_to_attack = []
                python:
                    for j in range ( 0, len(enemies_list) ):
                        one_of_enemies = enemies_list[j]["name"]
                        if enemies_list[j]["current_hp"] > 0:
                            list_to_attack.append( (one_of_enemies, j) )
                        
                $ enemy_to_attack = renpy.display_menu(list_to_attack)
                #
                #####
                
                
                menu:
                    "Attack!":
                        $ player_damage = renpy.random.randint( current_player["min_damage"], current_player["max_damage"] )
                        $ enemies_list[enemy_to_attack]["current_hp"] -= player_damage
                        "Take this! (damage dealt - [player_damage]hp)"
                        
                    "Use healing potion" if potions_left >0:
                        $ current_player["current_hp"] = min( current_player["current_hp"]+5, current_player["max_hp"] )
                        $ potions_left -= 1
                        "*Drink* 5hp restored"
                    
            
            # and the turn goes to the next party member
            $ party_index += 1
                    
            
            
        #####
        # and now it's enemies party turn
        
        # at first let's check if if enemy's party is ok
        if check_party(enemies_list) == "lost":
            jump win
        
        
        
        # all the party members will do their actions one after another
        $ enemy_index = 0
        
        while enemy_index < len(enemies_list):
            $ current_enemy = enemies_list[enemy_index]
            
            if current_enemy["current_hp"] > 0:
                
                # current enemy will act only if he still alive
                if check_party(party_list) == "lost":
                    jump lose
                
                # enemy will attack the random player
                $ party_member_to_attack = party_list[renpy.random.randint( 0, (len(party_list)-1) )]
                
                $ enemy_damage = renpy.random.randint( current_enemy["min_damage"], current_enemy["max_damage"] )
                
                $ party_member_to_attack["current_hp"] -= enemy_damage
                
                "Rrrrr! ([current_enemy[name]] dealt [enemy_damage]hp damage to [party_member_to_attack[name]])"
                
            
            # and the turn goes to the next party member
            $ enemy_index += 1
            
            
        # next round of the battle
        jump battle_loop
            
            
            
    label win:
        "Well done!"
        return
        
    label lose:
        "X_X"
        return
http://www.renpy.org/wiki/renpy/doc/ref ... splay_menu
http://docs.python.org/2/tutorial/datastructures.html

Zidiane
Newbie
Posts: 7
Joined: Wed Aug 28, 2013 11:43 am
Contact:

Re: [Solved] RPG style player stats and a battle system

#6 Post by Zidiane »

Thank you. I think it's too much for me right this moment, but I'll be coming back to it to try and break everything down. I'll figure it all out eventually, so thank you!

Saicachii
Newbie
Posts: 22
Joined: Tue Dec 09, 2014 12:05 pm
Contact:

Re: [Solved] RPG style player stats and a battle system

#7 Post by Saicachii »

Hello! ^-^

I love this script but I can't make it work the way I want it to, maybe someone can help?
For the first script, how can I change it so that there are two players and one enemy?
Also, how can I add status effects and so on? Just attack and potion is a little too boring I think...
For example a stun effect so the player/enemy has to wait a turn or random turns until the status effect wears off.

Thank you!

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: [Solved] RPG style player stats and a battle system

#8 Post by OokamiKasumi »

This really should be in the Cookbook.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

Post Reply

Who is online

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