Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 2nd Jun 2020 at 3:57 PM Last edited by AnaBelem : 2nd Jun 2020 at 5:05 PM.
Default Python (buffs, mood and fit/fat sliders)
Ok,

With some help, I'm still going strong! Besides what I already learned, I'm still trying to do the following, please help if you can.

  • Get the current mood for a sim.
  • Assign/Remove a particular buff.
  • Get the value of the CAS fit slider.
  • Get the value of the CAS fat slider.
Advertisement
Test Subject
#2 Old 2nd Jun 2020 at 4:58 PM
Getting the fit/fat sliders is not difficult, it is just awkward.

Code:
import services

# Get you sim. I'm just using the active.
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info

# Get the physique and split it.
physique = sim_info.physique.split(',')

# It will be split like this, in absolute values.
# Fat Pos | Fit Pos | Fat Neg | Fit Neg

# So to get the actual value, we use:
fat_slider = float(physique[0]) - float(physique[2])
fit_slider = float(physique[1]) - float(physique[3])

Test Subject
Original Poster
#3 Old 2nd Jun 2020 at 5:24 PM
Thanks again!

You did most of the hard work. I think the rest will be easy to get.
Test Subject
Original Poster
#4 Old 5th Jun 2020 at 12:53 PM
Well, getting the mood is ridiculously easy. Sims have built-in methods to do it.

Code:
import services

# I'm using the active sim for demonstration.
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info

# This gets the mood object, which you can then access.
mood = sim_info.get_mood()

# Getting the mood name is a bit messy.
mood_name = mood.__name__.split('_', 1)[-1]

# This gets the mood intensity.
intensity = sim_info.get_mood_intensity()

# Intesity is rated 0-2, like this:
if intensity == 2:
    intensity_name = "extreme"  # Just exists for a few moods, like angry.
elif intensity == 1:
    intensity_name = "very"
elif intensity == 0:
    intensity_name = "normal"  # Some have just this level, like bored and fine.
Test Subject
#5 Old 5th Jun 2020 at 2:11 PM
Hey, there,

I was having trouble with the buffs. The obvious methods in sim_info add a buff that is impossible to remove, with no timer. I had to dig into the commands and found other methods that work.

Code:
import services

# Get your sim.
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info

# Get your ID from the tuning files.
buff_id = 'example'

# Get the manager and instance.
buff_manager = services.get_instance_manager(Types.BUFF)
buff_test = buff_manager.get(get_resource_key(buff_id, Types.BUFF))

# This adds the buff, allowing it to be removed.
sim_info.debug_add_buff_by_type(buff_test)

# This removes the buff properly.
sim_info.remove_buff_by_type(buff_test)


# These didn't work, the buff was permanent.
sim_info.add_buff(buff_test)
sim_info.remove_buff(buff_test)

Test Subject
Original Poster
#6 Old 5th Jun 2020 at 2:26 PM
Nice, that does work. I was having the same trouble. I don't know if that is related to the particular buff or the method of adding it though.
Lab Assistant
#7 Old 23rd Feb 2022 at 3:12 AM
I know this thread is a couple years old at this point, but I thought I'd add some thoughts in case anyone else finds it helpful. AnaBelem's solution to get the mood is exactly right, but the mood name only works in English, as the code is in English. I wanted to get the localized string of the mood name so that I could pass it in as a text token and have it work across translations.

I figured out that .mood_names returns a list of localized strings, where the index is equal to the mood intensity. This worked great as a token for English, but then I realized that mood names can be gender specific in other languages, so you need to pass the sim_info in as an argument when calling it or you'll get an empty string.

Code:
# After you've gotten the sim_info, you can get the mood.
mood = sim_info.get_mood()

# Then we need to get the intensity of the mood. 
intensity = sim_info.get_mood_intensity()

# Since the intensity is equal to the index of the string, we can pass that in to mood_names to return the string.
mood_name = mood.mood_names[intensity]

# This will return a localized string object which can be called in a notification, but this also only works in English.
# In French, for example, the string is gender specific: {M.Heureux}{F.Heureuse}
# So, when you call the string, you need to call the sim_info as your first argument.
# Here is an example where you can pass the mood_name in as a text token, where 12345678 is your string hash.
localized_text = lambda *_, **__: _create_localized_string(12345678, sim_info, mood_name)

# If you want to just call the mood name by itself, you can still do that.  The problem is the string is already localized,
# so if you were to call it as is, you can't pass in tokens.  This is clumsy and I'm sure there's a better way, but you
# can get the hash of the mood name like this:
hash_string = str(mood_name)

# It will return something to the cheat output like 'hash: 123456'.  So then you can do this:
mood_hash = int(hash_string[6:])

# Then, you can call the string and pass in tokens like you normally would.
localized_text = lambda *_, **__: _create_localized_string(mood_hash, sim_info)
Back to top