Jump to content

Recommended Posts

I have a follower creature that has been proven to work perfectly well. But I want it to stay after logging out and in, like maxwell's shadow puppets, so I tried implementing the same kind of code. Upon crafting, the creature doesn't appear, even though the resources are consumed.

I didn't expect to run into much trouble since I already have a shadow puppet clone, the only difference here being that the new follower I'm trying to make has a different kind of build and anim. I can't make heads or tail out of it. I probably just have no idea how petleash works. I could really use a tutorial on it...

Is there anything wrong with my onbuilt and MakeBuilder functions? What about the return at the bottom?

Spoiler

local function OnAttacked(inst, data)
    if data.attacker ~= nil then
        if data.attacker.components.petleash ~= nil and
            data.attacker.components.petleash:IsPet(inst) then
            if inst.components.lootdropper == nil then
                inst:AddComponent("lootdropper")
            end
            inst.components.lootdropper:SpawnLootPrefab("papyrus", inst:GetPosition())
            data.attacker.components.petleash:DespawnPet(inst)
        elseif data.attacker.components.combat ~= nil then
            inst.components.combat:SuggestTarget(data.attacker)
        end
    end
end

local function onbuilt(inst, builder)
    local theta = math.random() * 2 * PI
    local pt = builder:GetPosition()
    local radius = math.random(3, 6)
    local offset = FindWalkableOffset(pt, theta, radius, 12, true)
    if offset ~= nil then
        pt.x = pt.x + offset.x
        pt.z = pt.z + offset.z
    end
    builder.components.petleash:SpawnPetAt(pt.x, 0, pt.z, inst.pettype)
    inst:Remove()
end

local function MakeBuilder(prefab)
    --These shadows are summoned this way because petleash needs to
    --be the component that summons the pets, not the builder.
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()

        inst:AddTag("CLASSIFIED")

        --[[Non-networked entity]]
        inst.persists = false

        --Auto-remove if not spawned by builder
        inst:DoTaskInTime(0, inst.Remove)

        if not TheWorld.ismastersim then
            return inst
        end

        inst.pettype = prefab
        inst.OnBuiltFn = onbuilt

        return inst
    end

    return Prefab(prefab.."_builder", fn, nil, { prefab })
end


local function MakeMinion(prefab, master_postinit)

    local assets =
    {
    
        Asset("ANIM", "anim/caterpillar_thibaud.zip"),  
    
    }
    local function fn()
        local inst = CreateEntity()

        inst.entity:AddTransform()

        inst.entity:AddAnimState()
        inst.entity:AddSoundEmitter()
        inst.entity:AddDynamicShadow()
        inst.DynamicShadow:Enable(true)
        inst.DynamicShadow:SetSize(2.5, .5)
        inst.entity:AddMiniMapEntity()

        inst.entity:AddNetwork()
        
        inst:SetPrefabNameOverride("caterpillar_thibaud")    
    
        inst.entity:SetPristine()
        if not TheWorld.ismastersim then
                return inst
        end
        

        
        inst.AnimState:SetBank("caterpillar_thibaud") 
        inst.AnimState:SetBuild("caterpillar_thibaud")

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


        
        
        inst:AddComponent("locomotor")
        inst.components.locomotor.walkspeed = 7
        inst.components.locomotor.runspeed = 7

        MakeCharacterPhysics(inst, 75, 0.4)
        
        inst.Transform:SetFourFaced()
        
        inst:AddComponent("follower")
        inst.components.follower:KeepLeaderOnAttacked()
        inst.components.follower.keepdeadleader = true
        
        inst:AddComponent("combat")

        inst:AddComponent("health")
        inst.components.health:SetMaxHealth(TUNING.CHESTER_HEALTH)
        
        local brain = require "brains/caterpillar_thibaudbrain" 
        inst:SetBrain(brain)

        inst:AddComponent("inspectable")
        
        inst:ListenForEvent("attacked", OnAttacked)

        
        
        inst:AddTag("scarytoprey")
        inst:AddTag("paperdrawing")


        
        MakeSmallBurnableCharacter(inst, "chest")
        
        inst:AddTag("character")
        inst:AddTag("scarytoprey")
        
        inst:SetStateGraph("SGcaterpillar_thibaud")
        inst.sg:GoToState("idle")

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

    return Prefab(prefab, fn, assets)
end


return MakeMinion( "caterpillar_thibaud"),
    MakeBuilder("caterpillar_thibaud")

 

 

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