Issue trying to change the friendship menu {Solved, if you want to make a vanilla character datable with c#, look here.}

SomeoneEls

Sodbuster
Odd little thing trying to change the menu here. Ive changed the character.xnb file in the data folder and made it so that only some characters are able to be romanced, but the changes arent showing in the friendship menu. Specifically..

C#:
if (e.NameWithoutLocale.IsEquivalentTo("Data/Characters") && (Game1.player != null))
{
    e.Edit(asset =>
    {
        var data = asset.AsDictionary<string, CharacterData>().Data;
        int seed = 0;
        for(int i = 0; i< Game1.player.Name.Length; i++)
        {
            seed += Game1.player.Name[i];
        }
        int x = 2;
        foreach (var item in data)
        {
            if (seed % x == 0)
            {
                item.Value.CanBeRomanced = true;
                item.Value.LoveInterest = "";
              
            }
            else
            {
                item.Value.CanBeRomanced = false;
            }
        }




    });
}
Is this hardcoded or nah?
 

SomeoneEls

Sodbuster
Fixed it. Just needed to change the canberomanced varible via game1.

Also added a check that made sure that the person in question was of age.
 
Last edited:

SomeoneEls

Sodbuster
Edit, I changed this and for some reason I still cant marry npc's that have the flag true. Any help would be great...

EDIT2: It seems that the datable flag in the npc isn't being changed. Dunno how the change it, as its read only though.
 
Last edited:

SomeoneEls

Sodbuster
Found how to do it and it works perfectly! Basically, if you have problems trying to change the npc's disposition, you have to change the datable varible of the npc and the canberomanced varible of the person in the Game1.characterdata dictionary.
How to change a read only variable?

Use this.

C#:
 Assembly.GetAssembly(typeof(NPC))
.GetType("StardewValley.NPC")
.GetField("datable")
.SetValue(n, t);
n is the npc varible of the character you want to change. You can get this by using this method.
t is just the netbool that is either true or false. It needs to be a netbool, not anything else.

C#:
NPC getCharacter(string npcName)
{
    foreach (GameLocation loc in Game1.locations)
    {
        if (loc.characters.Count > 0)
        {

            foreach (NPC npc in loc.characters)
            {
                if (npc.Name == npcName)
                {
               
                    return npc;
                
                }

            }
        }
    }
    return null;
}
It relies on getting the location first so maybe there is a better way to do it? But oh well, it works anyways. To use you want to input the name of the character (case sensitive) into the method.


Oh yeah, obviously don't use the assembly method for anything willy-nilly. You CAN change any read only varible of a class using this but usually there is a very good reason why it was read only in the first place. I only use this now bc trying to change the xml file simply just doesnt work in this case, since the value of that varible is changed first, the xml file by resource second.


Also using content patcher might also work in this case without being so intrusive. However, if you want to use pure C#, this is pretty much the only thing ya can do (of my knowledge)

Also also, there wont be any kissing animations or specific diolouge for that character along with some otherr missing bits you will have to fill. It won't crash (to my knowledge), but it would be better with that data.
 
Last edited:
Top