Jump to content

Recommended Posts

Hello, I need help :wilson_dead:!!!!!!

So, sometimes when my entity pickups/harvests item it goes braindead & nobody can help me with that...

So, I was wondering is there a way I can force restart my entity's brain?

I tried code like

inst.sg:GoToState("idle")

inst:ClearBufferedAction()

inst.sg:ClearBufferedEvents()

inst.brain:ForceUpdate()

inst.brain:Stop()

inst.brain:Start()

but none of them do anything for when my entity is braindead... Can someone please tell me if there's any other code to make my entity forget any action it wanted to preform & just follow it's leader again :wilson_cry:...?

Edited by SuperDavid
Please...help me...

Can someone at least tell me how I can make my entity cancel these actions if it doesn't preform the action on it's target within 3 seconds or when it's leader wanders 6 dist away from it? I really would appreciate help because I definitely am not smart enough to do this on my own & I really don't want to remove these functions from my entity :(...

local function PickupAction(inst)

	local target = nil
	local action = nil

	if inst.sg:HasStateTag("busy")
	or inst.sg:HasStateTag("attack")
	or inst.sg:HasStateTag("working")
	or (inst.components.inventory
	and inst.components.inventory:IsFull()) then
	return
	end

	local pt = inst:GetPosition()
	local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, SEE_ITEM_DIST, nil, NO_TAGS, inst.components.eater:GetEdibleTags())

	if not target then
	for k,v in pairs(ents) do
	if v and v:IsOnValidGround() and
	inst.components.eater:CanEat(v) and
	v.components.inventoryitem and not
	v.components.inventoryitem:IsHeld() and
	TargetNotClaimed(inst, v) then
	target = v
	break
	end
	end
	end

	if target and not target:HasTag("fire") then
	local action = BufferedAction(inst,target,ACTIONS.PICKUP)
	return action
	end
end
local function HarvestAction(inst)

	-- Food On Ground > Pots = Farms = Drying Racks > Plants

	local target = nil

	if inst.sg:HasStateTag("busy")
	or inst.sg:HasStateTag("attack")
	or inst.sg:HasStateTag("working")
	or (inst.components.inventory
	and inst.components.inventory:IsFull()) then
	return
	end

	local pt = inst:GetPosition()
	local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, SEE_STRUCTURE_DIST, nil, NO_TAGS)
	
	-- Look For Crop > Cook Pots > Drying Racks
	
	if not target then
	for k,item in pairs(ents) do
	if (item.components.stewer and item.components.stewer:IsDone()) or
	(item.components.dryer and item.components.dryer:IsDone()) or
	(item.components.crop and item.components.crop:IsReadyForHarvest()) then
	if TargetNotClaimed(inst, item) then
	target = item
	break
	end
	end
	end
	end

	if target and not target:HasTag("fire") then
	return BufferedAction(inst, target, ACTIONS.HARVEST)
	end

	-- Berry Bushes > Carrots
	
	if not target then
	for k,item in pairs(ents) do
	if item.components.pickable and
	item.components.pickable.caninteractwith and
	item.components.pickable:CanBePicked() and
	table.contains(PICKABLE_FOODS, item.components.pickable.product)
	and TargetNotClaimed(inst, item) then
	target = item
	break
	end
	end
	end

	if target and not target:HasTag("fire") then
	return BufferedAction(inst, target, ACTIONS.PICK)
	end
end

 

Okay, I think it works now, thank you so, so, so, so,so much DarkXero I could've never done this in a million years :D!!!!!!

If the entity goes braindead again then i'll comback again but hopefully it's completely fixed for good now, thank you :D!!!!!!

Edited by SuperDavid

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