Category | Scripting |
Created | 19.03.2022 10:32 |
Dirk Hameier (DirkH42) | 19.03.2022 10:32 |
---|---|
Hi, I know the funtion to get the Farmland (g_farmlandManager:getFarmlandIdAtWorldPosition) but I need a method to get the exact field, especially if the farmland has more than one field. Thx a lot Dirk |
Michael T. (mx11de) | 21.03.2022 18:46 |
---|---|
Source: gamesource.zip Vehicle.lua local isOnField, _ = FSDensityMapUtil.getFieldDataAtWorldPosition(wx, wy, wz) if isOnField then return true end |
Dirk Hameier (DirkH42) | 24.03.2022 18:01 |
---|---|
Thank you very much, I will try it out right away. |
Dirk Hameier (DirkH42) | 26.03.2022 19:08 |
---|---|
Unfortunately, the function does not help with my problem. It only returns the info if I am standing on a field, but not on which one. |
Colin Smith (WrinkleysRule) | 26.03.2022 20:16 |
---|---|
Have you looked in the debugger dataS scripts under fields ---Field.Lua |
Loki Laufeyson (loki_79) | 27.03.2022 21:27 |
---|---|
It seems like there is no in-game function to obtain the field id. I had a look in CoursePlay, and they have written a function to get the id of the owned plot of land, but not the specific field id. |
Jon Sage (jtsage) | 28.03.2022 03:57 |
---|---|
There isn't a base game function for it, so far as I've found. https://github.com/jtsage/FS22_simpleInspector/blob/6ae5572140e0094c70eb508dda1a0ff64f5ad6d0/src/SimpleInspector.lua#L307 The important bit is line 332 on. Courtesy somewhat of HappyLooser on his VehicleInspector mod, with some changes by me. Keep in mind, it is not terrible accurate at field edges, and even less so when you join fields together. |
Michael T. (mx11de) | 29.03.2022 12:22 |
---|---|
In the Fieldmanager.lua at line 130 is a part with an connection from field to farmland. You could try to use the table farmlandIdFieldMapping for i, field in ipairs(self.fields) do local posX, posZ = field:getCenterOfFieldWorldPosition() local farmland = g_farmlandManager:getFarmlandAtWorldPosition(posX, posZ) if farmland ~= nil then field:setFarmland(farmland) if self.farmlandIdFieldMapping[farmland.id] == nil then self.farmlandIdFieldMapping[farmland.id] = {} end table.insert(self.farmlandIdFieldMapping[farmland.id], field) else Logging.error("Failed to find farmland in center of field '%s'", i) end end |
Note: Log in to post. Create a new account here.