Community Forum

How to get access to attachedImplements now ?

Forum Overview >> Scripting

Created05.12.2018 17:23

Mykola Kushnir (Mykola) 05.12.2018 17:23
I am trying convert FS17 script to FS19.

This is how it work for FS17:

for nIndex,oImplement in pairs(oVehicle.attachedImplements)

where oVehicle is:
local oVehicle = g_currentMission.steerables[i];

Now, I replace oVehicle like:
local oVehicle = g_currentMission.enterables[i];

But oVehicle.attachedImplements return nil. So, how I can get attachedImplements now?

Any sample highly appreciate.

Jason Lynn (redmachine) 05.12.2018 23:55
I was successful in using vehicle:getAttachedImplements where vehicle is g_currentMission.controlledVehicle.
if g_currentMission.eneterables[i] is a vehicle then it should work as well for that.

for n in pairs(vehicle:getAttachedImplements()) do
local implement = vehicle:getObjectFromImplementIndex(n);

Note: Not sure how it worked with 17 but with 19 the getAttachedImplements only returns the implements directly attached to the vehicle, if you need an implement attached to another implement you need to recursively call it, at least that's how I'm handling it for now.

Mykola Kushnir (Mykola) 06.12.2018 00:29
Strange, for me g_currentMission.controlledVehicles count always return zero. Just did quick test and got next output:
g_currentMission.enterables - 14
g_currentMission.controlledVehicles - 0
g_currentMission.vehicles - 29.

Maybe I miss smth else. Could you share your script, just want check will it work in the same way as for you ?

Jason Lynn (redmachine) 06.12.2018 01:15
I forgot to mention, g_currentMission.controlledVehicle is only defined when you are in a vehicle.
If you want to apply something to all vehicles then you will likely need a different variable.

function mod:update(dt)
if(g_currentMission.controlledVehicle ~= nil) then
local vehicle = g_currentMission.controlledVehicle;
for n in pairs(vehicle:getAttachedImplements()) do
local implement = vehicle:getObjectFromImplementIndex(n);

Markus Hupfeld (Hupfi2012) 08.12.2018 02:46
Error: failed to load i3d file 'C:/Users/Desktop/Documents/My Games/FarmingSimulator2019/mods/ETA_Gaming_Simulator/data/shared/ai/trafficCollision.i3d'

Kevin I. (Ifkonator2) 15.12.2018 18:14
You can use:

function ModScript:onUpdate(dt, isActiveForInput, isSelected)
for implementIndex, implement in pairs(self.spec_attacherJoints.attachedImplements) do -- here will all attached Implements stored


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