Jump to content

DS/DST Bug or am I doing something wrong?


Recommended Posts

Hello I am writing my first DST mod, I don't want to give away my ideas so I will try to keep as much information to myself as I can.

I am making grass spawn faster on a specific tile, the code I have is:

for k, v in pairs(Ents) do
	local owner = v.components.inventoryitem and v.components.inventoryitem.owner
	if owner == nil and v.prefab == "grass" then
		if v.dcrew == nil then
			if v.AnimState:IsCurrentAnimation("picked") then
				v.dcrew = true
				local tile = TheWorld.Map:GetTileAtPoint(v:GetPosition():Get())
				if tile == GROUND.SAVANNA then
					v.components.pickable:SetUp("cutgrass", TUNING.dcrew.GRASS_ON_SAVANNA)
				end
			end
		elseif not v.AnimState:IsCurrentAnimation("picked") then
			v.dcrew = nil
		end
	end
end

the result is: it works, and I can re-pick the grass (after it grows) but its animation stays picked:

It only does it the first time I pick it, so if I pick it and then wait until it grows the animation refreshes/works fine.

Am I doing wrong or is this a DS bug?

Link to comment
Share on other sites

Probably because you don't reset the running task that takes care of the regen. I'd bet if you waited for the original growth time, the animation would correct itself. You may be able to take advantage of the LongUpdate(dt) function of the pickable component. After calling the SetUp() function, try this:

v.components.pickable:LongUpdate(0)

We tell it to do a LongUpdate, which is usually used when we want the game to skip a bunch of time, but we just tell it to skip 0 seconds. The LongUpdate() function always stops the current task and restarts it with the times set in the component, so it should do what you want.

Link to comment
Share on other sites

4 hours ago, Ultroman said:

Probably because you don't reset the running task that takes care of the regen. I'd bet if you waited for the original growth time, the animation would correct itself. You may be able to take advantage of the LongUpdate(dt) function of the pickable component. After calling the SetUp() function, try this:


v.components.pickable:LongUpdate(0)

We tell it to do a LongUpdate, which is usually used when we want the game to skip a bunch of time, but we just tell it to skip 0 seconds. The LongUpdate() function always stops the current task and restarts it with the times set in the component, so it should do what you want.

Yeah that's what I found worked not long after I posted this yesterday, I asked for it to be removed before it got approved but I guess that didn't happen, so I'll be useful and post what I had changed that fixed it.

Thank you very much anyway @Ultroman your solution was correct either way!

The whole code from the first post but with my changes:

for k, v in pairs(Ents) do
	local owner = v.components.inventoryitem and v.components.inventoryitem.owner
	if owner == nil and v.dcrew == nil then
		if v.prefab == "grass" then
			if v.AnimState:IsCurrentAnimation("picked") then
				local tile = TheWorld.Map:GetTileAtPoint(v:GetPosition():Get())
				if tile == GROUND.SAVANNA then
					--print("[dcrew] "..v.prefab.." picked on savanna")
					v.components.pickable.targettime = v.components.pickable.targettime - v.components.pickable.regentime + TUNING.dcrew.GRASS_ON_SAVANNA
					v.components.pickable.regentime = TUNING.dcrew.GRASS_ON_SAVANNA
					v.components.pickable.baseregentime = TUNING.dcrew.GRASS_ON_SAVANNA
					v.components.pickable:LongUpdate(0)
				end
				v.dcrew = true
			end
		end
	end
end

 

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