Jump to content

Recommended Posts

Hey there!

 

I want to give my character the ability to gain Sanity if she's around other players. I was able to achieve the same with some mobs, but I'm not sure how can I do it to players.

I'm using this code for the mobs (it's in my modmain.lua):

Spoiler

 

local function PositiveSanity(inst, observer)
    if observer.prefab == "spinel" then 
        return TUNING.SANITYAURA_MED
    end
    
    return 0
end

AddPrefabPostInit("butterfly", function(inst) 
    inst:AddComponent("sanityaura")
    inst.components.sanityaura.aurafn = PositiveSanity
end)

 

 

Is there a general codename for players (like "butterfly" above) or is it a lot more complicated than this?

Thanks in advance! :)

Edited by BillTheCipher

Every character has a prefab. The name is the same as the characters, with some exceptions like Maxwell named Waxwell and Wigfrid named Wathgrith. But I think it's better checking for players instead of checking for prefabs. You can do it like this:

AddPlayerPostInit(function(inst) -- function for every player
	local function PositiveSanity(inst, observer)
		if observer.prefab == "wilson" then -- "wilson" can be any character
			return TUNING.SANITYAURA_SMALL
		end
		
		return 0
	end

	if inst.components.sanityaura ~= nil then --= checking if the sanityaura component is there
		inst.components.sanityaura.aurafn = PositiveSanity
	else
		inst:AddComponent("sanityaura")
		inst.components.sanityaura.aurafn = PositiveSanity
	end
end)

 

Edited by IThatGuyI
  • Like 2

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