Jump to content

Trying to make a Panic perk for a character


Recommended Posts

I am very new to modding and am trying to get the hang of it, I am having trouble figuring out how a perk for a character that gains a speed boost when near an negative sanity aura effect, how would I code it?

Edited by Sanguine_Cree
Link to comment
Share on other sites

That's gonna be difficult, because many people have implemented sanity auras in different ways. If you're just talking about the vanilla stuff, like spiders which have a negative sanity aura, you're going to have to do something special.

In your character's masterpostinit, put this in:

-- DoPeriodicTask calls the given function every X seconds.
-- I set it to 1.0. You can set it to e.g. 0.5 seconds if you want.
inst:DoPeriodicTask(1.0, function(inst)
	-- 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.
	local ents = TheSim:FindEntities(x, y, z, TUNING.SANITY_EFFECT_RANGE, nil, {"playerghost", "INLIMBO", "FX", "NOCLICK", "DECOR"}, nil)

	for i, v in ipairs(ents) do 
		if v ~= inst and v.components.sanityaura ~= nil and v.components.sanityaura:GetAura(inst) < 0 then
			-- One of the entities has a sanityaura component on with a negative sanity aura value,
			-- so we apply the modifier and return immediately.
			inst.components.locomotor:SetExternalSpeedMultiplier(inst, "negativeauraspeedmod", 1.25)
			return
		end
	end
	
	-- No negative auras were found, so we remove the speed modifier.
	inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "negativeauraspeedmod")
end)

 

Edited by Ultroman
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...