Jump to content

Recommended Posts

Hello dearest forum

After taking a big break from making anything with DST mods I've decided to do a rework of my own two mods
(this time combining them into one)

The thing I need help with is...

I want to make character A death take some sanity from character B and conversely

Like, when character outside this mode dies (like Wilson) I don't want anything (outside what happens normally in game ofc) happen to Gray and Nick
But when Nick or Gray dies I want the other suffer some sanity loss (~10-15? Idk yet)

I also recycled some old code you helped me with and I don't want it to override it or fight with themselves

	-- Gain Sanity near player
		-- Every 1.0 seconds, execute the following function.
	inst:DoPeriodicTask(1.0, function()
	-- Do nothing if the player is dead.
	if inst.components.health:IsDead() or inst:HasTag("playerghost") then
		return
	end
	
	-- Store the position of the player in x, y, z variables.
	local x,y,z = inst.Transform:GetWorldPosition()
	
	-- Description of important function, which finds specific entities within a range:
	-- TheSim:FindEntities(x, y, z, radius, mustHaveTags, cantHaveTags, mustHaveOneOfTheseTags)
	
	-- We have limited it to any entity that is not ghosts, visuals or things in limbo.
	-- I have set the radius to be the one used for standard negative auras. You can set it to whatever radius you want.
	-- You can replace "TUNING.SANITY_EFFECT_RANGE" with a number instead, if you want to change the range.
	-- TUNING.SANITY_EFFECT_RANGE is 10.
	local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, nil, {"playerghost", "INLIMBO", "FX", "NOCLICK", "DECOR"}, nil)
	for k,v in pairs(ents) do 
		-- Substitute "THE_OTHER_CHARACTER_PREFAB"
		if v.prefab == "gray" then
			-- Give sanity if a player with that name is found.
			-- "true" makes the sanity-badge NOT pulse and make a sound when doing this.
			inst.components.sanity:DoDelta(0.4, true)
			return
		end
	end
end)

(The mod is not done yet and it's a big, BIG mess, Still got many things to do, so if any wrongly written code catch your eye please let me know)
(Few things I have from Reign of Runts
gray&nick.rar)

gray&nick.rar

The sanity aura for players seems to be fine. As for removing sanity, the first idea that comes to mind is to add an AddPlayerPostInit which should work for all players. You could use some system of events and trigger the loss of sanity. I just tested out some events but they didn't work. I tried listening for entity_death, which is apparently only used for players, but it did not work; and the event "death" is local to only the player that dies and others cannot hear it. If you were to use events, one solution could be to add a custom event to the health component for when a player dies (this is checked in the SetVal function) and listen for it in modmain.

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