Based on this question, what is it that makes something qualify as an XP generating moment?
Are those moments generated by the PCs, or by NPCs away from them as well?
Role-playing Games Stack Exchange is a question and answer site for gamemasters and players of tabletop, paper-and-pencil role-playing games. It only takes a minute to sign up.Sign up to join this community
The DM gets to decide when characters get XP. This can be after combat, after a difficult encounter, after a milestone, or literally whenever the DM feels like it (DMG 261):
You decide whether to award experience to characters for overcoming challenges outside combat. If the adventurers complete a tense negotiation with a baron, forge a trade agreement with a clan of surly dwarves, or successfully navigate the Chasm of Doom, you might decide that they deserve an XP reward.
You can do away with experience points entirely and control the rate of character advancement.
While XP-generating events may be related to actions from the PCs or NPCs, nothing in the game other than the DM can decide when and why XP is given--the DMG gives the DM wide latitude to decide XP and leveling on a whim.
Encounters with potential for combat are put together by the DM. Other encounters or opportunities for experience are ruled on by the DM. (DMG p. 261). It's worth noting this detail, however:
Monsters with a challenge rating of 0 are insignificant except in large numbers; those with no effective attacks are worth no experience points, while those that have attacks are worth 10 XP each. (DM Basic Rules, p. 5)
Any encounter, be it planned or impromptu, that may result in an award of XP is identified as "XP eligible" by the DM. For a similar point, see the DMG on awarding Inspiration (P. 240-241). The discretion any DM has in awarding (anything) to the party is pretty broad: not just XP but also treasure, magic items, maps, information, etc.
It is unclear how you arrived at the idea that PC's generate XP. XP is an award from the DM, by description in the rules text. Anything an NPC does tends to be a result of the DM's rulings/plans/discretion, and thus "something an NPC does that results in the XP" is rooted in DM agency / ruling.
At a given table, players can award one another their inspiration point (an optional rule, DMG p. 241)) but I do not find a similar entry for XP award from players.