Forum Discussion

ParallaxPlays's avatar
7 years ago

Pulling Statistics from Game to Text File

Good evening,

I'm working on a mod that would pull the stats found in the Simology panel and dump them to a text file outside the game. I've got everything (I think) besides actually pulling the stats for a given sim. Here's my code so far (thank you to Scumbumbo for the code I worked from, it was a huge help):


import sims4.commands
import services


def get_siminfo_by_name(fname, lname, output, _connection):
if fname is not None:
info = services.sim_info_manager().get_sim_info_by_name(fname, lname)
if info is None:
output("Error: Sim {} {} not found".format(fname, lname))
return None
else:
tgt_client = services.client_manager().get(_connection)
if tgt_client is not None:
info = tgt_client.active_sim.sim_info
else:
output("Error: no active sim targeted")
return None
return info

@sims4.commands.Command('challenge.view', command_type=sims4.commands.CommandType.Live)
def challenge_view(fname=None, lname=None, _connection=None):
output = sims4.commands.CheatOutput(_connection)

if fname is not None and lname is None:
output("usage: challenge.view ")
return False

info = get_siminfo_by_name(fname, lname, output, _connection)
if info is None:
return False


My question is, where can I find the command on how to actually pull the stats? I've looked through the EA python code, but haven't been able to find anything, even in the statistics folder. It probably has something to do with info.get_statistics, but I don't know how to get all the statistics or where to find a list of all the names of the stats.

Hope that makes sense - I would love any feedback you have.
  • Hey simmersimsimmersim, here's a command I whipped up that outputs the stats. Hopefully you can adapt it to your needs. Despite its name, simology stats are different from statistics on sim infos. They're actually a specific type of aspiration, so we need to dig through aspiration tracker to get the info.


    import aspirations.aspiration_types
    import services
    import sims4.commands
    import sims4.reload_service
    import sims4.resources


    @sims4.commands.Command('print_simology_stats', command_type=sims4.commands.CommandType.Live)
    def print_simology_stats(first_name:str="", last_name:str="", _connection=None):
    """
    Output a list of Simology Stats' objectives and their objective values.

    first_name/last_name: If specified, the output is for the Sim of this name. Otherwise, the stats are for the current
    active Sim.
    """
    output = sims4.commands.CheatOutput(_connection)

    # Fetch sim info
    if not first_name and not last_name:
    sim_info = services.active_sim_info()
    if sim_info is None:
    output(f"Missing active sim_info")
    return
    else:
    sim_info = services.sim_info_manager().get_sim_info_by_name(first_name, last_name)
    if sim_info is None:
    output(f"Failed to find sim of name: first_name={first_name} last_name={last_name}")
    return

    # All Sims retain their aspiration data, but only the active household's Sims have the data loaded into a tracker.
    if sim_info.aspiration_tracker is None:
    output(f"No aspiration tracker loaded for {sim_info.first_name} {sim_info.last_name}. They are likely an NPC.")
    return

    output(f"Simology Stats for {sim_info.first_name} {sim_info.last_name}")

    # Simology stats are aspirations of type AspirationSimInfoPanel, whose aspiration_type is SIM_INFO_PANEL.
    aspiration_manager = services.get_instance_manager(sims4.resources.Types.ASPIRATION)
    for aspiration in aspiration_manager.types.values():
    if aspiration.aspiration_type == aspirations.aspiration_types.AspriationType.SIM_INFO_PANEL:
    for objective in aspiration.objectives:
    # By convention, these aspirations only have one objective of type sim_info_statistic, so we can assume
    # get_objective_count() works. This breaks down if for some reason the objective is, say, for time data.
    value = sim_info.aspiration_tracker.get_objective_count(objective)
    output(f" {objective.__name__}: {value}")

    output(f"End Simology Stats")


  • @SimGuruTwoLegs thank you so much! It will take some time for me to comb through everything and figure out what I'm doing, but I'll let you know if I can adapt it to my needs. Seriously, thank you. I would never have been able to glean this much info - you're the best.