Community Forum

HELP; Get item and check for visibility

Forum Overview >> Scripting

CategoryScripting
Created12.11.2019 10:25


Zeb Farmington (ZZ_Farmington) 12.11.2019 10:25
Hi I am using mapbuyableobjects but the code is nothing to do with mapbuyableobjects code its separate.

What I am trying to do is when the item comes into the map this code runs, I thought if I could check each items visibility then that would state that the item has been bought and then run through the code.

If visibility will not work then I was thinking worldtranslation or something to that effect. But I cannot check the item for some reason.
Any help would be greatly appreciated, thank you in advance.

BuyAreaObjects = {}

function BuyAreaObjects.onCreate(id)
local x, y, z = getWorldTranslation(id);
local xr, yr, zr = getRotation(id);

if **** not sure what to put here as nothing is working **** visibility == true then
local treeType = Utils.getNoNil(getUserAttribute(id, "treeType"), "fir");
local treeIndex = Utils.getNoNil(getUserAttribute(id, "treeIndex"), 1);
local scale = Utils.getNoNil(getUserAttribute(id, "scale"), 1);
table.insert(aForestMod.TreeManager.treesToPlace, {x,y,z,yr,treeType,treeIndex,scale})
end;

delete(id);
end;


g_onCreateUtil.addOnCreateFunction("onCreateBuyAreaObjects", BuyAreaObjects.onCreate);

Bilbo Beutlin (BBeutlin) 12.11.2019 18:16
AFAIK the "mapbuyableobjects" script handles already present map objects, changes merely the ownership. That means you don't get more info by position or visibility, you must check the owner ID or similar.
Since this is non-default, but custom script depending, for this you must examine the script where the owner changes.

Zeb Farmington (ZZ_Farmington) 18.11.2019 10:27
OK that's something to look into, however just putting that and the mapbuyableobjects aside for a moment...

How do I reference the object that I'm using in my map (tree) after I use the IF statement, I've tried everything I know and its not working I think I am doing it incorrectly.
The items I am referencing are just placeholders I am also using them as an 8 triangle LOD, the items have a table with userAtrributes. onCreate.BuyAreaObjects links to that table information which is what the code uses to select which tree to add into the map/game. What I was trying to do was get the item and test an attribute of said item, but I do not believe I am referencing my item correctly.


Going back to the MapBuyableObjects,
I figured it might work with visibility but I may be wrong, as I was looking at the drawParts.lua and it does look like its changing the visibility here;
https://pastebin.com/4qe4dH7i (snippet)
https://pastebin.com/s3WEaQ8d (full)

But yes the mod does use items which are already in the map as with the following line of code for the IF statement it places the cuttable trees in the map from the start without buying them bypassing the MapBuyableObjects all together.
if g_currentMission.missionStats.traveledDistanceTotal == 0 and g_server ~= nil then

Bilbo Beutlin (BBeutlin) 18.11.2019 11:03
Since I don't know about the "MapBuyableObjects", only that it was used on some maps in FS17, I can't say anything about.
Contact the author of the script or examine the script yourself.


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