Recommended Posts

Yakuzashi    3
Posted (edited)

Hello, I am trying to achieve artillery barrage effect on item drop. I am still working on it but in case of my failure I am asking you for help.

 

Quote

local Assets =
{
    Asset("ANIM", "anim/barrage.zip"),
    Asset("ATLAS", "images/inventoryimages/barrage.xml"),    
    Asset("IMAGE", "images/inventoryimages/barrage.tex")
}

local prefabs =
{
}

local function OnEquip(inst, owner)
    
end

local function OnUnequip(inst, owner)
    
end

local function barrage(inst, owner)
            local pt = owner:GetPosition()
            local numtentacles = 3

           
            owner:StartThread(function()
                for k = 1, numbarrages do
                    local theta = math.random() * 2 * PI
                    local radius = math.random(3, 8)
                  

                    if result_offset ~= nil then
                        local x, z = pt.x + result_offset.x, pt.z + result_offset.z
                        local barrage = SpawnPrefab("explode_small")
                        barrage.Transform:SetPosition(x, 0, z)
                        

                    end

                    Sleep(.33)
                end
            end)
end


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

    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("barrage")
    inst.AnimState:SetBuild("barrage")
    inst.AnimState:PlayAnimation("idle", true)
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/barrage.xml"
 
    
    inst:AddComponent("inspectable")
    
    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip( OnEquip )
    inst.components.equippable:SetOnUnequip( OnUnequip )
    inst.components.equippable:SetOnEquip(barrage)
    
    MakeHauntableLaunch(inst)
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(200)
    inst.components.finiteuses:SetUses(200)    
    inst.components.finiteuses:SetOnFinished(inst.Remove)


    
    return inst
end

return Prefab( "common/inventory/barrage", fn, Assets)

 

 

I don't know how to trigger barrage on drop so I am experimenting with equip/unequip right now.

 

UPDATE:

I edited prefab file a little bit so this is how it looks now:
 

Quote

local Assets =
{
    Asset("ANIM", "anim/barrage.zip"),
    Asset("ATLAS", "images/inventoryimages/barrage.xml"),    
    Asset("IMAGE", "images/inventoryimages/barrage.tex")
}

local prefabs =
{
}


local function barragecall(inst, target)
            local pt = target:GetPosition()
            local numtentacles = 32

           
            target:StartThread(function()
                for k = 1, numtentacles do
                    local theta = math.random() * 2 * PI
                    local radius = math.random(3, 8)

                    -- we have to special case this one because birds can't land on creep
                    local result_offset = FindValidPositionByFan(theta, radius, 12, function(offset)
                        local pos = pt + offset
                        --NOTE: The first search includes invisible entities
                        return #TheSim:FindEntities(pos.x, 0, pos.z, 1, nil, { "INLIMBO", "FX" }) <= 0
                            and TheWorld.Map:IsDeployPointClear(pos, nil, 1)
                    end)

                                       
                    
                     if result_offset ~= nil then
                        local x, z = pt.x + result_offset.x, pt.z + result_offset.z
                        local tentacle = SpawnPrefab("explode_small")                                                
                        tentacle.Transform:SetPosition(x, 0, z)
                        
                        

                    end

                    Sleep(.33)
                end
            end)
end

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

    MakeInventoryPhysics(inst)
    
    inst.AnimState:SetBank("barrage")
    inst.AnimState:SetBuild("barrage")
    inst.AnimState:PlayAnimation("idle", true)    

    
    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/barrage.xml"
    
    
    inst:AddComponent("inspectable")
    
    MakeHauntableLaunch(inst)
    
    inst:AddComponent("edible")
    inst.components.edible.sanityvalue = -30
    inst.components.edible:SetOnEatenFn(barragecall)       


    
    return inst
end

return Prefab( "common/inventory/barrage", fn, Assets)

 

Can someone tell me how to add damage to every explosion ?

Edited by Yakuzashi
update

Share this post


Link to post
Share on other sites
Yakuzashi    3

:cry: RIP

 

local assets =
{
    Asset("ANIM", "anim/explode.zip")
}

 

local function MakeExplosion(data)
    local function PlayExplodeAnim(proxy)
        local inst = CreateEntity()

        inst:AddTag("FX")
        --[[Non-networked entity]]
        inst.entity:SetCanSleep(false)
        inst.persists = false

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

        inst.Transform:SetFromProxy(proxy.GUID)

        if data ~= nil and data.scale ~= nil then
            inst.Transform:SetScale(data.scale, data.scale, data.scale)
        end

        inst.AnimState:SetBank("explode")
        inst.AnimState:SetBuild("explode")
        inst.AnimState:PlayAnimation(data ~= nil and data.anim or "small")
        inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
        inst.AnimState:SetLightOverride(1)

        if data ~= nil and type(data.sound) == "function" then
            data.sound(inst)
        else
            inst.SoundEmitter:PlaySound(data ~= nil and data.sound or "dontstarve/common/blackpowder_explo")
        end

        inst:ListenForEvent("animover", inst.Remove)
    end

    local function fn()
        local inst = CreateEntity()

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

        --Dedicated server does not need to spawn the local fx
        if not TheNet:IsDedicated() then
            --Delay one frame so that we are positioned properly before starting the effect
            --or in case we are about to be removed
            inst:DoTaskInTime(0, PlayExplodeAnim)
        end

        inst.Transform:SetFourFaced()
        
        inst:AddTag("explosive")
        inst:AddTag("FX")

        inst.entity:SetPristine()

        if not TheWorld.ismastersim then
            return inst
        end

    inst:AddComponent("explosive")        
    inst.components.explosive:SetDamage(200)
    
        inst.persists = false
        inst:DoTaskInTime(1, inst.Remove)

        return inst
    end

    return fn
end

local extras =
{
    slurtle =
    {
        sound = "dontstarve/creatures/slurtle/explode",
    },
    slurtlehole =
    {
        sound = "dontstarve/creatures/slurtle/mound_explode",
    },
    firecrackers =
    {
        anim = "small_firecrackers",
        sound = function(inst)
            inst.SoundEmitter:PlaySoundWithParams("dontstarve/common/together/fire_cracker", { start = math.random() })
        end,
        scale = .5,
    }
}

return Prefab("explode", MakeExplosion(), assets)

 

----------------------------------

That's the explode_small prefab modified to give possibility of adding AOE damage for each explosion. Anyway it crashes or can't do any damage. I am terrible at coding.

Edited by Yakuzashi

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