Jump to content

Recommended Posts

I'm trying to make bernie activate and be active only when Willow is insane. I successfully made it so that he doesn't activate for characters that are now Willow, but there is a bug in relation to reanimating when Willow is insane. I added this code (with "end" being placed where appropriate):

if v.prefab == "willow" then

Underneath "for i, v in ipairs(AllPlayers) do" for both bernie_active.lua:

local function tryreanimate(inst)
    local target = nil
    local rangesq = 256 --[[16 * 16]]
    local x, y, z = inst.Transform:GetWorldPosition()
    for i, v in ipairs(AllPlayers) do
        if v.prefab == "willow" then
            if v.components.sanity:IsCrazy() and v.entity:IsVisible() then
                local distsq = v:GetDistanceSqToPoint(x, y, z)
                if distsq < rangesq then
                    rangesq = distsq
                    target = v
                end
            end
        end
    end
    if target ~= nil then
        local active = SpawnPrefab("bernie_active")
        if active ~= nil then
            --Transform fuel % into health.
            active.components.health:SetPercent(inst.components.fueled:GetPercent())
            active.Transform:SetPosition(inst.Transform:GetWorldPosition())
            inst:Remove()
        end
    end
end

and berniebrain.lua:

local function FindLeader(self)
    self._leader = nil
    local rangesq = LOSE_LEADER_DIST_SQ
    local x, y, z = self.inst.Transform:GetWorldPosition()
    for i, v in ipairs(AllPlayers) do
        if v.prefab == "wollow" then
            if v.components.sanity:IsCrazy() and v.entity:IsVisible() then
                    local distsq = v:GetDistanceSqToPoint(x, y, z)
                    if distsq < rangesq then
                        rangesq = distsq
                        self._leader = v
                    end
                end
            end
        end
    end
    return self._leader
end

Yet, for some reason, Bernie wakes up for 2 - 3 seconds and then sits back down again and keeps doing that over and over, deactivating and activating when he should just be active. This code is written inside copied files of bernie_active.lua and berniebrain.lua from the actual game (there is a reason as to why I'm simplifying this for myself and not using modmain.lua almost at all, but that's besides the point). I also indented any functions and variables related to decaying for Bernie in bernie_inactive.lua. And yes, I was standing next to him when he did that, in fact he does that whilst I'm standing right on top of him as Willow!

Link to comment
Share on other sites

FIXED:

Quote

local function FindLeader(self)
    self._leader = nil
    local rangesq = LOSE_LEADER_DIST_SQ
    local x, y, z = self.inst.Transform:GetWorldPosition()
    for i, v in ipairs(AllPlayers) do
        if v.prefab == "wollow" then
            if v.components.sanity:IsCrazy() and v.entity:IsVisible() then
                local distsq = v:GetDistanceSqToPoint(x, y, z)
                if distsq < rangesq then
                    rangesq = distsq
                    self._leader = v
                end
            end
        end
    end
    return self._leader
end

:wilson_facepalm:

Link to comment
Share on other sites

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
 Share

×
  • Create New...