Jump to content

Custom Character Mod help needed: Disabling Shadow Hostility


Recommended Posts

I'm currently trying to mod in a character for DST, yet I've come across a pretty difficult challenge. I need it so that my character is capable of going insane, yet shadow monsters WILL NOT become hostile towards him regardless of his sanity value.

So far, I've tried to yank the code from Webber's spider de-aggro mechanic and change it to my character's circumstances, yet nothing seemed to happen. Here is the code incase I did something wrong:

local function CLIENT_Welix_HostileTest(inst, target)
    if target.HostileToPlayerTest ~= nil then
        return target:HostileToPlayerTest(inst)
    end
    return (target:HasTag("hostile"))
        and (not target:HasTag("crawlinghorror") or target:HasTag("crawlingnightmare") or target:Hastag("terrorbeak") or target:HasTag("nightmarebeak") or target:HasTag("terrorclaw"))
end

(My character's name is Welix, btw)

I then attempted to make it so that shadows do not enter combat with them based on their sanity, but that code didn't seem to work either. Here is the code I snatched from the nightmare creatures file and tweaked it to try make them not aggro:

local function CLIENT_ShadowSubmissive_HostileToWelixTest(inst, welix)
    if welix:HasTag("shadowdominance") then
        return false
    end
    local combat = inst.replica.combat
    if combat ~= nil and combat:GetTarget() == welix then
        return false
    end
    local sanity = welix.replica.sanity
    if sanity ~= nil and sanity:IsCrazy() then
        return false
    end
    return false
end

I am very new to coding and especially new to lua, so if there are any mistakes coding wise that I should change about the script (I expect maybe a lot of variable names incorrect), then please inform me! Or alternatively, I would really appreciate a script to help with this matter.

Thank you so much in advance!

Link to comment
Share on other sites

Woodie has a skill tree perk so that Shadows don't target him while he's transformed, so I looked into how that works. It's pretty simple, it's just two tags that handle this. Add these to your character's common_postinit function:

inst:AddTag("inherentshadowdominance") -- So that "shadowdominance" tag is returned once Shadows stop being angry because you attacked them
inst:AddTag("shadowdominance") -- So that Shadows don't target you

I did expect there to be an issue when unequipping the Bone Helm though, where the functionality would stop working, and after testing I turned out to be correct. Woodie doesn't have this problem because he can't equip/unequip stuff when transformed. But I managed to fix it with this code, add it to your modmain:

-- Hack so that unequipping a Bone Helm doesn't make you lose the "shadowdominance" tag
AddComponentPostInit("shadowdominance", function(self)
	self.inst:ListenForEvent("unequipped", function(inst, data)
		if data ~= nil and data.owner ~= nil and data.owner.prefab == "yourcharacterprefabhere" then -- Make sure to change this!!!
			data.owner:DoTaskInTime(0, function() -- Delay by a frame so our code runs after the code that removes the tag
				if data.owner._shadowdsubmissive_task == nil then -- Make sure this task isn't running, otherwise Shadows lose aggro instantly the moment you unequip a Bone Helm (not regular behavior)
					data.owner:AddTag("shadowdominance") -- Reapply the tag that was removed by unequipping the Bone Helm
				end
			end)
		end
	end)
end)

Remember to change "yourcharacterprefabhere" to your character's prefab name. Alternatively, you could change it to check for a tag exclusive to your character, up to you!

  • Like 1
Link to comment
Share on other sites

On 12/30/2023 at 2:38 PM, ClumsyPenny said:

Woodie has a skill tree perk so that Shadows don't target him while he's transformed, so I looked into how that works. It's pretty simple, it's just two tags that handle this. Add these to your character's common_postinit function:

inst:AddTag("inherentshadowdominance") -- So that "shadowdominance" tag is returned once Shadows stop being angry because you attacked them
inst:AddTag("shadowdominance") -- So that Shadows don't target you

I did expect there to be an issue when unequipping the Bone Helm though, where the functionality would stop working, and after testing I turned out to be correct. Woodie doesn't have this problem because he can't equip/unequip stuff when transformed. But I managed to fix it with this code, add it to your modmain:

-- Hack so that unequipping a Bone Helm doesn't make you lose the "shadowdominance" tag
AddComponentPostInit("shadowdominance", function(self)
	self.inst:ListenForEvent("unequipped", function(inst, data)
		if data ~= nil and data.owner ~= nil and data.owner.prefab == "yourcharacterprefabhere" then -- Make sure to change this!!!
			data.owner:DoTaskInTime(0, function() -- Delay by a frame so our code runs after the code that removes the tag
				if data.owner._shadowdsubmissive_task == nil then -- Make sure this task isn't running, otherwise Shadows lose aggro instantly the moment you unequip a Bone Helm (not regular behavior)
					data.owner:AddTag("shadowdominance") -- Reapply the tag that was removed by unequipping the Bone Helm
				end
			end)
		end
	end)
end)

Remember to change "yourcharacterprefabhere" to your character's prefab name. Alternatively, you could change it to check for a tag exclusive to your character, up to you!

All of this worked perfectly, thank you!

Edited by RussianChattus
  • GL Happy 1
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...