Jump to content

Help Pls with Character perks (DST)


Recommended Posts

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 by AquaRC
just made a slight adjustment
Link to comment
Share on other sites

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

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 by DarkXero
Link to comment
Share on other sites

On 4/17/2016 at 1:41 AM, AquaRC said:

ok it works just fine now! :D

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

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

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