News:

Please request registration email again and then check your "Spam" folder

Former www.henthighschool.com

[Resources] Trait King mod

Started by neronero, May 16, 2022, 08:26 PM

Previous topic - Next topic

AlolanNinetales

Quote from: neronero on Apr 02, 2024, 06:46 PM
Quote from: AlolanNinetales on Apr 02, 2024, 05:03 PMHeya, I'm in the process of learning how to create more traits. I was trying to make a trait called "Bunny girl" where basically if she was wearing the bunny girl attire it would give her a really big stat and income boost but only if she was wearing bunny girl clothing. Basically very similar to the "Fashionista" trait but specifically for the bunny tag. Would that be possible? If so, could anyone point me in the right direction?
To make it work with the bunny tag, it's not going to be simple, but here's how it could be done:

You would need to modify the core game so that you can execute code whenever it's retrieving a picture with the "bunny" tag. The most straightforward way to do that would be at the end of def get_pic in BKfunctions.rpy

<at the end of get_pic in BKfunctions.rpy>

...

if girl.has_trait("Bunny girl") and pic.has_tag("bunny"):
    <execute a mod's code>

I'm not sure what exactly the mod's code would be from that point on, because even once you know that the game has retrieved an image with the bunny tag, there are still a lot of questions to resolve. You don't know in what context that image is being used, or how you would apply a bonus (do you apply a generic income bonus for the rest of the day, or do you need to make more changes to the core game in several places to check/modify reward calculations for specific types of work?)

