AquaRC Posted April 4, 2016 Share Posted April 4, 2016 (edited) So I made a new character mod and I want to add a perk which makes it so monsters don't attack the character unless provoked Much help is appreciated and please when you add in the code or string for this perk please show where I should place it, like in which folder? and where do I place it in the string of code? (screenshots of where the code should be is helpful) sorry if Im asking too much, but Im new to modding so yeah. Edited April 4, 2016 by AquaRC just made a slight adjustment Link to comment Share on other sites More sharing options...
AquaRC Posted April 5, 2016 Author Share Posted April 5, 2016 omg thank you Link to comment Share on other sites More sharing options...
AquaRC Posted April 5, 2016 Author Share Posted April 5, 2016 The help is much appreciated Link to comment Share on other sites More sharing options...
DarkXero Posted April 6, 2016 Share Posted April 6, 2016 The tags make it so the monsters' radars won't pick you up when they run their periodic retargeting function. local function PassiveUntilAttack(self) local _SetRetargetFunction = self.SetRetargetFunction self.SetRetargetFunction = function(self, period, fn) if fn then local _fn = fn fn = function(...) local _target = _fn(...) if _target and _target.prefab == "wilson" then return end return _target end end return _SetRetargetFunction(self, period, fn) end end AddComponentPostInit("combat", PassiveUntilAttack) This, in modmain, is a general solution. Nothing can retarget you (or in the example, "wilson"). Of course, if you get close to killer bee hives, they will be pissed at you, and if you hit a beefalo or spider, then the entire herd will be mad at you. But that is to be expected. If you are pacific then monsters won't get you. Link to comment Share on other sites More sharing options...
AquaRC Posted April 15, 2016 Author Share Posted April 15, 2016 um this is a bit late to ask but where do I place it? in which string? what file? help is appreciated. Link to comment Share on other sites More sharing options...
DarkXero Posted April 15, 2016 Share Posted April 15, 2016 (edited) On 15/4/2016 at 2:43 AM, AquaRC said: where do I place it? in which string? what file? Any place in modmain. Open modmain.lua, go to the end, press enter a few times, and copy paste the code. Replace "wilson" in the copy pasted code for the name of your character prefab. Now, shadows will target you: local function PassiveUntilAttack(self) if self.inst:HasTag("shadow") then return end local _SetRetargetFunction = self.SetRetargetFunction self.SetRetargetFunction = function(self, period, fn) if fn then local _fn = fn fn = function(...) local _target = _fn(...) if _target and _target.prefab == "wilson" then return end return _target end end return _SetRetargetFunction(self, period, fn) end end AddComponentPostInit("combat", PassiveUntilAttack) Edited April 17, 2016 by DarkXero Link to comment Share on other sites More sharing options...
AquaRC Posted April 17, 2016 Author Share Posted April 17, 2016 I tried that code where shadows attack you but now every mob attacks me. Link to comment Share on other sites More sharing options...
DarkXero Posted April 17, 2016 Share Posted April 17, 2016 22 minutes ago, AquaRC said: I tried that code where shadows attack you but now every mob attacks me. Did you remember to change "wilson" to your character like on the first snippet? Link to comment Share on other sites More sharing options...
AquaRC Posted April 17, 2016 Author Share Posted April 17, 2016 oh ok sorry xD must've forgot Link to comment Share on other sites More sharing options...
AquaRC Posted April 17, 2016 Author Share Posted April 17, 2016 ok it works just fine now! Link to comment Share on other sites More sharing options...
CreatorKami Posted June 29, 2016 Share Posted June 29, 2016 On 4/17/2016 at 1:41 AM, AquaRC said: ok it works just fine now! This comment is a bit late, but I tried this code and the hound attacks still auto-aggro my character. I assume it's because the hound attacks don't retarget and follow the player forever. I want to make it so this character is entirely pacifist unless aggro'd. I added the code to modmain. Is there possibly a prefab tag needed? Or am I missing something? Link to comment Share on other sites More sharing options...
DarkXero Posted June 29, 2016 Share Posted June 29, 2016 5 hours ago, CreatorKami said: but I tried this code and the hound attacks still auto-aggro my character. I assume it's because the hound attacks don't retarget and follow the player forever. I want to make it so this character is entirely pacifist unless aggro'd. I added the code to modmain. Is there possibly a prefab tag needed? Or am I missing something? No, if you change the "wilson" in the code snippet then you are good to go. Use the code and spawn a hound on your face, and it will ignore you. The thing is that during hound attacks, the spawned hounds get your player suggested as a target. Which is the game aggroing them on purpose onto you. But if you manage to lose them, then they won't retarget to you. You need something like: local function ChangeSuggest(inst) if inst.components.combat then local self = inst.components.combat local _SuggestTarget = self.SuggestTarget self.SuggestTarget = function(self, target) if target and target.prefab == "wilson" and target.components.combat.target ~= self.inst then return end return _SuggestTarget(self, target) end end end AddPrefabPostInit("hound", ChangeSuggest) AddPrefabPostInit("firehound", ChangeSuggest) AddPrefabPostInit("icehound", ChangeSuggest) To avoid hounds getting your character as a suggestion. Change "wilson" for your character prefab. Link to comment Share on other sites More sharing options...
CreatorKami Posted June 29, 2016 Share Posted June 29, 2016 1 hour ago, DarkXero said: Change "wilson" for your character prefab. Thanks, I'll give this code a try! I'm super new to modding, so I can use any help I get 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