Jump to content

Recommended Posts

Hi! I'm trying to add a sanity-boosting property to a funcap. If I add the line: 

inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE

directly to the game file, then everything works. But how can I do this by creating a mod? I found a mod that adds glow to a funcap. When I add my line to the file of this mod, everything works, but I do not know how to rewrite it to remove the funcap glow.

The code that adds the glow:

local function MakeHat(name)
    local fname = "hat_"..name
    local symname = name.."hat"
    local prefabname = symname

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

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

		inst.components.periodicspawner:Start()

		if owner.components.hunger ~= nil then
			owner.components.hunger.burnratemodifiers:SetModifier(inst, TUNING.MUSHROOMHAT_SLOW_HUNGER)
		end
		
		if inst._light == nil or not inst._light:IsValid() then
			if name == "red_mushroom" then
				inst._light = SpawnPrefab("redmushroomlight")
			elseif name == "green_mushroom" then
				inst._light = SpawnPrefab("greenmushroomlight")
			elseif name == "blue_mushroom" then
				inst._light = SpawnPrefab("bluemushroomlight")
			end
		end
		inst._light.entity:SetParent(owner.entity)

		if owner.components.bloomer ~= nil then
			owner.components.bloomer:PushBloom(inst, "shaders/anim.ksh", 1)
		else
			owner.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		end
	end

	local function turnoff(inst)
		if inst._light ~= nil then
			if inst._light:IsValid() then
				inst._light:Remove()
			end
			inst._light = nil
		end
	end
	
	local function onunequip(inst, owner)
		owner.AnimState:ClearOverrideSymbol("swap_hat")
        owner.AnimState:Hide("HAT")
        owner.AnimState:Hide("HAIR_HAT")
        owner.AnimState:Show("HAIR_NOHAT")
        owner.AnimState:Show("HAIR")

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

		inst.components.periodicspawner:Stop()

		if owner.components.hunger ~= nil then
			owner.components.hunger.burnratemodifiers:RemoveModifier(inst)
		end
		
		if owner.components.bloomer ~= nil then
			owner.components.bloomer:PopBloom(inst)
		else
			owner.AnimState:ClearBloomEffectHandle()
		end
		
		turnoff(inst)
	end

	local function displaynamefn(inst)
		return STRINGS.NAMES[string.upper(inst.prefab)]
	end

	local function custom_init(inst)
		
	end

	local function common(spore_prefab, light_prefab)
		local inst = CreateEntity()
		
        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddNetwork()

        MakeInventoryPhysics(inst)

        inst.AnimState:SetBank(symname)
        inst.AnimState:SetBuild(fname)
        inst.AnimState:PlayAnimation("anim")

        inst:AddTag("hat")

        if custom_init ~= nil then
            custom_init(inst)
        end

        MakeInventoryFloatable(inst)

        inst.entity:SetPristine()

        if not TheWorld.ismastersim then
            return inst
        end

		inst:SetPrefabNameOverride("mushroomhat")
		
        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)
		
		inst.components.equippable:SetOnEquip(onequip)
		inst.components.equippable:SetOnUnequip(onunequip)

		inst:AddComponent("perishable")
		inst.components.perishable:SetPerishTime(TUNING.PERISH_MED)
		inst.components.perishable:StartPerishing()
		inst.components.perishable:SetOnPerishFn(inst.Remove)		
		inst:AddTag("show_spoilage")

		inst:AddComponent("periodicspawner")
		inst.components.periodicspawner:SetPrefab(spore_prefab)
		inst.components.periodicspawner:SetRandomTimes(TUNING.MUSHROOMHAT_SPORE_TIME, 1, true)

		inst:AddComponent("insulator")
		inst.components.insulator:SetSummer()
		inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL)

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

		MakeHauntableLaunchAndPerish(inst)
		
		inst._light = nil
		inst.OnRemoveEntity = turnoff

		return inst
	end

	local function red_mushroom()
		local inst = common("spore_medium")

		inst.components.floater:SetSize("med")
		inst.components.floater:SetScale(0.95)

		if not TheWorld.ismastersim then
			return inst
		end

		return inst
	end

	local function green_mushroom()
		local inst = common("spore_small")

		inst.components.floater:SetSize("med")

		if not TheWorld.ismastersim then
			return inst
		end

		return inst
	end

	local function blue_mushroom()
		local inst = common("spore_tall")

		inst.components.floater:SetSize("med")
		inst.components.floater:SetScale(0.7)

		if not TheWorld.ismastersim then
			return inst
		end

		return inst
	end

	local fn = nil
	local assets = { Asset("ANIM", "anim/"..fname..".zip") }
	local prefabs = nil

	if name == "red_mushroom" then
		fn = red_mushroom
	elseif name == "green_mushroom" then
		fn = green_mushroom
	elseif name == "blue_mushroom" then
		fn = blue_mushroom
	end

	return Prefab(prefabname, fn or default, assets, prefabs)
