Papyrus is an object-oriented scripting language used by the recent Creation Kit-based Bethesda role playing games, The Elder Scrolls V: Skyrim and Fallout 4. I have made extensive use of it while creating mods for these games. The following script is the core of the Fallout 4 version of Imp's More Complex Needs, a hunger/thirst/sleep simulator that realistically models physiology, applying it to both the character and their currently active companion, making them require food, water, and rest to stay healthy. An instance of the script is attached to the player and to their currently active companion. It processes their metabolism and applies penalties and bonuses based on the resulting statistics.
The main function is an OnTimer event that is called at regular intervals. The character's activity level is checked at each interval; activity level is a scalar value that multiplies the consumption rate of relevant nutrients, and reflects the action that the player is performing at the time of calculation. Example activity levels range from about ~1.0 at rest to ~12.0 when sprinting with a heavy pack. A running average is maintained, updated at each interval. Every 10th interval, the running average is read and reset, and used to process the character's metabolism. Basically, the activity level is multiplied by the elapsed time since the metabolism was last processed, then multiplied by the base consumption rate for each nutrient. Tracked nutrients include the calorie-providing macronutrients fat, protein, carbohydrate, and alcohol, as well as water, caffeine, nutrients (a catchall statistic representing the vitamins and minerals in food).
Rather than simply calculating calorie consumption, food energy is instead broken down into macronutrients that are tracked separately. Fat is typically broken down into triglycerides in the liver and stored directly into fat cells, where it is used to fuel aerobic processes. Carbohydrates are converted into glucose and used to replenish liver and muscle glycogen, used to fuel anaerobic effort and brain activity. These are the body's two major fuel tanks. Fat reserves are essentially limitless, but glycogen reserves are capped based on available muscle and liver tissue, with excess carbohydrates being converted into triglycerides and stored as fat. When the body performs an activity, aerobic processes are used to supply the power, until the body's aerobic capacity is reached. Anaerobic process are used to make up the difference when that capacity is exceeded, but fuel is depleted quickly. Protein is not stored in any significant amount, but is used to fuel some dependent processes, and to build and repair tissue. Alcohol also supplies calories, preempting fat metabolism in the liver. The code below handles the juggling of calories between these various processes.
Although this level of detail is overkill for most gamers, it was reasonably popular among survival-oriented players looking for the additional, realistic challenge of keeping their character fed and healthy in the scarcity of an apocalypse. This level of realism also adds depth that improves replayability, a key feature of games that support modding. More impressively, I received messages from a number of users that said they changed their actual eating habits based on what they learned from this mod.
I am continuing to develop the model, and have begun work on a standalone metabolism simulator written in C# for the Unity engine. I will likely be switching to the Unreal engine, since it's visual scripting system seems like an interesting environment for developing the model, similar to mathematical modeling programs like MATLAB and Vensim.

You may also like

Back to Top