Silhh Posted March 15, 2015 Share Posted March 15, 2015 Hey guys we have a small question My pal @arcade is a lazy bum and sent me here We need help on making our character not attack small creatures such as bunnies, turkeys, birds, etc at all. If you can help us out we would greatly appreciate it, thanks! Link to comment Share on other sites More sharing options...
DarkXero Posted March 16, 2015 Share Posted March 16, 2015 (edited) 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 March 16, 2015 by DarkXero Link to comment Share on other sites More sharing options...
Silhh Posted March 16, 2015 Author Share Posted March 16, 2015 Thanks! Worked perfectly! Link to comment Share on other sites More sharing options...
rons0n Posted June 17, 2015 Share Posted June 17, 2015 (edited) 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 June 17, 2015 by rons0n Link to comment Share on other sites More sharing options...
Seiai Posted June 17, 2015 Share Posted June 17, 2015 (edited) @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 June 17, 2015 by Seiai Link to comment Share on other sites More sharing options...
DarkXero Posted June 17, 2015 Share Posted June 17, 2015 @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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now