Jump to content

How to check "leader" for a different "follower"?


Recommended Posts

Say I have 2 bernies and a player check that I am working with. I want to add a piece of code that would allow a bernie to check whether a player already has a bernie following (essentially trying to make it so that only one bernie can follow a player at a time). Any idea how I would create this check? I'm not sure how I would add that to this function exactly (this is in berniebrain.lua):

Spoiler

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.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
    return self._leader
end

Note that my mod's code for this function is a bit edited to add in some other features, but even if you use this code, I should be able to pick up on what exactly to add where respective to my changes in order to get this feature working as well.

 

Edited by EuedeAdodooedoe
Added tags to the topic
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...