Recommended Posts

Grymlahv    1

So, I'm trying to make my character afraid of Pickaxes. Being that he himself is made of rock. I've found a thread that point's me in the right direction.

Spoiler

 

But I'm wondering how do I check other player's inventories for Them holding a pick, and how do I check the ground for random dropped pickaxes, either from corpses or people not using chests. Thanks in advance

Share this post


Link to post
Share on other sites
Grymlahv    1

Also looking at the Zinnia Mod, they have this code for sharp things

Spoiler

-- Make afraid of sharp things
local function sanityfn(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local delta = 0
    local max_rad = 10
    local ent = FindEntity(inst, 5, function(ent) 
        return ent:HasTag("aichmophobiafuel")
            and not(ent.components.health and ent.components.health:IsDead())
    end)
    if ent then
        local sz = -TUNING.SANITYAURA_SMALL*0.75
        local rad = 10
        sz = sz * ( math.min(max_rad, rad) / max_rad )
        local distsq = inst:GetDistanceSqToInst(ent)
        delta = delta + sz/math.max(1, distsq)
    end
    
    return delta
end

along with this list in the modmain

Spoiler

- Zinnia is afraid of sharp things
AddPrefabPostInit("cactus", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("marsh_tree", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("marsh_bush", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("beehive", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("wasphive", setAura(-TUNING.SANITYAURA_LARGE))
--AddPrefabPostInit("trap_teeth", setAura(-TUNING.SANITYAURA_TINY)) -- Now tagged as aichmophobiafuel
--AddPrefabPostInit("beemine", setAura(-TUNING.SANITYAURA_SMALL)) -- Now tagged as aichmophobiafuel

AddPrefabPostInit("bee", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("killerbee", setAura(-TUNING.SANITYAURA_LARGE))
AddPrefabPostInit("beebox", setAura(-TUNING.SANITYAURA_SMALL))


AddPrefabPostInit("slurtlehole", setAura(-TUNING.SANITYAURA_SMALL))

--[[
AddPrefabPostInit("sewing_kit", setAura(-TUNING.SANITYAURA_MED))
AddPrefabPostInit("stinger", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("houndstooth", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("boneshard", setAura(-TUNING.SANITYAURA_TINY))

AddPrefabPostInit("flint", setAura(-TUNING.SANITYAURA_TINY))

AddPrefabPostInit("blowdart_pipe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("blowdart_fire", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("blowdart_sleep", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("spear", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("tentaclespike", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("pickaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("goldenpickaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("pitchfork", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("axe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("goldenaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("multitool_axe_pickaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("ruins_bat", setAura(-TUNING.SANITYAURA_TINY))
]]

AddPrefabPostInit("blowdart_pipe", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("blowdart_fire", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("blowdart_sleep", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("spear", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("spear_wathgrithr", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("tentaclespike", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("pickaxe", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("goldenpickaxe", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("pitchfork", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("axe", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("goldenaxe", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("multitool_axe_pickaxe", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("ruins_bat", setDapper(-TUNING.DAPPERNESS_MED))

-- Modded
AddPrefabPostInit("rakkyboomerang", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("rakkyboomerang_feather", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("rakkyboomerang_bat", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("nedelyasword", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("maliksword", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("tirixmace", setDapper(-TUNING.DAPPERNESS_MED))

-- Exceptions to the sharpness rule
AddPrefabPostInit("umbrella", setDapper(0))

-- Give the rest of sharp objects a negative dapperness
AddTagEquippablePostInit(function(inst)
    setDapper(-TUNING.DAPPERNESS_MED)(inst)        
end, "sharp")

 

Share this post


Link to post
Share on other sites
IThatGuyI    33

Try this:

local TUNING = GLOBAL.TUNING -- TUNING for the small sanity value

local function SanityDrain(inst, observer) -- The function that checks for a specific prefab
	if observer.prefab == "wilson" then -- I used Wilson as a test, you can use your character
		return -TUNING.SANITYAURA_SMALL -- The value of sanity drain
	else
		return 0 -- If it's not Wilson, do nothing
	end
end

AddPrefabPostInit("pickaxe", function(inst) -- Pickaxe override ( also override goldenpickaxe and multitool_axe_pickaxe )
	inst:AddComponent("sanityaura") -- Add a sanityaura component, for obvious reasons
	inst.components.sanityaura.aurafn = SanityDrain -- Set the sanity function
end)

This should make pickaxes on the ground s̷̮̝͖̜̰̪̤̣͝c̸̢͈̝͔̥̪͂̋͗̂̂͛ȃ̵̧̡̛͓̼̭̱̰͔̳̐̀́̒̚ͅr̵̘̣͗̈́͌́̀́̄̍͠y̴̨̘͓̌̽̒̀̈.

  • Thanks 1

Share this post


Link to post
Share on other sites
Grymlahv    1

So, I'm trying to emulate Zinnia's sanity lose while holding bad thing. I think I'm doing things right, but everytime I try to load up the server crashes. 
I have this in my modmain

Spoiler

--[[AddPrefabPostInit("pickaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("goldenpickaxe", setAura(-TUNING.SANITYAURA_TINY))
AddPrefabPostInit("multitool_axe_pickaxe", setAura(-TUNING.SANITYAURA_TINY))]]

AddPrefabPostInit("pickaxe", setDapper(-TUNING.DAPPERNESS_SMALL))
AddPrefabPostInit("goldenpickaxe", setDapper(-TUNING.DAPPERNESS_MED))
AddPrefabPostInit("multitool_axe_pickaxe", setDapper(-TUNING.DAPPERNESS_MED))

AddTagEquippablePostInit(function(inst)
    setDapper(-TUNING.DAPPERNESS_MED)(inst)        
end, "orebane")


local Orebane = function (inst)
    inst:AddTag("orebane")
end

And this in my prefab

Spoiler

local function sanityfn(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local delta = 0
    local max_rad = 10
    local ent = FindEntity(inst, 5, function(ent) 
        return ent:HasTag("orebane")
            and not(ent.components.health and ent.components.health:IsDead())
    end)
    if ent then
        local sz = -TUNING.SANITYAURA_SMALL*0.75
        local rad = 10
        sz = sz * ( math.min(max_rad, rad) / max_rad )
        local distsq = inst:GetDistanceSqToInst(ent)
        delta = delta + sz/math.max(1, distsq)
    end
    
    return delta
end

Am I missing a tag in my common_postinit? Where would I define it? Or is it something else entirely?

Share this post


Link to post
Share on other sites
Grymlahv    1

I also just found this

Spoiler

--function to add/change dapperness for specific items
local setDapper = function(EnergyFennecDapper)
    return function(prefab)
        if IsMasterSim() and prefab.components.equippable and not prefab.doneEnergyFennecPostInit then
            prefab.doneEnergyFennecPostInit = true -- Disallow adding another post init to this prefab
            local dapperfn_orig
            local dapperness = 0
            local dapperfn_plus = function(inst,owner)
                if owner:HasTag("aichmophobic") and not (inst.components.fueled and inst.components.fueled:IsEmpty()) then
                    return EnergyFennecDapper
                end
                if dapperfn_orig then
                    return dapperfn_orig(inst,owner)
                end
                return dapperness
            end
            dapperfn_orig = prefab.components.equippable.dapperfn
            prefab.components.equippable.dapperfn = dapperfn_plus
            dapperness = prefab.components.equippable.dapperness
        end
    end
end

But my coding experience is very limited. What does prefab.doneEnergyFennecPostInit mean?

Share this post


Link to post
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