Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Depraved Data

To facilitate the process of syncing custom data of characters between Server, and Clients on Project Zomboid. Depraved Sense has a data handling util called Depraved Data. Which is the main way of altering Depraved Sense values of characters.

Let’s assume we want to check how much libido a character has. We can simply do this example:

---We require the DepravedData module to get access to its utils.
local DepravedData = require("DepravedSense/Util/DepravedData")

---Get the libido value of the character. Assuming of course we have a `character` in scope.
local libido = DepravedData.get_libido(character)

---And now we print out on the console for us to see the value.
print(libido)

Let’s say we have a character, and we want to change their libido stat every time they hit a zombie. To achieve that we can do this:

local DepravedData = require("DepravedSense/Util/DepravedData")

---The amount of libido we want to add. In this case is 2%.
---For those wandering, in code we represent percentages with broken 1 values.
---0.5 = 50%, 0.2 = 20%, and in here, 0.02 = 2%
local libido_to_add = 0.02

---@param zombie IsoZombie
---@param attacker IsoGameCharacter
---@param body_part BodyPartType
---@param weapon HandWeapon
local function on_hit_zombie(zombie, attacker, body_part, weapon)
    ---We add the libido on the impact
    DepravedData.add_libido(attacker, libido_to_add)
end

Events.OnHitZombie.Add(on_hit_zombie)

Now, every time a player hits a zombie, their own libido will increase by 2%!

Keep in mind that you can only alter data if you’re on the Server side. That is to avoid command duplication coming from multiple Clients, and cause a lot of chaotic behaviour (also avoid cheats). While you can still alter the data on the Client, it will quickly be reflected to the Server's own value, and won’t sync with other Clients.

Belly Inflation

As some people might be aware of, Depraved Sense does support the ability to change the character’s belly size visually. You can easily do it by using set_belly_inflation().

local DepravedData = require("DepravedSense/Util/DepravedData")

---Sets the belly inflation to 50%
DepravedData.set_belly_inflation(character, 0.5)

When done, the character’s own belly will reflect the inserted percentage.

Note: It is highly endorsed to check the source code of DepravedData, as it has some special functions related to it that you might find neat! However, this module is still pretty much W.I.P; some changes can be expected in the future, and other functions can get deprecated. Always keep in touch with Depraved Sense patch notes!