RELEASED [SMAPI] CustomNPC

Discussion in 'Mods' started by Platonymous, Nov 5, 2017.

  1. Platonymous

    Platonymous Big Damn Hero

    There appears to be some issue with dating when using different names for the folder, name and displayname, so for now I would recommend to use the same name for all.
     
    • .Lavender.

      .Lavender. Pangalactic Porcupine

      Correct me if I'm wrong, but looks like you don't have a way to add festival data other than dialogue. I feel like I've seen it somewhere before as I have a festivalSpots.TSV, but yeah.
       
      • Platonymous

        Platonymous Big Damn Hero

        Seems like Ieft it out of the json:

        "specialPositions": "positions.tsv",

        positions.tsv:
        Flower Dance;<x> <y> <face>
        Dance of the Moonlight Jellies;<x> <y> <face>
        Feast of the Winter Star;<x> <y> <face>
        Egg Festival;<x> <y> <face>
        Luau;<x> <y> <face>
        Stardew Valley Fair;<x> <y> <face>
        Spirit's Eve;<x> <y> <face>
        Festival of Ice;<x> <y> <face>
         
          anothersarah, .Lavender. and Kyyttyy like this.
        • .Lavender.

          .Lavender. Pangalactic Porcupine

          Me again, I'm a little lost on how to add custom locations. I have been getting two errors. If I try overriding a location (using the beach in this case) with a map that only has the changes I made to it, I get this error:
          And if I change the actual beach.tbin and leave everything as it with but also with my changes I get this one:

          Here's the locations section from my .json file.

          "buildings":
          [
          {
          "map": "cottage.tbin",
          "location": "Beach",
          "position": [17,6]
          },
          ],
          "warps":
          [
          {
          "mapEntry": "Beach.tbin",
          "mapExit": "cottage.tbin",
          "entry": [17,6],
          "exit": [10,10],
          "flip": false,
          },
          ],
          "map": "Beach",
          "position": [11, 7],
           
          • Platonymous

            Platonymous Big Damn Hero

            I'm a little confused by your json. First off, mapEntry and mapExit need to be the map names. not the map files, so "Beach" instead of "Beach.tbin". The confusing part is your Exit, since cottage isn't a location, but a building on the beach, right?
            To clarify: buildings are map data that is replacing parts of an existing map, if this is as I suspect a new cottage on the beach, then building would be the right thing to use. Inside locations however would be declared in "rooms". In case of buildings you would in most cases not need any warps, since the "Action"-properties on tiles are copied over aswell, so you can use a "LookedDoorWarp"-Action on the door of you cottage to allow the entry to a room, either an existing one, or a new one you added via "rooms".

            Here's an example from an upcoming npc mod that adds a house (ForestPS.tbin) to the Forest map and contains two rooms (PetShop, AlecsRoom):

            "buildings":
            [
            {
            "map": "ForestPS.tbin",
            "location": "Forest",
            "position": [53,29]
            }
            ],
            "rooms":
            [
            {
            "name": "PetShop",
            "map": "PetShop.tbin"
            },
            {
            "name": "AlecsRoom",
            "map": "AlecsRoom.tbin"
            }
            ],


            No warps are used, because the maps themselves already contain warping properties. In case of the PetShop-Exterior (ForestPS.tbin) the door has the following "Action"-property on the door tile: "LockedDoorWarp 18 18 PetShop 1100 2000",
            in case of the rooms, they are using the map-property "Warp". For ex. this "Warp" property on the PetShop(.tbin) map: "17 20 Forest 57 38 17 2 AlecsRoom 8 15". Rooms retain all properties as they are imported, buildings only the tile-properties.

            But a working warp could look something like this:

            "warps":
            [
            {
            "mapEntry": "Forest",
            "mapExit": "PetShop",
            "entry": [57,37],
            "exit": [18,18]
            }
            ]


            Then again, your better off not using warps whenever you have the option to use properties.
             
              Last edited: Dec 8, 2017
            • .Lavender.

              .Lavender. Pangalactic Porcupine

              Thank you! Yeah, I was major confused hence why I came here for help! I figured it was my code - much appreciated!
               
              • .Lavender.

                .Lavender. Pangalactic Porcupine

                I'm getting this error now...
                Code:
                [SMAPI] Custom NPC crashed when editing asset 'Maps\Beach', which may cause errors in-game. Error details:
                System.IndexOutOfRangeException: Index was outside the bounds of the array.
                   at xTile.Tiles.TileArray.set_Item(Int32 x, Int32 y, Tile value)
                   at CustomNPC.CustomNPCMod.injectIntoMap(Map source, Map target, Vector2 targetPosition, GameLocation location, Boolean includeEmpty) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomNPC\CustomNPCMod.cs:line 559
                   at CustomNPC.CustomNPCMod.Edit[T](IAssetData asset) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomNPC\CustomNPCMod.cs:line 1190
                   at StardewModdingAPI.Framework.SContentManager.ApplyEditors[T](IAssetInfo info, IAssetData asset) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\SContentManager.cs:line 653
                And here's my json code.
                Thank you for your help.
                 
                • Platonymous

                  Platonymous Big Damn Hero

                  The json looks fine, must be something with the Beach.tbin. What exactly does that files include?
                  Check out how the PetShop is placed in this mod: https://www.nexusmods.com/stardewvalley/mods/1692/
                   
                  • sheetcakeghost

                    sheetcakeghost Weight of the Sky

                    Making a point of this in here since it'd be more your mod related than mine. It'd be fun to have the NPCs that use your mod to recognize one another in game. I'll be keeping in mind ways that my NPC could mention or even interact with Alec just as I want him to interact with all the canon game characters. I think that this might need to be handled in a separate patch, however.
                     
                    • Platonymous

                      Platonymous Big Damn Hero

                      I'm currently building in a feature that allows NPC mods to influence other Custom or Vanilla NPC dialogues and schedules. You could also already use other Custom NPCs in your NPCs events, but those events would break the game if the other NPC isn't installed, while dialogues and schedules wouldn't.
                       
                        anothersarah likes this.
                      • sheetcakeghost

                        sheetcakeghost Weight of the Sky

                        That's good to know. Making a "community patch" for other NPCs wouldn't be much of a hassle right now seeing as there is only one other NPC to take into account, but as the roster grows it would become a hassle.

                        I don't imagine the game has any "if", "then", or "else" statements for dialog? Forgive me if that makes little sense. I'm more familiar with python than I am whatever code Stardew uses (C#?).

                        Here is an example of what I mean.

                        If Alec Male Installed
                        rain "The guy at the pet shop seems nice. I'm glad all the animals Marnie finds have a decent home."

                        If Alec Female Installed
                        rain "The lady at the pet shop seems nice. I'm glad all the animals Marnie finds have a decent home."

                        Else
                        rain "I wish I could rescue all the animals Marnie finds myself, but I don't have the room."


                        Right now I'm just assuming that gets handled in variables somehow. I just have no idea how. d: (Also I know there wouldn't be quotes in the json code, I just put those there for ease of reading.)
                         
                          HopeWasHere likes this.
                        • Platonymous

                          Platonymous Big Damn Hero

                          I can add conditions for that, it could look something like this:
                          npc Alec male?rain | The guy at the pet shop seems nice. I'm glad all the animals Marnie finds have a decent home.
                          npc Alec female?rain | The lady at the pet shop seems nice. I'm glad all the animals Marnie finds have a decent home.
                          NOT npc Alec any?rain | I wish I could rescue all the animals Marnie finds myself, but I don't have the room.
                           
                            HopeWasHere likes this.
                          • sheetcakeghost

                            sheetcakeghost Weight of the Sky

                            That should do the trick. Then we just have to make a point of sharing which name coding is used for other creators.
                             
                            • sheetcakeghost

                              sheetcakeghost Weight of the Sky

                              So I'm wanting to do something with Antoine where he only shows up as an NPC if specific conditions are met. Basically I want him to be available when the farmer unlocks the community center. Preferably the day after. I also want him to disappear if the Community Center is turned into storage. I have no idea how to make those things happen.

                              Also, what's the best way to get the coordinates for sprite/furniture placement? Will I need to crack open the map editing software?
                               
                              • Platonymous

                                Platonymous Big Damn Hero

                                Yes, at least I can't think of a better way to find the coordinates.
                                The "condition" parameter already covers your appearing. Disappearing in theory, but untested. Buildings however would remain.
                                 
                                • sheetcakeghost

                                  sheetcakeghost Weight of the Sky

                                  Okay, so if I included any customizations such as buildings, secret maps (using advanced location loader most likely), or edits to the map itself (say adding a bed into the community center) they would be there from the start and stay even after he vanishes or gets married. Good to know.
                                   
                                  • Platonymous

                                    Platonymous Big Damn Hero

                                    Custom maps, that you would add via rooms can be removed or replaced, only buildings can't be. In the Alec mod for example his room switches from dirty to clean at some point.
                                     
                                      sheetcakeghost likes this.
                                    • DJ_Zapple

                                      DJ_Zapple Pangalactic Porcupine

                                      Hey, I got a question here. I tested my NPC at long last, and noticed something odd - after speaking to her for the first time, she seemed to work fine and all. Sprite was breathing, placeholder portraits worked, and while the dialogue, for some reason, used the dialogue for Spring_Mon, everything seemed to work right.

                                      ...Until I opened the relationship panel to see if she appeared there. She does, but she was still considered a ???, after being spoken to... I dunno where I went wrong on that, but if you could help me pinpoint where I went wrong, I'd be happy. I'll put the .json's contents in a spoiler...


                                      {
                                      "name": "Zintha",
                                      "displayName": "Zintha",
                                      "sprite": "Zintha.png",
                                      "version": "0.3.0",
                                      "author": "DJ Zapple",
                                      "portrait": "ZinthaPortrait.png",
                                      "schedule": "schedule.tsv",
                                      "dialogue": "dialogue.tsv",
                                      "marriageDialogue": "marriageDialogue.tsv",
                                      "animations": "animations.tsv",
                                      "specialPositions": "positions.tsv",
                                      "events": "events.tsv",
                                      "mail": "mail.tsv",
                                      "spouseRoom": "ZinthaSpouseRoom.tbin", "map": "Saloon",
                                      "position": [41, 18],
                                      "age": "adult",
                                      "facing": 2,
                                      "gender": "female",
                                      "manners": "polite",
                                      "homeRegion": "Town",
                                      "relations": "",
                                      "socialAnxiety": "outgoing",
                                      "optimism": "neutral",
                                      "datable": "datable",
                                      "crush": "null",
                                      "birthdaySeason": "fall",
                                      "birthday": 13,
                                      "loves": [72, 114, 167, 169, 206, 220, 234, 730,],
                                      "likes": [216, 262, 431,],
                                      "dislikes": [88, 117, 174, 176, 180, 194, 195, 442,],
                                      "hates": [74, 107, 166, 272, 306, 307, 308,]
                                      }
                                       
                                      • thingwithwings

                                        thingwithwings Phantasmal Quasar

                                        I have a question about shops... If i wanted to give an custom npc an outdoor shop (like Alex's summer icecream shop) How would I do it? Would it be more or less work that adding a new map/building for a shop?
                                         
                                          HopeWasHere likes this.
                                        • Darkry 115

                                          Darkry 115 Void-Bound Voyager

                                          I had gone through the work of making an NPC using this template and was going to test the NPC in game when I encountered these issues,

                                          From the SMAPI log:

                                          [14:514 ERROR Custom NPC] Mod crashed when editing asset 'Data\NPCGiftTastes', which may cause errors in-game. Error details:
                                          System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
                                          at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
                                          at CustomNPC.CustomNPCMod.getGiftTastes(NPCBlueprint blueprint) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomNPC\CustomNPCMod.cs:line 923
                                          at CustomNPC.CustomNPCMod.Edit[T](IAssetData asset) in C:\Users\David\Documents\GitHub\Stardew-Valley-Mods\CustomNPC\CustomNPCMod.cs:line 1241
                                          at StardewModdingAPI.Framework.ContentCore.ApplyEditors[T](IAssetInfo info, IAssetData asset) in C:\source\_Stardew\SMAPI\src\SMAPI\Framework\ContentCore.cs:line 715

                                          On first glance, I see that a certain file is looking for a "C:\Users\David\Documents\Github\...CustomnNPCMod.cs," a file which does not exist on my computer regardless if the username in the directory was changed to my name. Am I missing something, like a download from another site? Was there a file that wasn't included in the download here? How do I solve these issues?
                                           
                                            Last edited: Apr 8, 2018

                                          Share This Page