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!
Lab Assistant
Original Poster
#1 Old 18th Feb 2015 at 10:39 PM
Default -- Python: Getting Sim Names? --
Hi guys, I started script-modding with Python - it's actually really fun. Anyways, I was wondering if anyone has been able to get in their script mods, the SELECTED Sim's name? I made a few cheats, and I'd like the output, or the text that shows in the large reply box underneath, have a sentence that has the Sim's name in it.

I tried this in my code:
Code:
output(services.sim_info_manager().get_sim_info_by_name + 'test123')

But using that, the reply doesn't even show up.

If I don't include the services.sim_info.... stuff, the 'test123' shows up fine. Thanks and any help would be appreciated.

Simalary Studios

Contact Me
Send me a PM, if you need to contact me for anything.
Advertisement
Deceased
#2 Old 19th Feb 2015 at 3:17 AM
There's a couple different ways you could do that, depending on the circumstances of what existing information your script may already have, but assuming you have no information yet this should do the trick:
Code:
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info
full_name = sim_info.first_name + " " + sim_info.last_name
You'll need to import services in order to run that, btw.
Test Subject
#3 Old 4th Jan 2018 at 11:17 AM
Default How is this done for selected Sims?
Quote: Originally posted by scumbumbo
There's a couple different ways you could do that, depending on the circumstances of what existing information your script may already have, but assuming you have no information yet this should do the trick:
Code:
client = services.client_manager().get_first_client()
sim_info = client.active_sim.sim_info
full_name = sim_info.first_name + " " + sim_info.last_name
You'll need to import services in order to run that, btw.


Hello @scumbumbo.

I hate to bump another old thread again, but I see this thread has no solution for if you wanted to get the name of the sim you clicked on. The above works to retrieve the name of the selected sim, not the name of the sim you clicked on, which is desired if you attach a pie menu to all sims.

Lets say you added your pie menu instance (in this case 11111111111111111) to all Sims via (sims.sim.Sim, 'on_add.') Using your (Scumbumbo, Thank You again!) mailbox tutorial's injector as an example:


With the above, the pie menu instance would show up on every Sim clicked. But using the your code above in an actual command yields the currently selected Sim's name, even if you select another Sim.

This would be an example of what I am talking about, again using Scumbumbo's mailbox tutorial:


With this, even if you click on an NPC, you still get the name of your currently active/selected Sim.

If it helps at all, I have found (in extracted game files) and tried these different calls for retrieving sim_info:


So far I have not been able to get this to work, as I am guessing the client.manager() line may need to be modified as well?

What would be proper way to access the selected, not the active Sim's name?

Thank you for your knowledge!
Deceased
#4 Old 4th Jan 2018 at 7:01 PM
If you look at the XML for the interactions in the mailbox testing cheats tutorial, you'll see in the do_command tuning that we specify that an argument should be sent to the command.
Code:
    <V t="do_command">
      <U n="do_command">
        <L n="arguments">
          <V t="participant" />
        </L>
        <T n="command">mbox.tc_enable</T>
      </U>
    </V>

Any number of different types of arguments can be sent, and in this case we're specifying that we want to send one of the participants of the interaction. Since we don't specify which participant, it uses the default which is the Object participant type, which is the game object that a Sim is interacting with (note that the actual game object itself isn't sent to our command since you can't "type" an actual object into the cheat command line, but rather the ID number of it). In the regular mailbox tutorial, this would be the ID of the mailbox itself, but since you're changing things so the target is a Sim it will be the game object ID of the Sim you are targeting.

In the Python code for the enable and disable commands, we specify in our argument list that we want that argument assigned to the obj_id variable
Code:
def mbox_tc_enable_command(obj_id:int, _connection=None):
so our Python code is receiving that ID number, but we're not using it since we didn't really care for the purposes of that tutorial.

However, you CAN do something with that number, which is to get a reference to the object itself from the object manager. We can then test the is_sim property on the object to see if the object is a Sim or not (testing that would be optional if your code can be 100% certain that it's a Sim object, but we'll assume we don't know and test).

If it is a Sim object, then it has a sim_info assigned to it, and we can then query that to get the name of the targeted Sim. Something like this...
Code:
    obj = services.object_manager().get(obj_id)
    if obj.is_sim:
        full_name = obj.sim_info.first_name + " " + obj.sim_info.last_name
    else:
        full_name = "This is not a Sim object"

And of course, once we have an object reference, we can access a huge number of the variables and methods attached to that object. I suggest looking into the D3OI script I wrote if you are interested in seeing just what is accessible on these objects.
Test Subject
#5 Old 6th Jan 2018 at 12:51 AM
Thank you scumbumbo!
Quote: Originally posted by scumbumbo
If you look at the XML for the interactions in the mailbox testing cheats tutorial, you'll see in the do_command tuning ...


Aye, I was wondering how to exploit that "participant" argument, and if that was the solution. Thank you for your detailed explanation. I was able to get this working very nicely with your notifications script!
Back to top