But besides all that, this'd be an absurdly niche/imbalanced trait because I bet that 95% of girlpacks don't even contain any images with the "bunny" tag (so it'd be a useless trait for them) and at the other end of the spectrum there may be a few bunny-girl packs that contain only images with "bunny" tags. So in general I wouldn't recommend basing a trait on tags.

To make it work with the bunny items (bunny ears and bunny suit), more like fashionista, should be a lot easier and likely wouldn't require modifications to the vanilla game. You could give her a trait that doesn't do anything special on its own, but add code in your mod that gives an income/stat boost effect at the start of each day/night if she has both this trait and bunny equipment. Eg:

<in a mod or in a girl's event.rpy file>

...

if girl.has_trait("Bunny girl"):
    for item in girl.equipped:
        if "bunny" in item.name.lower():
            <execute a mod's code>
I appreciate the quick response! yeah i was trying to make niche traits for certain original girls but i figured this would be a lot more complicated than i could handle. However with that being said, is there a way you can always make sure an original girl is given a trait? Like in her events.rpy, if shes an orignal girl, she will have X trait? This is again also niche and if it's really complicated I'll probably just scrap the idea

neroneroTopic starter

Quote from: AlolanNinetales on Apr 02, 2024, 08:17 PMI appreciate the quick response! yeah i was trying to make niche traits for certain original girls but i figured this would be a lot more complicated than i could handle. However with that being said, is there a way you can always make sure an original girl is given a trait? Like in her events.rpy, if shes an orignal girl, she will have X trait? This is again also niche and if it's really complicated I'll probably just scrap the idea
Yes, that's a lot easier, so easy that I made a complete example for you ;D

Here's the code to put in your girl's own .rpy file:

init -2 python:

    def add_my_custom_trait(girl): ## Remember to change "add_my_custom_trait" to something unique, and then add it to your BK.ini under init_function (in the [background story] category)

    # This code is executed when your girl is being created (for her first appearance in the slavemarket or in the city)
    # The trait is added to whatever other traits she spawns with
    # If keep_init is false in her BK.ini, then it'll only apply to an original version of her
       
        global gold_traits, pos_traits, neg_traits
        global trait_dict

        # Define your trait here
        my_trait =  Trait("Comedian", verb = "be a", eff1 = Effect("change", "charm", 25), eff2 = Effect("boost", "waitress jp gains", 0.25), base_description = "She's funny.")
       
        # Adding the trait to trait_dict will make it a trait that other girls can spawn with & quests/contracts can request
        add_to_dictionary = False
       
        try: # If your trait has a name that already exists in the dictionary, we can keep things simple and add it immediately (even if it has been added to the dictionary by a mod such as Trait King)
       
            girl.add_trait(trait_dict[my_trait.name])
       
        except:

            if add_to_dictionary:
                gold_traits += [my_trait] # change this to gold_traits, pos_traits or neg_traits depending on how strong your trait is
                trait_dict[my_trait.name] = my_trait
                girl.add_trait(trait_dict[my_trait.name])
            else:
                girl.add_trait(my_trait)
           
        return
Important: Remember to change the name of the function "add_my_custom_trait" to something unique, and then add that name in quotes to your BK.ini under init_function (in the [background story] category)
If you want the code to only run for original girls, you can control that in the BK.ini: Under [cloning options], set keep_init to False.
My Girl Packs: [ link ] - Trait King mod: [ link ]

Goldo

For this I would rather recommend using the built-in _BK.ini framework:

[base positive traits]

## A girl may only have 2 positive traits in vanilla BK. Gold traits are included in positive traits.
## Trait names must be between quotes (""), spelled exactly as they are in-game. See BKtraits.rpy for the full list of trait names.

## The girl will ALWAYS have these traits (up to maximum nb of traits). Use with caution as it makes girl generation very predictable.
always = ["Bunny girl"]

[...]

## Cloning Options ##
keep_traits = False # If True, clones will keep the same base positive and negative trait settings.

To make this work, you'd need to add this trait to the trait dictionary from your mod. Add something like this to your init label:
label my_mod_init():
   $ trait_dict["Bunny girl"] = Trait("Bunny girl", verb = "be a", base_description = "Shake up your bun bun.")

Quote from: neronero on Apr 03, 2024, 10:16 AM# Adding the trait to trait_dict will make it a trait that other girls can spawn with & quests/contracts can request

Actually no, the cool thing about the trait dictionary is that it is only used a a reference table. The actual trait generation is handled with three lists (gold_traits, pos_traits and neg_traits). The one exception is that the traits in the trait_dict may be chosen randomly as a customer's fetish (but not in quests/contracts), which at this point I'd be tempted to call a feature instead of a bug.

I haven't tested this, mind you, but I think it should work.
Maker of BK. Looking for the latest patch for BK 0.2? The link doesn't change, so bookmark it!

AlolanNinetales

Quote from: neronero on Apr 03, 2024, 10:16 AM
Quote from: AlolanNinetales on Apr 02, 2024, 08:17 PMI appreciate the quick response! yeah i was trying to make niche traits for certain original girls but i figured this would be a lot more complicated than i could handle. However with that being said, is there a way you can always make sure an original girl is given a trait? Like in her events.rpy, if shes an orignal girl, she will have X trait? This is again also niche and if it's really complicated I'll probably just scrap the idea
Yes, that's a lot easier, so easy that I made a complete example for you ;D

Here's the code to put in your girl's own .rpy file:

init -2 python:

    def add_my_custom_trait(girl): ## Remember to change "add_my_custom_trait" to something unique, and then add it to your BK.ini under init_function (in the [background story] category)

    # This code is executed when your girl is being created (for her first appearance in the slavemarket or in the city)
    # The trait is added to whatever other traits she spawns with
    # If keep_init is false in her BK.ini, then it'll only apply to an original version of her
      
        global gold_traits, pos_traits, neg_traits
        global trait_dict

        # Define your trait here
        my_trait =  Trait("Comedian", verb = "be a", eff1 = Effect("change", "charm", 25), eff2 = Effect("boost", "waitress jp gains", 0.25), base_description = "She's funny.")
       
        # Adding the trait to trait_dict will make it a trait that other girls can spawn with & quests/contracts can request
        add_to_dictionary = False
       
        try: # If your trait has a name that already exists in the dictionary, we can keep things simple and add it immediately (even if it has been added to the dictionary by a mod such as Trait King)
       
            girl.add_trait(trait_dict[my_trait.name])
      
        except:

            if add_to_dictionary:
                gold_traits += [my_trait] # change this to gold_traits, pos_traits or neg_traits depending on how strong your trait is
                trait_dict[my_trait.name] = my_trait
                girl.add_trait(trait_dict[my_trait.name])
            else:
                girl.add_trait(my_trait)
           
        return
Important: Remember to change the name of the function "add_my_custom_trait" to something unique, and then add that name in quotes to your BK.ini under init_function (in the [background story] category)
If you want the code to only run for original girls, you can control that in the BK.ini: Under [cloning options], set keep_init to False.
Heya! I tried doing it with the example you've given me (which is easy to follow but i am just a baby when it comes to coding) And i can't seem to be getting it to work. I don't know exactly what I'm doing wrong but here is the code I put into my girl's BK_ini
[background story]
 
init -2 python:

    def custom_trait(girl): ## Remember to change "add_my_custom_trait" to something unique, and then add it to your BK.ini under init_function (in the [background story] category)

    # This code is executed when your girl is being created (for her first appearance in the slavemarket or in the city)
    # The trait is added to whatever other traits she spawns with
    # If keep_init is false in her BK.ini, then it'll only apply to an original version of her
      
        global gold_traits, pos_traits, neg_traits
        global trait_dict

        # Define your trait here
        my_trait =  Trait("Bunny Girl", verb="be a", effects=[Effect("boost", "dress", 0.69, scales_with = "rank")], archetype="The Model", base_description = "A world renown Bunny Girl that has become famous due to her alluring beauty.")
      
        # Adding the trait to trait_dict will make it a trait that other girls can spawn with & quests/contracts can request
        add_to_dictionary = False
      
        try: # If your trait has a name that already exists in the dictionary, we can keep things simple and add it immediately (even if it has been added to the dictionary by a mod such as Trait King)
      
            girl.add_trait(trait_dict[my_trait.name])
      
        except:

            if add_to_dictionary:
                gold_traits += [my_trait] # change this to gold_traits, pos_traits or neg_traits depending on how strong your trait is
                trait_dict[my_trait.name] = my_trait
                girl.add_trait(trait_dict[my_trait.name])
            else:
                girl.add_trait(my_trait)
          
        return


I'm sure I am probably just putting this code in the wrong place or something like that. If you could possibly help I would appreciate it  :'(

neroneroTopic starter

Quote from: AlolanNinetales on Apr 10, 2024, 01:39 AMI'm sure I am probably just putting this code in the wrong place or something like that. If you could possibly help I would appreciate it  :'(
Yup  ;D

The python code should go in an .rpy file in your girl folder, eg: "_custom_trait.rpy"
You can make the file with a text editor like notepad, just make sure to save it with the extension ".rpy" instead of .txt

Then in your _BK.ini file, you only need to mention the name of the init_function under [background story]:
[background story]

## If provided, this function will be called when a girl with this template is created, after randomization.
## It must take 'girl' as an argument. It must not interrupt game flow (python only, no ren'py calls or jumps).
## Write the function in an init block in _events.rpy or another custom .rpy file.
init_function = "custom_trait" ; provide a custom function name that is called after girl creation (between quotes)
"custom_trait" refers to def custom_trait(girl) in the .rpy file, so if you change that name in the rpy file, it must also change in the BK.ini
Note that I don't think "custom_trait" is a good name. The reason why this has to be unique, is that the game will crash if the same name is used twice.
Try to pick a name that has your girl's name or your own name in it for example. Something that Goldo or another modder or packmaker is unlikely to ever choose as a name, even accidentally.
My Girl Packs: [ link ] - Trait King mod: [ link ]

Kyoto Nixon

Am i doing something wrong? when i activate this mod - i get duplicates of all the original traits in the game (i can see them with the King's Way mod)

Is there a way to overwrite it or is that intended?

neroneroTopic starter

Quote from: Kyoto Nixon on Apr 10, 2024, 10:07 AMAm i doing something wrong? when i activate this mod - i get duplicates of all the original traits in the game (i can see them with the King's Way mod)

Is there a way to overwrite it or is that intended?
That does sound like something went wrong in the installation/start-up. Trait King replaces the original trait dictionary entirely, so duplicates shouldn't exist in any way. Did you start a new game, or are you trying to activate it halfway though a save/playthrough?

I haven't tested it with King's Way, but I doubt that's causing an issue.
My Girl Packs: [ link ] - Trait King mod: [ link ]

AlolanNinetales

Quote from: neronero on Apr 10, 2024, 09:28 AMThe python code should go in an .rpy file in your girl folder, eg: "_custom_trait.rpy"
Thank you so much!! I got it to work thanks to your help!  ;D  Lastly I just wanted to make sure the color of the trait comes up as gold, what do i tweak in the _custom_traits.rpy for the color of the trait to change?

neroneroTopic starter

Quote from: AlolanNinetales on Apr 10, 2024, 05:57 PM
Quote from: neronero on Apr 10, 2024, 09:28 AMThe python code should go in an .rpy file in your girl folder, eg: "_custom_trait.rpy"
Thank you so much!! I got it to work thanks to your help!  ;D  Lastly I just wanted to make sure the color of the trait comes up as gold, what do i tweak in the _custom_traits.rpy for the color of the trait to change?
To make it come up as a gold trait, the trait must be added to the gold_traits dictionary, which'll happen by changing add_to_dictionary = True - but this'll also mean that other girls will spawn with the trait. You can't give the trait a color without making it available for other girls.
My Girl Packs: [ link ] - Trait King mod: [ link ]