Dungeon Crawl RPG Framework

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
Zebragirl
Newbie
Posts: 8
Joined: Fri Apr 05, 2013 3:54 pm
Contact:

Re: Dungeon crawling RPG frame

#31 Post by Zebragirl » Fri Apr 05, 2013 4:14 pm

Hello, this script is really great for combat and very flexible.

I have some questions,and hope I dnt disturb...

I've search in forum, but I cant find a way to add events or graphic effects on skills:
example: (dialogues during combat or the effects of fire, thunder, lightning etc. for hits of skills).
is there a way to put them? or is it too complicated?

Also I can put healing skill?

I know a few things of python, sorry if I ask stupid questions...

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#32 Post by nyaatrap » Fri Apr 05, 2013 7:46 pm

You can use renpy.show to show images inside of python code.
To make skill varieties, add a new attribute "type" on skill class and evaluate it when a skill is used. For example,

Code: Select all

class skill(type="", image="",wait=.3):
    ......

class actor():
    .....
    def command(self,target):
        ......
        if self.skill.type=="attack"
            self.attack(self,skill,target)
        elif self.skill.type=="heal"
            self.heal(self,skill)

    def attack(self,skill,target):
        renpy.show(self.skill.image)
        renpy.pause(self.skill.wait,hard=True) 
        if self.skill.hit<renpy.random.randint (0,100):
        .......
        renpy.hide(self.skill.image) #Usually, hide is needed to work the next animation correctly
   
    def heal(self,skill)
        self.hp += self.skill.power

User avatar
Zebragirl
Newbie
Posts: 8
Joined: Fri Apr 05, 2013 3:54 pm
Contact:

Re: Dungeon crawling RPG frame

#33 Post by Zebragirl » Sat Apr 06, 2013 6:41 am

nyaatrap wrote:You can use renpy.show to show images inside of python code.
To make skill varieties, add a new attribute "type" on skill class and evaluate it when a skill is used. For example,
Thanks for your kind reply.
The images work well, but for the variety of skills I have a invalid syntax

Code: Select all

 if self.skill.type=="attack"
The new attribute maybe I need put it before the first attribute class Skill?

Code: Select all

init -1 python:
     
    
    class Skill():
        def __init__(self, name, hit, power):
            self.name = name
            self.hit = hit
            self.power = power 
    
    
            
    
    class Actor(renpy.store.object):
      def __init__(self, name, max_hp=0, skills=[]):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.skills = skills
        
         
        
      def command(self, target):
            self.skill = renpy.call_screen("command")
            target.skill = renpy.random.choice(target.skills)
            self.attack(self.skill, target)

            if self.skill.=="attack"
             self.attack(self,skill,target)
        elif self.skill.type=="heal"
            self.heal(self,skill)
            
            if target.hp < 1:
                return
            target.attack(target.skill, self)
                
            
        
            
            
        def attack(self,skill,target):
                 
            if self.skill.hit<renpy.random.randint (0,100):
         def heal(self,skill)
               self.hp += self.skill.power
               narrator ("{} dodged {}'s attack".format(target.name,self.name))
                
            else:
                target.hp -= self.skill.power
                narrator ("{} got {} damage".format(target.name, self.skill.power)) 
Thanks again for the answers

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#34 Post by nyaatrap » Sat Apr 06, 2013 7:25 am

It's __ini__ which creates attributes when objects are created.

Code: Select all

class Skill():
        def __init__(self, name, hit, power, type="attack"):
            self.name = name
            self.hit = hit
            self.power = power
            self.type = type
Then create objects:

Code: Select all

label start:
    $ thunder = SKill("Thunder", 80, 15)
    $ heal = Skill("Heal", 0, 10, "heal")
So you can evaluate heal.type.

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: Dungeon crawling RPG frame

#35 Post by Ryue » Sat Apr 06, 2013 7:53 am

@Zebragirl

Code: Select all

   if self.skill.=="attack"
             self.attack(self,skill,target)
self.skill. <--something is missing here

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: Dungeon crawling RPG frame

#36 Post by Zeroized » Mon Apr 08, 2013 12:09 am

Thanks for your earlier help. However, I've hit another roadblock.
I've been tweaking the fighting part of the script to do some stuff, so I've changed the some of the skills to work with some variables that I've defined earlier in other parts of the game, outside of the python script.

Code: Select all

            $ level = 1
            $ STR = 5
            $ END = 5
            $ AGI = 5
            $ INT = 5
            $ LDR = 5
            $ LCK = 5
            $ GOLD = 0
            
            $ Attack = Skill("Attack", 0, (50+AGI/2), STR, "none")
            
            $ player = Fighter (charname, (END*10), (INT*10), [Attack, Wait], [])
The last [] is for the status changing attacks, as you kindly suggested. When I tried the script, it worked, and the player's attack did 5 damage, as intended.
The problem begins when I try to change the stats. I've created a level up part where every stat us raised by 1. I can see the stats being changed in-game, however, the HP stays at 50, the MP stays at 50, and it doesn't matter how much I change the stats, the attack keeps doing 5 damage.

