Hey guys, new to this forum, new to ren'py, sorta! I am making a dating sim and one thing that's holding me back is character location.
There are 4 possible locations for Kate- home, office, mall, park.
There are 3 times of the day - morning, afternoon, night.
I want to build a sort-of random schedule based on odds for the player to find Kate at different locations.
For example, the chances of finding Kate at home in the morning is 50%, else 50% chance she is at the office. She cannot be at the mall or park in the morning.
The chances of meeting Kate at office in the afternoon is very high, about 80% else there is 10% chance you will meet her in the park or 10% she is in the mall.
At night, there is 60% chance you will find her at home, 10% chance she is at the mall and 30% chance she could be at the park.
Let know if one of you code ninjas can help me out with a sample code or an example. Any help will be much appreciated.
Randomized character location based on odds?
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.
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.
- Ocelot
- Lemma-Class Veteran
- Posts: 2384
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Randomized character location based on odds?
Something like that:
Code: Select all
init python:
# Takes a list of (value, weight) pairs
# and returns one value
def weighted_random(pairs):
total_weight = sum(n for _, n in pairs)
rvalue = renpy.random.randint(1, total_weight)
for (value, weight) in pairs:
rvalue -= weight
if rvalue <= 0:
return value
define location_chances = {
'morning': [('home', 50), ('office', 50),],
'afternoon': [ ('office', 80), ('mall', 10), ('park', 10),],
'night': [('home', 60), ('mall', 10), ('park', 30),],
}
default time_of_day = 'morning'
default kate_location = weighted_random(location_chances[time_of_day])
# usage:
# Whenever you want to change Kate location
$ kate_location = weighted_random(location_chances[time_of_day])
# Assuming you store time of day in varable. You can also use it like:
$ kate_location = weighted_random(location_chances['night'])
< < insert Rick Cook quote here > >
Re: Randomized character location based on odds?
Hello Ocelot,
Thank you for your code, it's working well ! I was wondering if it could be customized in game with variables.
Like if an event occur, you can't go to work anymore. So it would be convenient to be able to change the character schedule, change the odds or add a location.
Do you think it's possible ?
Thank you for your code, it's working well ! I was wondering if it could be customized in game with variables.
Like if an event occur, you can't go to work anymore. So it would be convenient to be able to change the character schedule, change the odds or add a location.
Do you think it's possible ?
Re: Randomized character location based on odds?
Hi, can someone help me with this dict ? I tried to understand by my own but I'm in a dead end.
Ideally, I just need a way to add or modify a key and its value to a certain period of time.
Ideally, I just need a way to add or modify a key and its value to a certain period of time.
Who is online
Users browsing this forum: Google [Bot], Ocelot