Ludeon Forums

RimWorld => Mods => Help => Topic started by: TranceBlossom on September 14, 2023, 02:51:18 AM

Title: [SOLVED] Spawning an Animal with a Nickname
Post by: TranceBlossom on September 14, 2023, 02:51:18 AM
Hello there, I'm new to modding RimWorld, but I'm trying to fix a bug in the RimConnect mod (https://github.com/Better-Scenes/RimConnect-mod) which integrates RimWorld to Twitch chat. When a viewer buys an animal, the animal is spawned via drop pod and is named after the user that bought it. The following code in this file (https://github.com/Better-Scenes/RimConnect-mod/blob/master/Source/RimConnection/Actions/Resources/TameAnimalAction.cs) does the renaming, where "boughtBy" is the Twitch username of the viewer:

Pawn newAnimal = PawnGenerator.GeneratePawn(itemDef.race.AnyPawnKind, Faction.OfPlayer);
                if(boughtBy != "Poll")
                {
                    newAnimal.Name = new NameTriple("", boughtBy, "");
                }

This appears to work, but if you try to rename the animal after, you get an error that "The chosen name is invalid". and I suspect it's because NameTriple was intended for humans with a First Name, Nickname, and Last Name, and not animals, or perhaps there needs to be a default name like "Cat 1" that remains somewhere.

Does anyone know how the system for setting animal nicknames works, or how I might go about fixing this?

EDIT: Setting the animal name with NameSingle was the key:

Pawn newAnimal = PawnGenerator.GeneratePawn(itemDef.race.AnyPawnKind, Faction.OfPlayer);
                if(boughtBy != "Poll")
                {
                    newAnimal.Name = new NameSingle(boughtBy);
                }