Jump to content

Recommended Posts

Hi! I am trying to make lurking nightmares sanity related creatures. I'd like to make them some sort of a miniboss. With the current code they can spawn when you are under 10% sanity. I'd want to make them disappear (playing their death animation but not dropping loot) when the player goes above 20% sanity and also make them regen your sanity if you kill them. I'd also like to not make them spawn if there is already one alive due to your low sanity. THANKS IN ADVANCE!


local SpawnPrefab = GLOBAL.SpawnPrefab

local CHECK_INTERVAL = 30
local SPAWN_CHANCE = 0.50
local SANITY_THRESHOLD = 0.10


local function SpawnLurking(player)

    if player.components.sanity == nil then
        return
    end

    local sanity = player.components.sanity:GetPercent()

    if sanity > SANITY_THRESHOLD then
        return
    end

    if math.random() > SPAWN_CHANCE then
        return
    end

    local x, y, z = player.Transform:GetWorldPosition()

    local shadow = SpawnPrefab("ruinsnightmare")

    if shadow ~= nil then

        shadow.Transform:SetPosition(
            x + math.random(-6,6),
            y,
            z + math.random(-6,6)
        )
    end
end


AddPlayerPostInit(function(inst)

    if not GLOBAL.TheWorld.ismastersim then
        return
    end

    inst:DoPeriodicTask(CHECK_INTERVAL, function()

        SpawnLurking(inst)

    end)

end)
 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...