Jump to content

3 questions for a character mod


Recommended Posts

Hey all,

I've tried googling and searching through files to find the answers, but had no luck, so asking here.

Does anyone know the code for losing extra sanity for a character, 20 per minute?

Also the code for a hat that would give the wearer 20 sanity per minute, to negate his extra sanity loss?

Finally, what code do I need so that picking something up costs 5 sanity?

Thanks in advance. 

 

 

Edited by FaZZa
Link to comment
Share on other sites

1 hour ago, FaZZa said:

losing extra sanity for a character, 20 per minute?

-- master_postinit

inst.components.sanity.dapperness = -TUNING.DAPPERNESS_HUGE

 

1 hour ago, FaZZa said:

a hat that would give the wearer 20 sanity per minute

local assets = {}

local function onequip(inst, owner)
	owner.AnimState:OverrideSymbol("swap_hat", "hat_top", "swap_hat")
	owner.AnimState:Show("HAT")
	owner.AnimState:Show("HAT_HAIR")
	owner.AnimState:Hide("HAIR_NOHAT")
	owner.AnimState:Hide("HAIR")

	if owner:HasTag("player") then
		owner.AnimState:Hide("HEAD")
		owner.AnimState:Show("HEAD_HAT")
	end
end

local function onunequip(inst, owner)
	owner.AnimState:ClearOverrideSymbol("swap_hat")
	owner.AnimState:Hide("HAT")
	owner.AnimState:Hide("HAT_HAIR")
	owner.AnimState:Show("HAIR_NOHAT")
	owner.AnimState:Show("HAIR")

	if owner:HasTag("player") then
		owner.AnimState:Show("HEAD")
		owner.AnimState:Hide("HEAD_HAT")
	end
end

local function fn()
	local inst = CreateEntity()
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
	inst.entity:AddNetwork()

	MakeInventoryPhysics(inst)

	inst.AnimState:SetBank("tophat")
	inst.AnimState:SetBuild("hat_top")
	inst.AnimState:PlayAnimation("anim")

	inst:AddTag("hat")

	inst.entity:SetPristine()

	if not TheWorld.ismastersim then
		return inst
	end

	inst:AddComponent("inventoryitem")
	inst:AddComponent("inspectable")
	inst:AddComponent("tradable")

	inst:AddComponent("equippable")
	inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
	inst.components.equippable:SetOnEquip(onequip)
	inst.components.equippable:SetOnUnequip(onunequip)

	-- This gives sanity gain to the hat
	inst.components.equippable.dapperness = TUNING.DAPPERNESS_HUGE

	inst:AddComponent("fueled")
	inst.components.fueled.fueltype = FUELTYPE.USAGE
	inst.components.fueled:InitializeFuelLevel(TUNING.TOPHAT_PERISHTIME)
	inst.components.fueled:SetDepletedFn(inst.Remove)

	inst:AddComponent("waterproofer")
	inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)

	MakeHauntableLaunch(inst)

	return inst
end

return Prefab("testhat", fn, assets)

 

1 hour ago, FaZZa said:

picking something up costs 5 sanity

-- master_postinit

inst:ListenForEvent("onpickupitem", function(inst, data)
	inst.components.sanity:DoDelta(-5)
end)

 

Link to comment
Share on other sites

Thanks, the first two parts work fine, but this:

1 hour ago, DarkXero said:

-- master_postinit inst:ListenForEvent("onpickupitem", function(inst, data) inst.components.sanity:DoDelta(-5) end)

Causes the game to crash I might not have made it clear sorry, i meant a specific item, the prefab for it is "soul"

Edited by FaZZa
Link to comment
Share on other sites

7 minutes ago, FaZZa said:

Causes the game to crash I might not have made it clear sorry, i meant a specific item, the prefab for it is "soul"

It doesn't crash for me.

You putting it on the master_postinit of your character? Maybe it's the soul that causes the crash when grabbing it.

inst:ListenForEvent("onpickupitem", function(inst, data)
	local item = data and data.item
	if item and item.prefab == "soul" then
		inst.components.sanity:DoDelta(-5)
	end
end)

This for specific item.

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