Create and Fuck your AI Cum Slut -70% OFF
x

Ren'Py [Solved]how to add pregnancy to this code for each character?

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,228
3,239
how to add pregnancy to this code for each character?

characters at certain time and locations

images name would like so

with minutes mom_12_0_livingroom.png

without minutes mom_12_livingroom.png

this fully working code anyone can use it if they want too

class.rpy (you can remove the minutes so the character stay in that location longer)

Python:
class NPC(object):

    def __init__(self, name, nicename, location, hours, minutes, lbt=""):
        self.name = name
        self.nicename = nicename
        self.location = location
        self.hours = hours
        self.minutes = minutes
        self.lbt = lbt

    @property

    def avatar(self):
        #If you remove the minutes remove one of the {} and remove str(minutes),
        avtr = "images/avatar/{}/{}_{}_{}_{}.png".format(self.name, self.nicename, str(hours), str(minutes), location)

    if renpy.loadable(avtr):
        return avtr
    else:
        return "images/avatar/empty.png"


character_screen.rpy

Python:
screen charcater_screen():

   # remove and q.minutes == minutes if you are planning to remove minutes
    for q in NPCS:
         if q.location == location and q.hours == hours and q.minutes == minutes:
            imagebutton:
                idle q.avatar
                hover q.avatar
                focus_mask True
                action Call(q.lbt)

default.rpy

Python:
default lbt = ""  #lbt is for labels
default NPCS = []
default hours = 0
default minutes = 0


#make sure you use call InitialiseVariables

label InitialiseVariables:

    #If you remove minutes just remove the minutes out
    $ NPCS.append(NPC("mom", "mom", "livingroom", 12, 0, lbt="test"))
    #$ NPCS.append(NPC("character_name", "folders name", location", hour, minutes, lbt="label"))

    return


script.rpy


Python:
label start:

    call InitialiseVariables
    return

then create screen with


use charcater_screen
 

Winterfire

Conversation Conqueror
Respected User
Game Developer
Sep 27, 2018
6,101
8,838
Just extend avtr to take pregnancy into consideration as well. If anything, it makes more sense than having minutes/hours, that shouldn't be contained in the name of the file you're going to be using... That's going to be hell if you ever plan to edit it. That should be kept inside the script, completely unnecessary to expose it to the name of the file imho.
 
  • Like
Reactions: anne O'nymous

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,228
3,239
Just extend avtr to take pregnancy into consideration as well. If anything, it makes more sense than having minutes/hours, that shouldn't be contained in the name of the file you're going to be using... That's going to be hell if you ever plan to edit it. That should be kept inside the script, completely unnecessary to expose it to the name of the file imho.
something like this

Python:
def avatar(self):
        #If you remove the minutes remove one of the {} and remove str(minutes),
        avtr = "images/avatar/{folder_name}/{name}_{nicename}_{hours}_{minutes}_{pregnancy}.png".format(self.name, self.nicename, str(hours), str(minutes), location, self.pregnancy)
and put pregnancy in the class

Python:
label InitialiseVariables:

    #If you remove minutes just remove the minutes out
    $ NPCS.append(NPC("mom", "mom", "livingroom", 12, 0, pregnancy=False  lbt="test"))
    #$ NPCS.append(NPC("character_name", "folders name", location", hour, minutes, lbt="label"))

    return
something like that?
but I don't all characters pregnant at the same time though
 

Winterfire

Conversation Conqueror
Respected User
Game Developer
Sep 27, 2018
6,101
8,838
Yes, but I'd suggest against using the boolean raw, this way you can simply add a simple "P" to avoid making the name too long. What do you mean you don't want the characters pregnant at the same time? That piece of code calls the file for the right sprite at that moment, for each character, no? You're basically parsing the variable value into a string and use it to call the file name. If you change the variable, the file called will be different.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,338
19,779
Python:
class NPC(object):

    def __init__(self, name, nicename, location, hours, minutes, lbt=""):
Why is the time values part of the character definition?

This make no sense since they all live in the same universe, same planet, and more than surely same town. The time is always the same for all characters and have no reason do be defined here.
But pregnancy have a reason and should be added:

Python:
    def __init__(self, name, nicename, location, pregnancy=False, lbt=""):
        self.pregnancy = pregnancy
        [...]

Python:
    @property

    def avatar(self):
        #If you remove the minutes remove one of the {} and remove str(minutes),
        avtr = "images/avatar/{}/{}_{}_{}_{}.png".format(self.name, self.nicename, str(hours), str(minutes), location)

    if renpy.loadable(avtr):
        return avtr
    else:
        return "images/avatar/empty.png"
As Winterfire said, there's no need to have both "hours" and "minutes" here. It would force you to have 1440 different sprites for each character, this for each location.
A "period" value, to have a different sprite for the morning, noon, afternoon, and night, can possibly have an interest (but not really in your game), but not a granularity as small as minutes.
This especially when there's either a valid character spriteor a none empty default sprite. 99% of the time your code will return the empty one.
Anyway, a value representing the occupation would be more interesting here than the period.

And, once again, it's here that the pregnancy should be used, as you did.

