[SOLVED] Random NPC generator help!

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
Mord87
Regular
Posts: 26
Joined: Fri May 31, 2019 7:17 pm
Contact:

[SOLVED] Random NPC generator help!

#1 Post by Mord87 »

Hello!

I would like to create a random npc generator. All I want is to make a random npc which has a name, height, hair colour and body type. The main character walks into the club and starts dancing then the random npc start talking to him. In the dialogue text will be written down the random npc details. I find some helpful information here:

Code: Select all

init python:
    class RandomNPC(): # template
        def __init__(self, namelist):
            self.name = renpy.random.choice(namelist)

label start:
    $ randnamelist = ["Adam", "Bob", "Charles"]
    $ randchar1 = RandomNPC(randnamelist) # creating actual instance
    "[randchar1.name]" # just to check if it's been created
This is working but I don`t know how I can add more details for the character. I need help to add more information from the generated character.
Thank You!
Last edited by Mord87 on Fri Oct 11, 2019 6:09 am, edited 1 time in total.

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Random NPC generator help!

#2 Post by Kia »

it's simple, you can add more attributes to your class:

Code: Select all

init python:
    class RandomNPC(): # template
        def __init__(self, namelist):
            self.name = renpy.random.choice(namelist)
            self.hair = renpy.random.choice(["black", "red", "blond"])
            self.height = renpy.random.randint(150, 210)
            self.body = renpy.random.choice(["thin", "normal", "chubby", "fat"])

label start:
    $ randnamelist = ["Adam", "Bob", "Charles"]
    $ randchar1 = RandomNPC(randnamelist) # creating actual instance
    "[randchar1.name]" # just to check if it's been created
then you can use the chosen attributes to piece together an image to show.

Mord87
Regular
Posts: 26
Joined: Fri May 31, 2019 7:17 pm
Contact:

Re: Random NPC generator help!

#3 Post by Mord87 »

Kia wrote: Wed Oct 09, 2019 12:30 am it's simple, you can add more attributes to your class:

Code: Select all

init python:
    class RandomNPC(): # template
        def __init__(self, namelist):
            self.name = renpy.random.choice(namelist)
            self.hair = renpy.random.choice(["black", "red", "blond"])
            self.height = renpy.random.randint(150, 210)
            self.body = renpy.random.choice(["thin", "normal", "chubby", "fat"])

label start:
    $ randnamelist = ["Adam", "Bob", "Charles"]
    $ randchar1 = RandomNPC(randnamelist) # creating actual instance
    "[randchar1.name]" # just to check if it's been created
then you can use the chosen attributes to piece together an image to show.
It is working perfectly Thank You very much!

I tried to add pictures for different hair colours and body types but it didn't work. Any chance to help me out with it? I just want to show 1-2 large full body picture in the middle when the player meets with the random NPC and a small portrait on the bottom next to the text. I know how to show them but i don't know how I can connect the right picture to the randomized NPC. So if her blonde then show the blond girl picture.
Thank You again!

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Random NPC generator help!

#4 Post by Kia »

you might need layered images to construct your character's image: https://www.renpy.org/doc/html/layeredimage.html

Mord87
Regular
Posts: 26
Joined: Fri May 31, 2019 7:17 pm
Contact:

Re: Random NPC generator help!

#5 Post by Mord87 »

Kia wrote: Wed Oct 09, 2019 11:20 pm you might need layered images to construct your character's image: https://www.renpy.org/doc/html/layeredimage.html
Hello!
I tried so many different variations of codes but I can not do it. I just try to add a portrait pic to the character depending on the hair colour.
Here is my last try:

Code: Select all

init python:
    class RandomNPC(): # template
        def __init__(self, namelist):
            self.name = renpy.random.choice(namelist)
            self.hair = renpy.random.choice(["black", "red", "blonde"])

define e = Character("[randchar1.name]", image="randchar1")
image side randchar1:
    choice ([randchar1.hair] == blonde):
        "blond.jpg"
    choice ([randchar1.hair] == red):
        "red.jpg"
    choice ([randchar1.hair] == black):
        "black.jpg"

label start:
    $ randnamelist = ["Adam", "Bob", "Charles"]
    $ randchar1 = RandomNPC(randnamelist)
    $ randchar2 = RandomNPC(randnamelist)# creating actual instance

    "fsdfsfsfsgfsg"
    e "His/Her name is [randchar1.name] and He/She has [randchar1.hair] hair. The other one's name is [randchar2.name] and He/She has [randchar2.hair] hair." # just to check if it's been created
    e "So you are [randchar1.name] and your hair is [randchar1.hair]"
    e "Hello my name is [randchar1.name] nice to meet you and yes I have a [randchar1.hair] hair."
    e "foesfnjosejnf"
    e "fesonjfosenjfosfe"
    e "Yes I am still here with [randchar1.hair] hair."
    "[randchar2.name]""and I am here as well with [randchar2.hair] hair."
return
Everything is working fine except for the images.
I tried with IF variations and other ways but no luck. For this code the error message is NameError: name 'randchar1' is not defined.
I hope somebody can help me!

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Random NPC generator help!

#6 Post by Kia »

try removing brackets around your attributes, from "choice ([randchar1.hair] == blonde):" to "choice (randchar1.hair == blonde):"
the variables only need brackets around them when they are placed inside a string

Mord87
Regular
Posts: 26
Joined: Fri May 31, 2019 7:17 pm
Contact:

Re: Random NPC generator help!

#7 Post by Mord87 »

Kia wrote: Fri Oct 11, 2019 1:26 am try removing brackets around your attributes, from "choice ([randchar1.hair] == blonde):" to "choice (randchar1.hair == blonde):"
the variables only need brackets around them when they are placed inside a string
I had to modify the code a little but it is working now. I had to define them first.

Code: Select all

init python:
    class RandomNPC(): # template
        def __init__(self, namelist):
            self.name = renpy.random.choice(namelist)
            self.hair = renpy.random.choice(["black", "red", "blonde"])

define randnamelist = ["Adam", "Bob", "Charles"]
define randchar1 = RandomNPC(randnamelist)
define e = Character("[randchar1.name]", image="randchar1")

image side randchar1:
    choice (randchar1.hair == "blonde"):
        "blond.jpg"
    choice (randchar1.hair == "red"):
        "red.jpg"
    choice (randchar1.hair == "black"):
        "black.jpg"
Thank You!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]