Jump to content

Recommended Posts

You can edit CanBeAttacked or IsValidTarget, CanAttack in combat to make either your character run to the target and perform an attack that does no damage, or just make it run to the target and do nothing. Example:

local untouchables = {	rabbit = true,	perd = true,	crow = true,	robin = true,	robin_winter = true}AddComponentPostInit("combat", function(self)	local old = self.CanAttack	function self:CanAttack(target)		local valid = old(self, target)		if valid and self.inst.prefab == "wilson" and untouchables[target.prefab] then			return not valid		else			return valid		end	endend)

 

You can also edit the wilson stategraph to stop the locomotion.

 

However, I presume the most elegant solution is editing PlayerActionPicker, so that your character doesn't get to attack or force attack any of these creatures. But I'm not doing well in building this solution, so in the mean time, I summon mouse.

 

EDIT: This should do the trick, optimizations welcome.

local untouchables = {	rabbit = true,	perd = true,	crow = true,	robin = true,	robin_winter = true}AddComponentPostInit("playeractionpicker", function(self)	local old = self.SortActionList	function self:SortActionList(actions, target, useitem)		if #actions == 0 then			return actions		end		local c = 0		for k, v in pairs(actions) do			if v == GLOBAL.ACTIONS.ATTACK and 			self.inst.prefab == "wilson" and 			untouchables[target.prefab] then				c = 1				break			end		end		if c == 1 then			return {}		else			return old(self, actions, target, useitem)		end	endend)
Edited by DarkXero

Sorry to bring an old topic back to life but I'm having trouble with this tidbit of code.

 

Well actually this issue has been happening since forever ago but I didn't want to fix it quite yet.

 

So yeah, basically auto(force) attack ignores the code posted above. How would I make this so it also stops my character auto(force)-attacking small creatures?

Edited by rons0n

@rons0n

i think i remember that there's and action called FORCEATTACK.

 

edit: ah, that was in DS, in DST it's done differently, i think it done via the canforce variable that actions have, but i didnt test it.

Edited by Seiai

@rons0n,

put this in the common_postinit of your character:

local untouchables = {    rabbit = true,    perd = true,    crow = true,    robin = true,    robin_winter = true}    inst:DoTaskInTime(0, function()    local old = inst.replica.combat.IsValidTarget    inst.replica.combat.IsValidTarget = function(self, target)        if target and untouchables[target.prefab] then            return false        end        return old(self, target)    endend)

You shouldn't make it avoid small creatures because spiders are small creatures.

If you want to include spiders, you can check target:HasTag("smallcreature").

But I think putting the animals in a table is best.

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