Community Forum

Get Growstate

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created26.06.2010 23:28

Heady Planet-ls (Headshot XXL) 26.06.2010 23:29
Exist a function to get the current Growstate of a Area?

Stefan Geiger - GIANTS Software 30.06.2010 15:00
The density functions always return the sum of all the values, thus you can only calculate the growth state if you assume that each value in the area has the same growth state.

However you can also just get the value for a single value

For example you can use this function:
getDensityRegion(densityId, x, y, 1, 1, 0, 3);

Using this function, you will get a value between 0 and 5. Where
0 = no fruit
1 = growth state 0 (seeded but not visible yet)
2 = growth state 1
3 = growth state 2
4 = growth state 3
5 = growth state 4

The parameters x and y is the position of the pixel in the density maps, in pixels.
Thus they need to be between 0 and 4095.

Heady Planet-ls (Headshot XXL) 30.06.2010 19:51
I tried this:

function Foliage:getGrowstate(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ)
local x,z, widthX,widthZ, heightX,heightZ = Utils.getXZWidthAndHeight(g_currentMission.terrainDetailId, startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ);
local density = getDensityRegion(g_currentMission.fruits[FruitUtil.FRUITTYPE_WHEAT].id, (1024+x)*2, (1024+z)*2, 1, 1, 0, 3);
print("density", density);

but "density" is 0. If i set Wheat on the bottom right corner on the Map (coordinate: x=1024, y=1024), i got "density" = 5.
I think the both 1,1 of getDensityRegion(...) are not right, but i don't know.

Stefan Geiger - GIANTS Software 02.07.2010 09:57
You should pass the same id to the Utils.getXZWidthAndHeight as to the getDensityRegion.
However this shouldnt be the problem, since the current setup doen not make a difference.

If you use x=1024 and y=1024, you have the problem, that you will get the coordinate 4096,4096 which is just one pixel out of range.
So you should use a smaller value, e.g x=y=1023.5 or you should do some clamping on the calculated values math.max(math.min((1024+x)*2,4095),0)

Heady Planet-ls (Headshot XXL) 02.07.2010 14:56
Sorry, I wrote my problem not exactly.

print("density", density) is all over the map = 0, also on wheat areas. If i set wheat on the bottom right corner on the Map, than is print("density", density) = 5 all over the map, also on not wheat areas.

Heady Planet-ls (Headshot XXL) 08.07.2010 23:18
x and y is not the input of the pixel, but the input of coordinates. now it works.

Bad Touch (Unknown) 27.05.2011 10:51

I am working on a mod where I am using the growth state of different areas, and have followed everything posted here about using getDensityRegion. I am using the PDA coordinates for the x,y parameters. For some reason, I just cannot get the values to come out right. The highest number I get back is "4", and it is right for some areas, and not right for other areas.

I was just wondering if you could help me figure out what I might be doing wrong. I just would like to be able to figure out the correct growth state for different areas on my maps.


Bad Touch (Unknown) 28.05.2011 02:38
Well, I finally figured everything out. Thanks to all who posted. I have learned a great deal.

Note: Log in to post. Create a new account here.