Jump to content

Problem with shadowwaxwellbrain.lua


Recommended Posts

Again.. I'm coming here to search for help with my messy code..
My goal is: 

  • Make maxwell's shadow lumbers not to cut any 1st or 2nd stage trees. I'm running game without any error after this code but it seems not working in-game.

I was thinking many hours why it's not working and i'm guessing the problem is in BufferedAction (but i don't know how it works)
Any help is REALLY appreciated :wilson_worried:

Code:

Spoiler

 


local function FindEntityToWorkAction(inst, action, addtltags)
    local leader = GetLeader(inst)
    if leader ~= nil then
        --Keep existing target?
		--[[
		if TUNING.PREFERABLE_TREE == 1 then
			if(data and data.object and data.object.prefab=="evergreen_short") then
				data.object.target:RemoveComponent("workable")
			end
			if(data and data.target and data.target.prefab=="evergreen_short") then
				data.object.target:RemoveComponent("workable")
				data.target:RemoveComponent("workable")
			end
		end	
		]]--

		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

       ---------- Find new target -> Here is code i actually found in archived topic and i can't make it work (topic wasn't solved unfortunately) ----------
		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
---------- Here ends everything that is changed in whole file ----------

-- This function i copied just for clear view how it works with "FindEntityToWorkAction" function
function ShadowWaxwellBrain:OnStart()
    local root = PriorityNode(
    {
        --#1 priority is dancing beside your leader. Obviously.
        WhileNode(function() return ShouldDanceParty(self.inst) end, "Dance Party",
            PriorityNode({
                Leash(self.inst, GetLeaderPos, KEEP_DANCING_DIST, KEEP_DANCING_DIST),
                ActionNode(function() DanceParty(self.inst) end),
        }, .25)),

        WhileNode(function() return IsNearLeader(self.inst, KEEP_WORKING_DIST) end, "Leader In Range",
            PriorityNode({
                --All shadows will avoid explosives
                RunAway(self.inst, { fn = ShouldAvoidExplosive, tags = { "explosive" }, notags = { "INLIMBO" } }, AVOID_EXPLOSIVE_DIST, AVOID_EXPLOSIVE_DIST),
                --Duelists will try to fight before fleeing
                IfNode(function() return self.inst.prefab == "shadowduelist" end, "Is Duelist",
                    PriorityNode({
                        WhileNode(function() return self.inst.components.combat:GetCooldown() > .5 and ShouldKite(self.inst.components.combat.target, self.inst) end, "Dodge",
                            RunAway(self.inst, { fn = ShouldKite, tags = { "_combat", "_health" }, notags = { "INLIMBO" } }, KITING_DIST, STOP_KITING_DIST)),
                        ChaseAndAttack(self.inst),
                }, .25)),
                --All shadows will flee from danger at this point
                RunAway(self.inst, { fn = ShouldRunAway, oneoftags = { "monster", "hostile" }, notags = { "player", "INLIMBO" } }, RUN_AWAY_DIST, STOP_RUN_AWAY_DIST),
                --Workiers will try to work if not fleeing
                IfNode(function() return self.inst.prefab == "shadowlumber" end, "Keep Chopping",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.CHOP) end)),
                IfNode(function() return self.inst.prefab == "shadowminer" end, "Keep Mining",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.MINE) end)),
                IfNode(function() return self.inst.prefab == "shadowdigger" end, "Keep Digging",
                    DoAction(self.inst, function() return FindEntityToWorkAction(self.inst, ACTIONS.DIG, DIG_TAGS) end)),
        }, .25)),

        Follow(self.inst, GetLeader, MIN_FOLLOW_DIST, TARGET_FOLLOW_DIST, MAX_FOLLOW_DIST),

        WhileNode(function() return GetLeader(self.inst) ~= nil end, "Has Leader",
            FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn)),
    }, .25)

    self.bt = BT(self.inst, root)
end

return ShadowWaxwellBrain

 

 

 

 

Edited by Weexer
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...