Jump to content

How to mod shadowwaxwellbrain.lua


Recommended Posts

I want to prevent maxwell's shadow workers from digging mushtree stumps and cutting any type of tree unless it's fully grown. As I understood changing shadowwaxwell.lua is enough, so my mod consists only of brains/shadowwaxwelbrain.lua and modinfo.lua. Here are the contents changed in the former:

 

local function FindEntityToWorkAction(inst, action, addtltags)
    local leader = GetLeader(inst)
    if leader ~= nil then
        --Keep existing target?
        local target = inst.sg.statemem.target
        if target ~= nil and
                target:IsValid() and
                not (target:IsInLimbo() or
                        target:HasTag("NOCLICK") or
                        target:HasTag("event_trigger")) and
                target.components.workable ~= nil and
                target.components.workable:CanBeWorked() and
                target.components.workable:GetWorkAction() == action and
                not (target.components.burnable ~= nil
                        and (target.components.burnable:IsBurning() or
                        target.components.burnable:IsSmoldering())) and
            target.entity:IsVisible() and
            target:IsNear(leader, KEEP_WORKING_DIST) then
                
            if addtltags ~= nil then
                for i, v in ipairs(addtltags) do
                    if target:HasTag(v) then
                        return BufferedAction(inst, target, action)
                    end
                end
            else
                return BufferedAction(inst, target, action)
            end
        end
        TheNet:SystemMessage("target.prefab: ".. target.prefab, false)
        --Find new target
        target = FindEntity(leader, SEE_WORK_DIST, nil, { action.id.."_workable" }, { "fire", "smolder", "event_trigger", "INLIMBO", "NOCLICK" }, addtltags)
        if target ~=nil and (target.prefab == "mushtree_small_stump"
                        or target.prefab == "mushtree_medium_stump"
                        or target.prefab == "mushtree_tall_stump"
                        or target.prefab == "marbleshrub_small"
                        or target.prefab == "marbleshrub_medium"
                        or target.prefab == "evergreen_normal"
                        or target.prefab == "evergreen_short"
                        or target.prefab == "evergreen_sparse_normal"
                        or target.prefab == "evergreen_sparse_short"
                        or target.prefab == "twiggy_normal"
                        or target.prefab == "twiggy_short"
                        or target.prefab == "twiggy_old"
                ) then
            return nil
        end
        return target ~= nil and BufferedAction(inst, target, action) or nil
    end
end

The only thing I have added is the last if; there is no other change.

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