Plus, if this is actually the code you used:
Python:
def avatar(self):
        #If you remove the minutes remove one of the {} and remove str(minutes),
        avtr = "images/avatar/{folder_name}/{name}_{nicename}_{hours}_{minutes}_{pregnancy}.png".format(self.name, self.nicename, str(hours), str(minutes), location, self.pregnancy)
Then there's absolutely no reason for the pregnancy to apply to all characters. This can only happen if you changed self.pregnancy to all the characters instead of the sole character that is now pregnant.


More globally, you're following the wrong logic, taking everything from its ending point.


Your NPC class should looks like:
/!\ Warning, wrote on the fly /!\
Python:
class NPC( renpy.python.RevertableObject ):
    def __init__(self, ID, name, nicename, schedule, pregnancy=False):
        #  Will be used for the label.
        self.ID = ID
        self.name = name
        self.nicename = nicename
        #  Where is the character, at what time
        self.schedule = schedule
        #  Is the character currently pregnant?
        self.pregnancy = pregnancy

    @property
    def isPresent( self, location=None, hour=None ):
        ''' 
            Return True if the character is, or will be, present in the given location at the given time.

            If /location/ and/or /time/ are not provided, will check for the current player location
           and/or right now.
        '''

        #  When not specified, use the player location from the global variables
        if not location:
            location = store.location
        #  When not specified, use the current time from the global variables
        if not hour:
            location = store.hours

        #  Will return True if the girl schedule for the given /hour/ is the given /location/,
        # will return False else.
        return self.schedule.location( hour ) == location

    @property
    def avatar(self):
        '''
            The sprite will be the character, at the current location, doing what the character is doing,
           and adding the "pregnant" suffix if it apply.

            By example:
              images/avatar/mom/kitchen_cooking.png
              images/avatar/mom/kitchen_eating_pregnant.png
        '''
        avtr = "images/avatar/{}/{}_{}{}.png".format(self.name, store.location, self.schedule.action, "_pregnant" if self.pregnancy else "" )

        if renpy.loadable(avtr):
            return avtr
        else:
            #  If the sprite is missing, return a default sprite showing the girl in top of the background.
            return "images/avatar/{}/default{}.png".format( self.name, "-pregnant" if self.pregnancy else "" )

    @property
    def label( self ):
        ''' Label to call for interaction. '''

        return "{}_{}_hub".format( self.ID, self.schedule.location( store.hours ) )


class Schedule( renpy.python.RevertableObject ):

    def __init__( self, schedule ):

        #  Where is she doing at a given hour.
        self.location = {}
        #  What is she doing at a given hour.
        self.action = {}

        for atom in schedule:
            self.location[atom[0]] = atom[1]
            self.action[atom[0]] = atom[2]


    #  Return the location of the character at the given hour.
    #  Get the hour as argument since it can be called preventively.
    def location( self, hour ):
        #  If there's no entry for this hour, the character is nowhere...
        if not hour in self.location:
            return None
        #  else she's where her schedule is saying.
        else
            return self.location[hour]

    #  Return what she's doing.
    #  Do not take argument because it's only called to defined the sprite,
    # therefore the value can never be None.
    @property
    def action( self ):
        return self.action[store.hours]

    def update( self, hour, location, action ):
        self.location[hour] = location
        self.action[hour] = action

    def delete( self, hour ):
        if hour in self.location:
            del self.location[hour]
        if hour in self.action:
            del self.action[hour]


label InitialiseVariables:
    #  Note that I used a 30 minutes granularity. So, 7h, 7h30, 8h...
    $ tmp = Schedule( [ ( 700, "kitchen", "cooking" ), ( 730, "kitchen", "eating" ), ( 800, "bathroom", "showering" ), ( 830, "motherBedroom", "dressing" ), [...] )
    $ mom = NPC( "MOM", "mom", "mommy", tmp )
    [...]

screen charcater_screen():

    for q in NPCS:
         if q.isPresent():
            imagebutton:
                idle q.avatar
                hover q.avatar
                focus_mask True
                action Call(q.label)

label MOM_kitchen_hub:
    [...]

label MOM_motherBedrom_hub:
    [...]

label whatever:
    $ mom.schedule.update( "2200", "motherBedroom", "masturbating" )


screen mapUI():

    for q in Rooms:
        $ TempName = "images/maps/map_" + q.name + ".png"
        imagebutton:   
            focus_mask True
            idle TempName
            hover TempName
            action SetVariable("clickType", "move"), Return(q.name)

        #  This need a bit of work to look nice.
        for npc in NPCS:
            if npc.isPresent( store.hours, q.name ):
                add [whatever overlay showing that the character is at this place]
Since I'm here:
if location == "livingroom" or location == "kitchen" or location == "bathroom" or location == "motherBedroom" or location == "mybedroom" or location == "twinbedroom":
would be better like that:
if location in [ "livingroom", "kitchen", "bathroom", "motherBedroom", "mybedroom", "twinbedroom" ]:

And, once again, there's absolutely no reason, even in your code, for the pregnancy to apply to everyone.