Personalised ID Card

A number of my mods use an id card (based on Michelle's credit cards) kept in inventory either as an indicator or for storing data (or both). Most of these are owned by a specific Sim and cannot be taken/used by another Sim. It would therefore be useful if the card could include a picture of the owning Sim.


The photobooth creates a picture (Accessory - Photo Booth - Photo) with 4 images of a specific Sim so this seemed a good place to start, but all it really proves is that there is some "magic" going on with primitive 0x006D Change Material and temp values.

But it does lead to the MTS page for the primitive, which has a cryptic section about adding a Sim's graphic and a helpful pointer to the date love/hate letter.

Digging into the love letter (DateReward - Love Letter) code, it turns out that adding a Sim's thumbnail to an object is remarkably simple, provided that the object's mesh has a suitable sub-set to receive it.

So, with a lot of help from gayars, a new mesh was created for the ID card with a subset to receive the thumbnail - defaulted to Mr Potato Head taken from SimPe - and UV mapped to one of CatherineTCJD textures.

The bug collection (Collection - Bug Box) when picked up to be placed in inventory displays "Sim X's bug collection" and digging into that code reveals a Lua function called "BugCollectionRename" which is really a generic rename.


Putting it all together we get, in Buy mode ...

... and when placing the ID Card into the owning Sim's inventory.


The interesting code is in BHAV 0x1020 "Sub - Set Owner" which takes one parameter, the Sim's NID

Lines 0x00 to 0x03 set up the temps to perform the "magic" with prim 0x006D Change Material to generate/retrieve the thumbnail of the Sim and return its GUID in temps 4 and 5

Lines 0x04 to 0x06 stash the GUID in case it's needed in the future and change the photo subset to be the thumbnail

Line 0x07 marks the ID card as now owned by the Sim

Line 0x08 calls the Lua function to change the title and description of the ID card to include the Sim's name

The text displayed along with the Sim's name is in STR# 0x1001. To use a different STR# instance change the third parameter passed to the Lua function in line 0x08 above.


When creating an ID Card from code via primitive 0x002A Create New Object Instance, set temp 0 to the owning Sim's NID and set bit 5 of op 5. This will pass the value in temp 0 into the OBJf:main function as parameter 0

The example OBJf:main "Function - Main" BHAV, verifies param 0 as a NID and if so initialises the thumbnail and ownership.


The ID Card has two menu options, "Put Away" to place the card into the Sim's inventory and "Update Picture" to change the thumbnail after a Sim has changed appearanced, re-planned their wardrobe or aged.


To use the ID Card in your own project(s), just make a clone (as you would for any other object) and change the GUID.


Credits

  • whoward69: code and any errors
  • gayars @Sims Crafters; mesh
  • CatherineTCJD @Sims Crafters; texture
  • Michelle @MTS: credit-card ghost (although with a new mesh, new texture, new code and a complete restructure this is a bit like Trigger's broom)
  • SimPe: Mr Potato Head thumbnail

Files

Download SimsIdCard.zip