Jump to content

'Fade' animation and non-deleting deployable


Recommended Posts

I'm in dire need of assistance!

How is the 'fade' effect on dead/destroyed things handled? I'd like to add this effect for my item, but I don't know how to do it. You know, this effect:

fade.JPG.63cba0126a51e54df839c9a14b6b3f2

It doesn't seem to be related to creature animations, because spriter/krane doesn't show/unpack these anims, so it's probably done in a different way.

 

The second thing I have problem with is: I'd like to make a deployable item that isn't consumed upon being deployed. I tried to make a custom action:

-- Make a special action for stickybomb launcher
local STICKYBOMBING = GLOBAL.Action({ priority= -10 })	
STICKYBOMBING.str = "Set Up"
STICKYBOMBING.id = "STICKYBOMBING"
STICKYBOMBING.fn = function(act)
	if act.invobject and act.invobject.prefab == "stickybomblauncher" and act.invobject.components.deployable and act.invobject.components.deployable:CanDeploy(act.pos) then
        local obj = act.doer.components.inventory or act.doer.components.container
        if obj then
            if obj.components.deployable:Deploy(act.pos, act.doer) then
                return true
            else
                act.doer.components.inventory:GiveItem(obj)
            end
        end
    end
end
AddAction(STICKYBOMBING)

local stickybombing_handler = ActionHandler(ACTIONS.STICKYBOMBING, "dolongaction")
AddStategraphActionHandler("wilson", stickybombing_handler)

AddComponentAction("SCENE", "inventoryitem", function(inst, doer, pos, actions, right)
    if right and inst:HasTag("stickybomblauncher") and inst.replica.inventoryitem ~= nil and inst.replica.inventoryitem:CanDeploy(pos) then
        table.insert(actions, ACTIONS.STICKYBOMBING)
    end
end)
AddStategraphActionHandler("wilson_client", stickybombing_handler)

It doesn't matter what priority it is, Deploy is always used instead.

I tried to edit "Deploy" in deployable component, but I failed miserably at that as well. Welp. Maybe there's a different, better way to do that?

Any help is welcome!

Link to comment
Share on other sites

A pinecone's deployment is set up this way:

local function plant(inst, growtime)
    local sapling = SpawnPrefab("pinecone_sapling")
    sapling:StartGrowing()
    sapling.Transform:SetPosition(inst.Transform:GetWorldPosition())
    sapling.SoundEmitter:PlaySound("dontstarve/wilson/plant_tree")
    inst:Remove()
end

local function ondeploy(inst, pt, deployer)
    inst = inst.components.stackable:Get()
    inst.Physics:Teleport(pt:Get())
    local timeToGrow = GetRandomWithVariance(TUNING.PINECONE_GROWTIME.base, TUNING.PINECONE_GROWTIME.random)
    plant(inst, timeToGrow)
--...
end

local function fn()
--...
    inst:AddComponent("deployable")
    inst.components.deployable:SetDeployMode(DEPLOYMODE.PLANT)
    inst.components.deployable.ondeploy = ondeploy
--...
end

I'd guess removing the inst:Remove() from plant() should not consume it. Although, looking at DEPLOY action's call of inventory:RemoveItem(act.invobject), they seem to be interconnected.

That component action doesn't seem to be set up correctly. SCENE collector function receives (inst, doer, actions, right) arguments, not (inst, doer, pos, actions, right) (that POINT collector function receives).

Can you try this (in addition to not calling inst:Remove() within your stickybomblauncher's deployable.ondeploy:

-- Make a special action for stickybomb launcher
local STICKYBOMBING = GLOBAL.Action({ priority= 10 })	
STICKYBOMBING.str = "Set Up"
STICKYBOMBING.id = "STICKYBOMBING"
STICKYBOMBING.fn = function(act)
	if act.invobject and act.invobject.prefab == "stickybomblauncher" and act.invobject.components.deployable and act.invobject.components.deployable:CanDeploy(act.pos) then
        if act.invobject.components.deployable:Deploy(act.pos, act.doer) then
            return true
        end
    end
end
AddAction(STICKYBOMBING)

local stickybombing_handler = ActionHandler(ACTIONS.STICKYBOMBING, "dolongaction")
AddStategraphActionHandler("wilson", stickybombing_handler)

AddComponentAction("POINT", "deployable", function(inst, doer, pos, actions, right)
    if right and inst:HasTag("stickybomblauncher") and inst.replica.inventoryitem ~= nil and inst.replica.inventoryitem:CanDeploy(pos) then
        table.insert(actions, ACTIONS.STICKYBOMBING)
    end
end)
AddStategraphActionHandler("wilson_client", stickybombing_handler)

 

Edited by Muche
Link to comment
Share on other sites

3 hours ago, Muche said:

Can you try this (in addition to not calling inst:Remove() within your stickybomblauncher's deployable.ondeploy:


-- Make a special action for stickybomb launcher
local STICKYBOMBING = GLOBAL.Action({ priority= 10 })	
STICKYBOMBING.str = "Set Up"
STICKYBOMBING.id = "STICKYBOMBING"
STICKYBOMBING.fn = function(act)
	if act.invobject and act.invobject.prefab == "stickybomblauncher" and act.invobject.components.deployable and act.invobject.components.deployable:CanDeploy(act.pos) then
        if act.invobject.components.deployable:Deploy(act.pos, act.doer) then
            return true
        end
    end
end
AddAction(STICKYBOMBING)

local stickybombing_handler = ActionHandler(ACTIONS.STICKYBOMBING, "dolongaction")
AddStategraphActionHandler("wilson", stickybombing_handler)

AddComponentAction("POINT", "deployable", function(inst, doer, pos, actions, right)
    if right and inst:HasTag("stickybomblauncher") and inst.replica.inventoryitem ~= nil and inst.replica.inventoryitem:CanDeploy(pos) then
        table.insert(actions, ACTIONS.STICKYBOMBING)
    end
end)
AddStategraphActionHandler("wilson_client", stickybombing_handler)

 

Thank you very much! It works perfectly! :)

Yeah, inst:Remove() was the first thing I got rid of when trying to make it so item doesn't get deleted. It seems that it's meant to remove it on top of removing the second time within action itself to make it 100% sure item gets destroyed.

demo_happy.jpg.ca0b3b9f0d6cd9b4f3933c189

Demoman is one bloody happy lad now.

Edited by PanAzej
Link to comment
Share on other sites

On 24.03.2016 at 8:39 PM, Neutral_Steve said:

Damn, looks so awesome!

demosaw.png.fafb66197eca7841d82c292f8103

On 24.03.2016 at 9:11 PM, Muche said:

Regarding the fade out animation, components/health.lua|SetVal() uses ErodeAway, defined in simutil.lua, which in turn calls inst.AnimState:SetErosionParams(erode_amount, 0.1, 1.0).

Oh, so it's related to health component! Thank you so much once again!

I got most of the things working by now, mod should be released next week, I think :)

Link to comment
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
 Share

×
  • Create New...