Jump to content

Recommended Posts

Here's the function that causes entities to fall asleep when eating a mandrake:

local function doareasleep(inst, range, time)
    local x, y, z = inst.Transform:GetWorldPosition()
    local ents = TheSim:FindEntities(x, y, z, range, nil, SLEEPTARGETS_CANT_TAGS, SLEEPTARGETS_ONEOF_TAGS)
    local canpvp = not inst:HasTag("player") or TheNet:GetPVPEnabled()
    for i, v in ipairs(ents) do
        if (v == inst or canpvp or not v:HasTag("player")) and
            not (v.components.freezable ~= nil and v.components.freezable:IsFrozen()) and
            not (v.components.pinnable ~= nil and v.components.pinnable:IsStuck()) and
            not (v.components.fossilizable ~= nil and v.components.fossilizable:IsFossilized()) then
            local mount = v.components.rider ~= nil and v.components.rider:GetMount() or nil
            if mount ~= nil then
                mount:PushEvent("ridersleep", { sleepiness = 7, sleeptime = time + math.random() })
            end
            if v:HasTag("player") then
                v:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() })
            elseif v.components.sleeper ~= nil then
                v.components.sleeper:AddSleepiness(7, time + math.random())
            elseif v.components.grogginess ~= nil then
                v.components.grogginess:AddGrogginess(4, time + math.random())
            else
                v:PushEvent("knockedout")
            end
        end
    end
end

 

It's from mandrake_inactive.lua, line 21.

5 hours ago, -t- said:

Here's the function that causes entities to fall asleep when eating a mandrake:


local function doareasleep(inst, range, time)
    local x, y, z = inst.Transform:GetWorldPosition()
    local ents = TheSim:FindEntities(x, y, z, range, nil, SLEEPTARGETS_CANT_TAGS, SLEEPTARGETS_ONEOF_TAGS)
    local canpvp = not inst:HasTag("player") or TheNet:GetPVPEnabled()
    for i, v in ipairs(ents) do
        if (v == inst or canpvp or not v:HasTag("player")) and
            not (v.components.freezable ~= nil and v.components.freezable:IsFrozen()) and
            not (v.components.pinnable ~= nil and v.components.pinnable:IsStuck()) and
            not (v.components.fossilizable ~= nil and v.components.fossilizable:IsFossilized()) then
            local mount = v.components.rider ~= nil and v.components.rider:GetMount() or nil
            if mount ~= nil then
                mount:PushEvent("ridersleep", { sleepiness = 7, sleeptime = time + math.random() })
            end
            if v:HasTag("player") then
                v:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() })
            elseif v.components.sleeper ~= nil then
                v.components.sleeper:AddSleepiness(7, time + math.random())
            elseif v.components.grogginess ~= nil then
                v.components.grogginess:AddGrogginess(4, time + math.random())
            else
                v:PushEvent("knockedout")
            end
        end
    end
end

 

It's from mandrake_inactive.lua, line 21.

That's the problem - I already tried this code and its not workin. No effect, just the usual health/sanity/hunger change.

14 hours ago, Ziro2k said:

@Enderia

Can you post your relevant code so we can see how you're trying to implement it?

I tried for few hours to the point where the original code wasn't even recognizable but it either had no effect or kept crashing. I don't know enough about LUA to get it to work, would appreciate any help on what I have to do with this piece of code. I just need it to work on one eater with  no AoE.

moondrops.lua

Try this:

local function doareasleep(inst, eater, time)
    eater:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() })
end

local function oneaten(inst, eater)
    eater:DoTaskInTime(0.5, function()
        doareasleep(inst, eater, TUNING.MANDRAKE_SLEEP_TIME)
    end)
end

 

1 hour ago, -t- said:

Try this:


local function doareasleep(inst, eater, time)
    eater:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() })
end

local function oneaten(inst, eater)
    eater:DoTaskInTime(0.5, function()
        doareasleep(inst, eater, TUNING.MANDRAKE_SLEEP_TIME)
    end)
end

 

Yessss!! It workes perfectly! Thank you so much!!!

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...