Community Forum

Linking i3d to custom script

Forum Overview >> Scripting

Created05.02.2019 01:39

Derek Squire (dezza069) 05.02.2019 01:39
Hi all,

Would someone please be kind enough to provide an example (or a link) of how to link a (custom) trigger in an i3d "placeable item" (for example), to a custom script which is loaded with the map, using a custom "onCreate" scriptCallBack user attribute/function in Farming Simulator 19.

I've tried all sorts of things based on info found on the various forums and the GDN tutorials, but much of it seems out-of-date for FS19 and, I am lost. I also can't see the links on the GDN tutorials for the support docs to have a look at them. Many of the forums explain Animations, which I have working fine. It's accessing the custom script itself from the i3d I'm totally confused with. And, the new mods I've found are not using scripts - they seem to be mostly XML based and just using standard functions.

Just a simple example - even just a few LUA lines - for a custom skeleton "onCreate" function and any applicable i3d tags to point me in the right direction would be much appreciated.

Thanks very much in advance.

Derek Squire (dezza069) 05.02.2019 05:18
Here's an example of somethings I've tried, adding a trigger/object with an "onCreate" scriptCallBack user attribute with "doStuffonCreate" as the string.

in script, log says this script is being loaded with the map, but "doStuffonCreate" is not loaded.

_G.doStuffonCreate = function(id)
print("Trigger doStuff:", id);

With an "onCreate" scriptCallBack user attribute with "doStuff.onCreate" as the string, script loads - doStuff.onCreate does not.

function doStuff:onCreate(id)
print("doStuff:onCreate - initiated.");

And this. Didn't work.

function doStuff:loadMap(name)
doStuff.isRunning = false;
g_onCreateUtil.addOnCreateFunction("doStuffonCreate", doStuff.onCreate);

Debug entries show the custom script is loaded when the maps loads, but there is never any errors or references to these onCreate functions from the i3d when loaded...

Obviously, I'm doing something wrong and have totally missed it, but I can't seem to even add a user "onCreate" scriptCallBack for "NightLight2.onCreate" and get it to work either.

Any guidance is very much appreciated.

Thanks! :)

Derek Squire (dezza069) 07.02.2019 02:13
Ok, after spending a few days looking, found these two forum entries:

... and I've ended up with a script loaded via the map's modDesc.xml file (scripts/doStuff.lua) containing these lines outside of any functions:

doStuff.modDirectory = g_currentModDirectory;
doStuff.specFile = Utils.getFilename("placeables/custom/mySpecialFactory/scripts/mySpecial_Factory.lua", doStuff.modDirectory);
print("doSuff: specFile: "..doStuff.specFile)
doStuff.ret = g_placeableTypeManager:addPlaceableType("mySpecial_Factory", "SiloPlaceable", doStuff.specFile, "addPlaceableType()");

Which results in log entry:
2019-02-07 10:59 Loaded placeable types
2019-02-07 10:59 doStuff.lua - loaded
2019-02-07 10:59 doSuff: specFile: /Users/XXXXXXXXX/Library/Application Support/FarmingSimulator2019/mods/FS19_EstanciaLapacho/placeables/custom/mySpecialFactory/scripts/mySpecial_Factory.lua
2019-02-07 10:59 Error: No filename specified for placeable type 'FS19_EstanciaLapacho.mySpecial_Factory'. Ignoriring it!

Is anyone able to please offer any suggestion(s)?

Thanks very much.

Derek Squire (dezza069) 09.02.2019 11:53

Me again!!

This can all be ignored with the 1.3.0 beta update, it appears to work correctly.

Thank you.

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