end
	   
local function redlightfn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    inst:AddTag("FX")

    inst.Light:SetRadius(2)
    inst.Light:SetFalloff(.7)
    inst.Light:SetIntensity(.75)
    inst.Light:SetColour(197/255, 126/255, 126/255)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    return inst
end

local function greenlightfn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    inst:AddTag("FX")

    inst.Light:SetRadius(2)
    inst.Light:SetFalloff(.7)
    inst.Light:SetIntensity(.75)
    inst.Light:SetColour(146/255, 225/255, 146/255)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    return inst
end

local function bluelightfn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    inst:AddTag("FX")

    inst.Light:SetRadius(2)
    inst.Light:SetFalloff(.7)
    inst.Light:SetIntensity(.75)
    inst.Light:SetColour(111/255, 111/255, 227/255)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst.persists = false

    return inst
end

return MakeHat("red_mushroom"),
       MakeHat("green_mushroom"),
       MakeHat("blue_mushroom"),
	   Prefab("redmushroomlight", redlightfn),
	   Prefab("greenmushroomlight", greenlightfn),
	   Prefab("bluemushroomlight", bluelightfn)

How can I force funkap to raise a character's sanity?

The mod you used as a base is way more complicated than what you really need.

In reality, you only need a modinfo.lua file and a modmain.lua file. In modmain.lua, you only need to add this and the mod you want is complete:

local function AddSanity(inst)
  if not GLOBAL.TheWorld.ismastersim then
    return inst
  end
  inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE
end

AddPrefabPostInit("red_mushroom",AddSanity)
AddPrefabPostInit("green_mushroom",AddSanity)
AddPrefabPostInit("blue_mushroom",AddSanity)

You will still need to fill the modinfo.lua file with the info it needs, but the modmain.lua file only needs this.

With AddPrefabPostInit you add a function to a prefab that is already existing, in this case your sanity boosting.

  • Like 1
1 hour ago, Monti18 said:

The mod you used as a base is way more complicated than what you really need.

In reality, you only need a modinfo.lua file and a modmain.lua file. In modmain.lua, you only need to add this and the mod you want is complete:


local function AddSanity(inst)
  if not GLOBAL.TheWorld.ismastersim then
    return inst
  end
  inst.components.equippable.dapperness = TUNING.DAPPERNESS_LARGE
end

AddPrefabPostInit("red_mushroom",AddSanity)
AddPrefabPostInit("green_mushroom",AddSanity)
AddPrefabPostInit("blue_mushroom",AddSanity)

You will still need to fill the modinfo.lua file with the info it needs, but the modmain.lua file only needs this.

With AddPrefabPostInit you add a function to a prefab that is already existing, in this case your sanity boosting.

Thank you very much for your reply! I did everything exactly as you indicated, but now the game hangs when creating the server.

Edited by SilentKid
32 minutes ago, Monti18 said:

Have a look at the server log. The error should be written there. If you're not sure what causes it, post the server log here.

After looking at the logs, I only realized that the mod is causing some kind of error. But I can't understand the reason. 

The name of the mod containing your code: "my (Red Mushroom Hat)"

server_log.txt

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