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 30th May 2020 at 2:40 PM
Default Python (fame, slider values, statistics)
Hello,

Besides what I asked in my other question, I'm also trying to do the following in Python:
  • Get the current fame level of a Sim.
  • Get the value of a particular CAS slider.
  • Get the value of any particular statistic.

The 3rd point is about those statistics like "how many times slept in a coffin" and things like that. Thanks for any help!
Advertisement
Test Subject
Original Poster
#2 Old 30th May 2020 at 2:50 PM
Ok, I was able to get the fame. I wasn't able to get the level directly, but I was able to convert it by checking the numbers in-game. I'm sure there is a proper method for getting the level, but, for now, this will do.

Code:
from fame.fame_tuning import FameTunables
import services

# First, we get the Sim info we are going to work with.
# In this case, I'm getting the active sim.
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info

# Then we get the Fame statistic itself.
stat_fame = sim_info.get_statistic(FameTunables.FAME_RANKED_STATISTIC)

# Initializing the variable.
fame = 0

# Just making sure the statistic is there.
if stat_fame is not None:

    # Then we get the raw value of the statistic.
    fame_raw = stat_fame.get_value()

    # Then we convert into the appropriate levels.
    if fame_raw >= 5195:
        fame = 5
    elif fame_raw >= 3334:
        fame = 4
    elif fame_raw >= 1917:
        fame = 3
    elif fame_raw >= 837:
        fame = 2
    elif fame_raw >= 162:
        fame = 1


If anyone has tips for other points, please share!
Test Subject
Original Poster
#3 Old 2nd Jun 2020 at 3:50 PM Last edited by AnaBelem : 2nd Jun 2020 at 5:02 PM.
Well, getting the statistics wasn't hard at all. The game treats them as 'objectives' in the aspiration tracks.

Code:
from sims4.resources import Types, get_resource_key
import services

# I'm using the active sim, but any sim will do.
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info

# First you need the objective ID, get it at the XML.
obj_id = 'example_ID'

# Then you need the manager.
obj_manager = services.get_instance_manager(Types.OBJECTIVE)

# We use the manager to get the instance for our particular ID.
obj_instance = obj_manager.get(get_resource_key(obj_id, Types.OBJECTIVE))

# To get the count, we use this method.
obj_count = sim_info.aspiration_tracker.get_objective_count(obj_instance)
Test Subject
#4 Old 2nd Jun 2020 at 4:45 PM
Getting the slider values is not hard. The difficult part is getting the IDs. The following command will get the IDs and values in a text file, but I couldn't get the names. You will have to check the values against what you get in-game.

Code:
from server_commands.argument_helpers import get_optional_target, OptionalSimInfoParam
import sims4.commands
from protocolbuffers import PersistenceBlobs_pb2
import itertools
import os


@sims4.commands.Command('slider_list', command_type=sims4.commands.CommandType.Live)
def slider_list(opt_sim:OptionalSimInfoParam=None, _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    
    # This is a trick to get the sim in a different manner.
    sim_info = get_optional_target(opt_sim, target_type=OptionalSimInfoParam, _connection=_connection) 
    if sim_info is None:
        return False
    
    # This is the blob thing that gets the slider templates.
    facial_attributes = PersistenceBlobs_pb2.BlobSimFacialCustomizationData()
    facial_attributes.MergeFromString(sim_info.facial_attributes)

    # Just getting the script path.
    pathname = os.path.dirname(os.path.realpath(__file__))
    if pathname.lower().endswith('.zip') or pathname.lower().endswith('.ts4script'):
        pathname = os.path.dirname(pathname)

    # File will be at the script directory with name 'sim_id.sliders.txt'
    filename = os.path.join(pathname, str(sim_info.sim_id) + '.sliders.txt')

    # Opening file to writing.
    with open(filename, 'w') as file:
        mod_strings = []

        # Building the slider list.
        for modifier in itertools.chain(facial_attributes.face_modifiers, facial_attributes.body_modifiers):
            mod_strings.append(str(modifier))

        # Writing the file.
        file.write('\n'.join(mod_strings))
        
    return True


Once you know the ID you want, you can get the slider value in your code like this:

Code:
from protocolbuffers import PersistenceBlobs_pb2
import services
import itertools

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

# Use the slider ID you got.
slider_id = 'example'

# Get the blob thing. It is called 'facial' but actually includes the body sliders as well.
facial_attributes = PersistenceBlobs_pb2.BlobSimFacialCustomizationData()
facial_attributes.MergeFromString(sim_info.facial_attributes)

# Iterate over the attributes, checking against the slider ID.
for modifier in itertools.chain(facial_attributes.face_modifiers, facial_attributes.body_modifiers):

    # This is your slider value.
    if str(modifier.key) == slider_id:
        slider_value = modifier.amount
Test Subject
Original Poster
#5 Old 2nd Jun 2020 at 5:12 PM
Thanks, I managed to get the slider IDs by using your command and comparing the values with the sliders in MC Command Center. I'm sure there is a proper way of getting their names in a list or tuning file, but your solution worked very well.

Thanks a lot!
Test Subject
Original Poster
#6 Old 2nd Jun 2020 at 5:21 PM
If people want to get the slider IDs, what I did was set them, using MCCC, to really obvious values in an example sim (values like 1, 2, 3, 4...). Then I ran BethA's command to generate the file. That way it was really easy to identify which value was which.
Back to top