Jump to content

Make a bush plantable in specific turfs


Recommended Posts

I do something like this :


    inst:AddComponent("deployable")
	inst.components.deployable.CanDeploy = test
    inst.components.deployable.ondeploy = OnDeploy
    inst.components.deployable:SetDeployMode(DEPLOYMODE.PLANT)

local function test(inst, pt)
	if TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.DECIDUOUS or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.FOREST or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.GRASS then
		return true
	else
		return false
	end
end

First part in the main function of the item you want to deploy (like the dug_bush), second in your prefab. Change the ground name for what you want.

I'm not sure it's perfect, sometime it act strangely (like not showing that planting here is not possible), but still a first step i guess.

Link to comment
Share on other sites

2 hours ago, Lumina said:

I do something like this :



    inst:AddComponent("deployable")
	inst.components.deployable.CanDeploy = test
    inst.components.deployable.ondeploy = OnDeploy
    inst.components.deployable:SetDeployMode(DEPLOYMODE.PLANT)


local function test(inst, pt)
	if TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.DECIDUOUS or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.FOREST or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.GRASS then
		return true
	else
		return false
	end
end

First part in the main function of the item you want to deploy (like the dug_bush), second in your prefab. Change the ground name for what you want.

I'm not sure it's perfect, sometime it act strangely (like not showing that planting here is not possible), but still a first step i guess.

@Lumina Thanks buddy, it worked like a charm :D. Just a few questions to help me understand the code better, if you have time to answer:

So as far as I knew then you called a function, you used () as in  generic_function(), but in the example you sent you called it just generic_function and it actually doesn't work with (). Do you know why?

Also I don't completely understand at all what the inst and pt means in the test function.

Last one: As I understended you told me to put the first part on the dug_x_bush main code and the second on the x_bush code right? (might be me misunderstanding you, if so, sorry, english is not my primary language). But it only worked when I placed the second part in the dug_bush prefab file too.

Anyway thanks for all the help, you're awesome!

Link to comment
Share on other sites

This is why;

local function test(inst)
	if inst ~= nil then
		return true
	else
		return false
	end
end

inst.components.deployable.CanDeploy = test

--'CanDeploy' will store the 'test' function itself, and whenever 'CanDeploy' is called, 
--it will run 'test'. This line doesn't run the 'test' function

inst.components.deployable.CanDeploy = test(inst)

--'CanDeploy' will store the RETURN value of 'test' function instead. 
--This line runs the 'test' function to get the return value

--The Difference? The way its implemented in the 'deployable' component.

 

Edited by Aquaterion
Link to comment
Share on other sites

17 hours ago, Zardexrlz said:

english is not my primary language

Mine isn't either and it was late yesterday so sorry if i made mistake explaining. I wanted to explain where to put what in the prefab, but wasn't clear.

For the others questions, i don't understand enough how things work to explain. My code is based on another code that was doing not exactly what i wanted so i modified it a bit, but can't explain all the parts.

17 hours ago, Zardexrlz said:

Also I don't completely understand at all what the inst and pt means in the test function.

So i'm totally not sure, but i think inst is the basic function itself, and pt is needed to be able to use "TheWorld.Map:GetTileAtPoint(pt:Get())", like some function have "onpickedfn(inst, picker)". I can't explain more why and how it's needed, i learn by copying, changing code and sometime i understand and others not.

Also i forgot, you need a "OnDeploy" function at some point i guess, mine look like this :

local function OnDeploy(inst, pt, deployer) 
    local prefabname = SpawnPrefab("prefabname")
	if prefabname then
		prefabname.Transform:SetPosition(pt:Get())
		prefabname.components.pickable:MakeEmpty()
		inst.components.stackable:Get():Remove()
	end
end

I don't remember if the game does it naturally.

 

Good luck !

Link to comment
Share on other sites

3 minutes ago, Lumina said:

Mine isn't either and it was late yesterday so sorry if i made mistake explaining. I wanted to explain where to put what in the prefab, but wasn't clear.

For the others questions, i don't understand enough how things work to explain. My code is based on another code that was doing not exactly what i wanted so i modified it a bit, but can't explain all the parts.

So i'm totally not sure, but i think inst is the basic function itself, and pt is needed to be able to use "TheWorld.Map:GetTileAtPoint(pt:Get())", like some function have "onpickedfn(inst, picker)". I can't explain more why and how it's needed, i learn by copying, changing code and sometime i understand and others not.

Also i forgot, you need a "OnDeploy" function at some point i guess, mine look like this :


local function OnDeploy(inst, pt, deployer) 
    local prefabname = SpawnPrefab("prefabname")
	if prefabname then
		prefabname.Transform:SetPosition(pt:Get())
		prefabname.components.pickable:MakeEmpty()
		inst.components.stackable:Get():Remove()
	end
end

I don't remember if the game does it naturally.

 

Good luck !

@Lumina

Oh yeah, I already had a OnDeploy (actually mine was ondeploy but whatever) function. Later I was thinking that It might be something like:
Lets suppose we have a function
local function generic_function(inst, pt)

     --     do stuff

end

If we call generic_function(), we are saying that inst and pt are nil, but if we call like generic_function, without () we might be saying to use as variables inside generic_function or even use global variables. I might be totally wrong though. Again, thanks for all the help \o/

Edited by Zardexrlz
Link to comment
Share on other sites

On 22.12.2016 at 2:22 AM, Lumina said:

I do something like this :



    inst:AddComponent("deployable")
	inst.components.deployable.CanDeploy = test
    inst.components.deployable.ondeploy = OnDeploy
    inst.components.deployable:SetDeployMode(DEPLOYMODE.PLANT)


local function test(inst, pt)
	if TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.DECIDUOUS or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.FOREST or TheWorld.Map:GetTileAtPoint(pt:Get()) == GROUND.GRASS then
		return true
	else
		return false
	end
end

First part in the main function of the item you want to deploy (like the dug_bush), second in your prefab. Change the ground name for what you want.

I'm not sure it's perfect, sometime it act strangely (like not showing that planting here is not possible), but still a first step i guess.

That was that I have been searching for! Is it possible to add deployabillity to custom turfs?

Edited by makar5000
  • Like 1
Link to comment
Share on other sites

4 hours ago, makar5000 said:

That was that I have been searching for! Is it possible to add deployabillity to custom turfs?

Of course

1 hour ago, Lumina said:

I didn't try.

 

I think it's possible, if they have a name like the normal ones, but i don't know if you need something special for the game to recognize special turfs.

GROUND.DECIDUOUS is just a global variable that contains a number. Deciduous being 30. As long as you know the id for that groundtype then you're good.

all the numbers can be found in DST/data/scripts/constants.lua:Line 377

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