Jump to content

Recommended Posts

As the title says, i want to create a perk that focuses on sanity during combat, it goes like this -

  • This character has 250 sanity (Already coded).
  • Whenever this character is attacked, this character loses 10 sanity points,
  • This effect also applies to everyone else in the server, but everyone else loses 3 sanity points instead.
  • When this character dies, everyone loses 90 sanity points.
  • When this character is revived, their sanity score will start at 20.

Can someone help or at least hint me through on how i'm able to do this? I would be very grateful! :D

Edited by DonMatio

Try this

local function DoSanityDeltaOnAttacked(inst)
	for _, v in pairs(AllPlayers) do
		if v.components.sanity ~= nil and not v:HasTag("playerghost")
			if v == inst then
				v.components.sanity:DoDelta(-10)
			else
				v.components.sanity:DoDelta(-3)
			end
		end
	end
end

local function DoSanityDeltaOnDeath()
	for _, v in pairs(AllPlayers) do
		if v.components.sanity ~= nil and not v:HasTag("playerghost")
			v.components.sanity:DoDelta(-90)
		end
	end
end

local function SetSanityOnRevive(inst)
	inst:DoTaskInTime(0, function(inst) v.components.sanity.current = 20 end)
end

inst:ListenForEvent("attacked", DoSanityDeltaOnAttacked)
inst:ListenForEvent("ms_becameghost", DoSanityDeltaOnDeath)
inst:ListenForEvent("ms_respawnedfromghost", SetSanityOnRevive)

 

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