First post here on the BI Forums. Has been a great resource so far, as evidenced by the fact that I haven't had to make a single post looking for help in the four years I've been involved in Arma :P
I'm working on a farming script which dynamically creates an object that a player can gather. The issue I am having is that if multiple objects are created without the player moving around, they are all created in the same place as each other. On the wiki page for createVehicle it is stated that "If the exact position is occupied, nearest empty position is used.". For whatever reason this doesn't seem to be working in this case, however the object I am using does throw the following RPT error: No geometry and no visual shape.
To fix this, I wrote a script which checks if an object is within a certain radius of another object of the same classname, and if it is then to move the object. For some reason, it doesn't seem to be doing anything. I tested the code using the debug console and it worked perfectly fine, however when I implement it into the mission file it doesn't seem to work.
No errors thrown regarding this script from the RPT. There is more code in the SQF, but this is the only segment which is giving me issues.
plantCrop.sqf
_plantObject = "classname";
//Create the plant
_plant = _plantObject createVehicle (getpos player);
_plant setVariable ["plantReady", false, true];
//Check if plant is too close to another plant
_nearestCrop = nearestObject [(getpos _plant), _plantObject];
_distance = (getpos _plant) distance (getpos _nearestCrop);
if (_distance <= 2) then {
_random = selectRandom [1,2];
if (_random == 1) then {
_plant setPos [(getPos _plant select 0) + 2, getPos _plant select 1];
} else {
if (_random == 2) then {
_plant setpos [getPos _plant select 0, (getPos _plant select 1) + 2];
};
};
};