# NPC Loader Reads NPC definitions out of the cache as they are needed, works out what the ones that change form are shown as, and builds the NPC database WaspLib looks NPCs up in by name. - - - ## TNPCLoader.Load ```pascal procedure TNPCLoader.Load(); ``` Caches the NPC archive of the config index and makes room in `TNPCLoader.Definitions` for every NPC id. No NPC is decoded until {ref}`TNPCLoader.Get` asks for it. Does nothing once loaded. The archive is compressed as a whole, so it is unpacked in full even when only a few NPCs are needed; decoding them is what's left for later. - - - ## TNPCLoader.Get ```pascal function TNPCLoader.Get(id: Integer): TNPCDefinition; ``` The definition of NPC `id`, decoded the first time it is asked for and kept in `TNPCLoader.Definitions` from then on. Loads the archive first with {ref}`TNPCLoader.Load` if it isn't yet. - - - ## TNPCLoader.Resolve ```pascal function TNPCLoader.Resolve(id: Integer): TNPCDefinition; ``` The definition NPC `id` is shown as. Some NPCs change with the player's progress and spawn as a stand-in whose definition only lists what it can turn into. Those are shown as the first of their forms that has a name, or as themselves if none of them has one. A name of `null`, or an empty one, doesn't count as a name. Only the forms looked at are decoded. - - - ## TNPCLoader.WriteDatabase ```pascal function TNPCLoader.WriteDatabase(path: String): Integer; ``` Writes the NPC database into `path` as two column files, `name.txt` and `id.txt`, where line `N` of each belongs to row `N`. There is a row for every NPC id that has a name as shown by {ref}`TNPCLoader.Resolve`, in id order, so a name with several ids has a row for each. Names keep the case the game shows them in. Creates `path` if it doesn't exist and returns how many rows were written. This decodes every NPC. Example: ```pascal CacheReader := TCacheReader.Create(); NPCLoader.WriteDatabase('C:/npcs-db/'); ```