top of page
  • Writer's pictureJesse Toyota

NPC Events

Updated: Jan 22, 2019

For our latest milestone in Lil Tribals, I was tasked with implementing NPC events, starting with giving gifts and insulting sprees. In our game, NPC events are categorized as semi-random events that NPCs will engage in for a short period of time. These events are primarily triggered by their stats, especially their comfort stat, but are also based on chance.



Because the NPCs are driven by role-based behaviour, I simply defined each NPC event as a role. When checking which role to engage in, it also checks if it should engage in an NPC event based on individual checks. By creating a virtual Check function that each individual role can define as well as a static Role.Check function that takes an inherited Role class and returns its virtual Check function, I can easily check through each of the NPC events that we develop.



For the "give gift" event, it checks if the NPC has formed any relationships yet and has a 20% chance of randomly triggering. This is what its override Check function looks like.




Once engaged in a role, the NPC will carry out the defined behaviour through its Play function, until it returns false, indicating that the behaviour has been completed. When completed, it will decide its next behaviour after a short delay.



By having this base structure, we can now easily develop new events by simply creating new classes inherited from the Role class. The benefit of creating new classes per role, rather than new functions, is that each new class has the virtual functions Play and Check, making it easier and cleaner to assess roles. These functions also take the character's Controller as a parameter, allowing the character behaviour to be contained within the event classes rather than in the Controller class itself.


bottom of page