ZombieFear Lua

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

require "MF_ISMoodle"

local function traitModifier(player)


local mod = 1
if player:getTraits():contains("Cowardly") then
mod = mod / 2
end
if player:getTraits():contains("Hemophobic") then
mod = mod / 2
end
if player:getTraits():contains("Brave") then
mod = mod * 2
end
return 1
end

local moodleName = ZomboRP.key("zombiefear")

local function effectStrength(player)


if player:getTraits():contains("Desensitized")
or player:getTraits():contains(ZomboRP.key("psychopath"))
or player:isGodMod() then
return 0
end
local startDate = os.time {
day = SandboxVars.ZomboRP.ZombieFearDay,
month = SandboxVars.ZomboRP.ZombieFearMonth,
year = SandboxVars.ZomboRP.ZombieFearYear,
}
local currDate = os.time {
day = getGameTime():getDay() + 1,
month = getGameTime():getMonth() + 1,
year = getGameTime():getYear(),
}
local elapsedSeconds = math.max(0, currDate - startDate)
local zedTargetRatio = math.max(0.0, 1.0 - player:getZombieKills() /
SandboxVars.ZomboRP.ZombieFearKills)
local minDuration = SandboxVars.ZomboRP.ZombieFearDuration
local additionalDuration = SandboxVars.ZomboRP.ZombieFearDurationKillZombie *
zedTargetRatio
local duration = (minDuration + additionalDuration) * 24 * 60 * 60
local completion = elapsedSeconds * traitModifier(player) / duration
return math.max(0.0, math.min(1.0, 1.0 - completion))
end

local checkAgainAt = 0
local function checkPlayer(player)
local now = getTimestampMs()
if now > checkAgainAt then
checkAgainAt = now + 1000
local zeds = math.max(
player:getStats():getNumVisibleZombies(),
player:getStats():getNumChasingZombies()
)
local moodle = MF.getMoodle(moodleName)
moodle:setThresholds(0.25, 0.5, 0.75, 0.99, 2, 3, 4, 5)
local md = player:getModData()
if not player:isAsleep() and zeds > 0 then
local intensity = effectStrength(player)
if player:getVehicle() then
intensity = intensity / 10
end
moodle:setValue(1 - intensity)
if intensity > 0 then
md.zrp_countZed = (md.zrp_countZed or 0) + zeds
md.zrp_countTime = (md.zrp_countTime or 0) + 1
player:getStats():setStress(player:getStats():getStress() + 0.005 *
zeds * intensity)
player:getStats():setPanic(player:getStats():getPanic() + 5 * zeds
* intensity)
end
else
moodle:setValue(1)
end
end
end

MF.createMoodle(moodleName)

local function initialize()


local player = getPlayer()

Events.OnPlayerUpdate.Remove(checkPlayer)
if effectStrength(player) > 0 then
Events.OnPlayerUpdate.Add(checkPlayer)
end
end

Events.OnGameStart.Add(initialize)
Events.OnNewGame.Add(initialize)

You might also like