How can I refresh the variables? Do I need to add the fight code again every time the character levels up? Do I need to define the player part every time I change the stats?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#37 Post by nyaatrap » Mon Apr 08, 2013 9:22 am

It just makes things difficult when you mix instances and variables. You should put anything in instances.
Add these variable on the class, and define level up method, then call it when an actor levels up.

Code: Select all

    class Actor(renpy.store.object):
        def __init__(self, name, max_hp=0, level=1, str=1, ....., skills=[]):
            self.name=name
            ......

        def levelup(self):
            self.level += 1
            self.hp += 5
            .......

Code: Select all

label start:
    $player = Actor("name", max_hp=50, level=1, str=5, ........)

label battle_end:
    $player.levelup()

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: Dungeon crawling RPG frame

#38 Post by Zeroized » Mon Apr 08, 2013 4:40 pm

I've changed the class to hold the stats, but my script doesn't seem to work anymore.
When I change the skills using the stat name, I get "NameError: name 'agi' is not defined."
How can I fix that? Here is the code.

Code: Select all

class Fighter(renpy.store.object):
        
        def __init__(self, name, str, end, agi, int, max_hp, max_mp, skills, effect):
            self.name = name
            self.str = str
            self.end = end
            self.agi = agi
            self.int = int
            self.max_hp = end*10
            self.max_mp = int*10
            self.skills = skills
            self.effect = effect
            (Rest of the script...)

label start:

$ Attack = Skill("Attack", 0, (50+agi/2), str, "none")

$ player = Fighter ("Charname", 5, 5, 5, 5, 50, 50, [Attack, Wait])

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: Dungeon crawling RPG frame

#39 Post by Ryue » Mon Apr 08, 2013 5:03 pm

Problem is order of things there
"agi" is not defined.
Only the line
$ player = Fighter ("Charname", 5, 5, 5, 5, 50, 50, [Attack, Wait])

defines that player.agi is defined. But you already need Attack there.
I had a similar problem with my own dungeon crawler (which I'm currently reworking).

Would be interesting what others made there as solution (only thing I came up with is that you had to give the "mob" the skill belongs to to the call parameter of the skill
which is a bit inconvenient).

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#40 Post by nyaatrap » Mon Apr 08, 2013 6:06 pm

You should adjust skill parameters when method is called, rather than when creating these instances.

Code: Select all

class Actor():
    def attack(self,self.skill):
         hitrate = self.skill.hit+self.agi/2

Attack = Skill("Attack", 0, 50, 0, "none")

berley819
Newbie
Posts: 1
Joined: Sun Apr 14, 2013 2:26 am
Contact:

Re: Dungeon crawling RPG frame

#41 Post by berley819 » Sun Apr 14, 2013 2:33 am

Thanks very much! This is super helpful. I was curious if anyone could tell me how to change the player's name into the dynamic character name I use elsewhere. This is the code I used to set it up.

inti:
$ player_name = ""
$ y = DynamicCharacter("player_name", color="#c8ffc8")

label start:
$ Char_name = "player1"

label name:

show Nora happy

n "First, what is your name?"

$ player_name = renpy.input("Your name")

$ player_name = player_name.strip()

if player_name == "":
$ player_name="Jaden"

n "Well I will be calling you %(player_name)s then!"

$ Char_name = "%(player_name)s"

y "Sure seems that way."


********************

Now, I am trying to modify the name here. Let me know if this is not the right place:

init python:
# Create skills (name, hit, power)
Slash = Skill("Slash", 70, 20)

# Create battle actors (name, max_hp, skills)
player = Actor("[???]",100, [Slash])
Goblin = Actor("Goblin",40,[Slash])

As far as player name goes, I have tried "player_name," "[player_name]", and "%(player_name)s" and none work. This is only my third day attempting python so my apologies if this is a really dumb question! I really have been appreciating the help of all the kind, intelligent people on these forums.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#42 Post by nyaatrap » Sun Apr 14, 2013 11:58 pm

Code: Select all

lavel start:
    $playername=renpy.input()
    $player.name=playername

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#43 Post by DapNix » Sun Apr 21, 2013 1:33 pm

I've gotten a bit more accustomed to Python now, but I'm having a hard time with something here..
Is it possible to keep the same battle actor, yet change skills?
If I for instance wanted to have my character learn a new skill in the midst of a battle, how would that be done?
I have also added a leveling system, so it would be best if I could reuse the same battle actor, even though he will learn new skills in the future.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#44 Post by nyaatrap » Sun Apr 21, 2013 9:18 pm

It's simply

Code: Select all

$player.skills.append(skillInstance)
$player.max_hp += 5

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#45 Post by DapNix » Mon Apr 22, 2013 2:00 pm

That worked out, however I also need to know how to remove spells, in case I need to remove some bugs to the game.

I watched the stuff about the leveling system, and just as the previous guy said, the stats go up, but there is no change in my HP and my stats don't do the change they are supposed to do. Can someone help me out there?

Post Reply

Who is online

Users browsing this forum: No registered users