Jump to content

Recommended Posts

I use a shadow puppet "clone" to make a craftable creature with a player's appearance. In the same way I can make it hold any kind of hand-held tool, I'd like it to wear a hat uppon spawning.

 

Below you will find the relevant code in of the prefab's lua, as a spoiler.

 Here's my thinking so far:

Note the assets. The game appears to search for a variety of tools using    

Asset("ANIM", "anim/"..tool..".zip"). 

I don't really understand how that works since no relevant folder in anim seems to contain "tool" in its name. But somehow it works. Then, at the bottom of the code, we have  

return  MakeMinion("guardianminer","swap_pickaxe")

"swap_pickaxe" is used to make the creature spawn with it holding a pickaxe. I'd like to add something like a "swap_minerhat" so it can wear a minerhat. But I don't know how to make the game find the minerhat. The games' anim files contain a "hat_miner" but referring to it with a

Asset("ANIM", "anim/hat_miner.zip") 

and simultaneously using

return  MakeMinion("guardianminer","swap_pickaxe", "swap_minerhat") 

doesn't work. The game can't find "swap_minerhat" and crashes. Using the following string ("..hat.." instead of "hat_miner") doesn't result in a crash, but the creature won't be wearing a hat in-game either. 

Asset("ANIM", "anim/"..hat..".zip")

I tried that last one just in case it might work analogous to 

Asset("ANIM", "anim/"..tool..".zip"). 

Spoiler

local function MakeMinion(prefab, tool, hat, master_postinit)
    local assets =
    {
        Asset("ANIM", "anim/guardian_thibaud.zip"),
        Asset("SOUND", "sound/maxwell.fsb"),
        Asset("ANIM", "anim/"..tool..".zip"),

    }

    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()
        inst.entity:AddAnimState()
        inst.entity:AddSoundEmitter()
        inst.entity:AddNetwork()

        inst.entity:AddDynamicShadow()
        inst.DynamicShadow:Enable(true)
        inst.DynamicShadow:SetSize(1, 1)
        
        MakeGhostPhysics(inst, 1, 0.5)

        inst.Transform:SetFourFaced(inst)

        inst.AnimState:SetBank("wilson")
        inst.AnimState:SetBuild("guardian_thibaud")
        inst.AnimState:PlayAnimation("idle")
        -- inst.AnimState:SetMultColour(0, 0, 0, .5)

        if tool ~= nil then
            inst.AnimState:OverrideSymbol("swap_object", tool, tool)
            inst.AnimState:Hide("ARM_normal")
        else
            inst.AnimState:Hide("ARM_carry")
        end

        if hat ~= nil then
            inst.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
            inst.AnimState:Hide("HAIR_NOHAT")
            inst.AnimState:Hide("HAIR")
        else
            inst.AnimState:Hide("HAT")
            inst.AnimState:Hide("HAIR_HAT")
        end

        inst:AddTag("scarytoprey")
        inst:AddTag("shadowminion")
        inst:AddTag("NOBLOCK")

        inst:SetPrefabNameOverride("guardian_thibaud")

        inst.entity:SetPristine()

        if not TheWorld.ismastersim then
            return inst
        end

        

        
        inst:AddComponent("locomotor")
        inst.components.locomotor.runspeed = TUNING.SHADOWWAXWELL_SPEED
        inst.components.locomotor.pathcaps = { ignorecreep = true }
        inst.components.locomotor:SetSlowMultiplier(.6)

        inst:AddComponent("health")
        inst.components.health:SetMaxHealth(1)
        inst.components.health.nofadeout = true
        inst.components.health.redirect = nodebrisdmg

        inst:AddComponent("combat")
        inst.components.combat.hiteffectsymbol = "torso"
        inst.components.combat:SetRange(2)

        inst:AddComponent("follower")
        inst.components.follower:KeepLeaderOnAttacked()
        inst.components.follower.keepdeadleader = true

        inst:SetBrain(brain)
        inst:SetStateGraph("SGguardian_thibaud")

        inst:ListenForEvent("attacked", OnAttacked)

        inst.OnBuiltFn = onbuilt
        
        if master_postinit ~= nil then
            master_postinit(inst)
        end

        return inst
    end

    return Prefab(prefab, fn, assets, prefabs)
end

return MakeMinion("guardianlumber", "swap_axe"),
    MakeMinion("guardianminer","swap_pickaxe"),
    MakeMinion("guardiandigger", "swap_shovel"),
    MakeMinion("guardianduelist", "swap_spear", nil, spearfn),
    MakeBuilder("guardianlumber"),
    MakeBuilder("guardianminer"),
    MakeBuilder("guardiandigger"),
    MakeBuilder("guardianduelist")

 

Thanks in advance! :)

Edited by Fancy_Fox_Pers
6 hours ago, Aquaterion said:

I don't think you really need to call the assets at the top, but for hats, its not swap_minerhat, but it would be something like hat_miner

Well I thought I should use swap_minerhat because when yielding a spriter folder of the anim files (using ktools) I find the images are in a folder "swap_minerhat". The images are then called "swap_hat-0" with increasing numbers. But the spriter file itself (.scml) is called "hat_miner", so I now tried

return    MakeMinion("guardianminer","swap_pickaxe", "hat_minerhat"),

But that doesn't result in any change in-game, no crash either. So I guess my real problem is that I don't know how to properly "call" what I'm doing. It's probably just meaningless code, if you know what I mean. Thanks for the input!

 

 

5 hours ago, kertinker said:

you might need to make a special "shadow" version of the hat, so that it doesn't look like there's a real miner's hat floating around.

This is not a problem because my creature actually looks like a player, I removed the shadow effects. I just need it to spawn with a real minerhat that works, it's basically a miner companion.

13 minutes ago, Aquaterion said:

"hat_miner" not "hat_minerhat"

Oh wow. Wait, is that because in the game file hats.lua it respectively says at the top and bottom

local function MakeHat(name)
    local fname = "hat_"..name
return  MakeHat("miner"),

? Many thanks!


This of course only made the minerhat appear, but without any light. I knew how to fix it so for the record if anyone's interested:

Spoiler

local function lightfn(inst)
    local light = inst.entity:AddLight()
    inst.Light:Enable(true)
    inst.Light:SetFalloff(0.4)
    inst.Light:SetIntensity(.7)
    inst.Light:SetRadius(2.5)
    inst.Light:SetColour(180 / 255, 195 / 255, 150 / 255)
    
    return inst
end

 


return     MakeMinion("guardianminer","swap_pickaxe", "hat_miner", lightfn),

 

 

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