Home   Help Search Login Register  

Author Topic: position near a tree  (Read 3272 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
position near a tree
« on: 01 Jul 2007, 03:01:15 »
is dere a way to detect if a give position is near a tree ???

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: position near a tree
« Reply #1 on: 01 Jul 2007, 06:00:01 »
I believe you use nearestobject type, like

_Tree = position player nearestObject "Tree"

Not sure of thats the correct type or not
Xbox Rocks

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: position near a tree
« Reply #2 on: 01 Jul 2007, 12:22:46 »
yeah is just kind find da right object type 4 tree... tried a hint w/ da typeOf command but it doesnt work ???  :dunno:

also im not sure dat it can register trees dat r in a forest object ?

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: position near a tree
« Reply #3 on: 01 Jul 2007, 17:13:04 »
Sadly trees and bushes don't have a classname, they are .wrp placed objects.

I'm sure this sort of thing was discussed recently and some sort of workaraound was found.....maybe.
I'll look and see if I can find it again.

ArmA also does not have forest objects, they are 'old technology'   :P


Planck
I know a little about a lot, and a lot about a little.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: position near a tree
« Reply #4 on: 03 Jul 2007, 19:14:54 »
There is a workaround, but it is hindered by the lack of any string functions. You can get all objects within a radius using nearestObjects specifying class type as an empty array i.e. []. You can then loop through this list and check the bounding box size to remove the objects that are too small to be a tree (like a bullet or a bumblebee). You can also view the p3d name of the object.

If ArmA had string functions you could then do a substring search that compared the p3d names to a list of known substrings that commonly occur in the names of bush and tree objects. However, ArmA does not have string functions so you are out of luck AFAIK.
urp!

Offline Trexian

  • Members
  • *
Re: position near a tree
« Reply #5 on: 26 Feb 2009, 17:48:22 »
I found this in searching, and I don't think there's any more recent post on this subject - apologies if there is. :)

Building on this idea, would it be possible to build the array of nearestObjects, then cull that of any objects that are too small (or actually, store the right-sized stuff in a new array), then further cull the array of any objects that are of the class "building" and maybe "vehicle" I suppose?  That would only leave natural objects?
Sic semper tyrannosauro.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: position near a tree
« Reply #6 on: 26 Feb 2009, 18:32:48 »
You could do that to cull, but since we have string functions ArmA now, peanut's solution will work.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: position near a tree
« Reply #7 on: 26 Feb 2009, 19:33:35 »
I've written a nearRoads function and it works quite well. It compares all object names returned by nearestObjects with a list of road object names. The road object names where extracted from the README that came with BIS' environment sample models. Maybe the function can serve you as a basis for a nearTrees function:

Code: [Select]
#define ROAD_NAMES ["SILNICE_MESTO_6.P3D","SILNICE_MESTO_LP_6.P3D","SILNICE_MESTO_T_12.P3D","SILNICE_MESTO_X_12.P3D","SILNICE_MESTO_PREDX_6.P3D","SILNICE_MESTO_ZJZ.P3D","SILNICE_MESTO_ZVS.P3D","SILNICE_MESTO_ZZJ.P3D","SILNICE_MESTO_ZZS.P3D","ASF10 100.P3D","ASF10 25.P3D","ASF10 50.P3D","ASF10 75.P3D","ASF12.P3D","ASF25.P3D","ASF6.P3D","ASF6_PRECHOD.P3D","ASF6KONEC.P3D","CES10 100.P3D","CES10 25.P3D","CES10 50.P3D","CES10 75.P3D","CES12.P3D","CES25.P3D","CES6.P3D","CES6KONEC.P3D","CES_D10 100.P3D","CES_D10 25.P3D","CES_D10 50.P3D","CES_D10 75.P3D","CES_D12.P3D","CES_D25.P3D","CES_D6.P3D","CES_D6KONEC.P3D","KOS10 100.P3D","KOS10 25.P3D","KOS10 50.P3D","KOS10 75.P3D","KOS12.P3D","KOS25.P3D","KOS6.P3D","KOS6KONEC.P3D","KR_ASFALTKA_ASFALTKA_T.P3D","KR_ASFALTKA_CESTA_T.P3D","KR_ASFALTKA_SIL_T.P3D","KR_NEW_ASF_ASF_T.P3D","KR_NEW_ASF_CES_T.P3D","KR_NEW_ASF_SIL_T.P3D","KR_NEW_KOS.P3D","KR_NEW_KOS_KOS_T.P3D","KR_NEW_KOS_SIL_T.P3D","KR_NEW_SIL_ASF_T.P3D","KR_NEW_SIL_CES_T.P3D","KR_NEW_SIL_KOS_T.P3D","KR_NEW_SIL_SIL_T.P3D","KR_NEW_SIL_SIL_T_TEST.P3D","KR_NEW_SILXSIL.P3D","KR_SILNICE_ASFALTKA_T.P3D","KR_SILNICE_CESTA_T.P3D","KR_SILNICE_SILNICE_T.P3D","KR_SILNICEXSILNICE.P3D","SIL10 100.P3D","SIL10 25.P3D","SIL10 50.P3D","SIL10 75.P3D","SIL12.P3D","SIL25.P3D","SIL6.P3D","SIL6_PRECHOD.P3D","SIL6KONEC.P3D"]

#define ASCII_COLON 58


fn_nearRoads = {

    // This function returns an array of road objects

    private ["_position", "_radius", "_roads", "_objects", "_objInfo", "_lenInfo", "_objName", "_i"];

    _position = _this select 0; // can also be an object
    _radius   = _this select 1;

    assert (_radius <= 100); // 100m should be enough
    if (typeName _position == "OBJECT") then { _position = getPos _position };

    _roads   = [];
    _objects = [];

    // find all near objects but keep only those of unknown type
    {
        if ("" == typeOf _x) then { _objects = _objects + [_x] };
    } forEach nearestObjects [_position, [], _radius];

    {
        // _x is something like "5150: ces_d10 100.p3d"

        _objInfo = toArray(str(_x));
        _lenInfo = count _objInfo - 1;
        _objName = [];

        _i = 0;

        // determine where the object name starts
        {
            if (ASCII_COLON == _objInfo select _i) exitWith {};
            _i = _i + 1;
        } forEach _objInfo;
        _i = _i + 2; // skip the ": " part

        for "_k" from _i to _lenInfo do {
            _objName = _objName + [_objInfo select _k];
        };

        // To stick with the example above: _objName now contains "ces_d10 100.p3d"

        _objName = toUpper(toString(_objName));
        if (_objName in ROAD_NAMES) then { _roads = _roads + [_x] };

    } forEach _objects;

    _roads; // return value

}; // fn_nearRoads

Beware: I've replaced some variables names to make it more readable and did not test if afterwards.
try { return true; } finally { return false; }

Offline Trexian

  • Members
  • *
Re: position near a tree
« Reply #8 on: 26 Feb 2009, 19:46:03 »
Thanks Spooner!  I'll look at that stuff again, too.

And wow, WE, that looks awesome....  Some real stuff to get my head around.

Completely overlooked the use of the assert command in my scripts.  I take it that if the assert is false, the script just stops?  Any particular reason to make it stop, rather than just limit it to 100?

Thanks!
Sic semper tyrannosauro.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: position near a tree
« Reply #9 on: 26 Feb 2009, 20:13:08 »
The assert is used as an annoyance. It painfully tells me that I've just tried to freeze the ArmA process.

I've added it after calling the function with a radius >1km several times...  :D
try { return true; } finally { return false; }

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re: position near a tree
« Reply #10 on: 02 Mar 2009, 02:23:02 »
I've written a nearRoads function and it works quite well...


Hi there Worldeater, I was looking at functions on the BIS Wiki and it says there:
Quote
The last expression given in a function is returned to the calling instance. Note that there must not be a semicolon after this value.
I can see two semicolons after the return value, one immediately after the value "_roads" (which I assume MUST go) and another outside the loop. Do they BOTH need to go? I'm having trouble getting it to work (I replaced all the road names with tree names) and I'm just trying to lose all the errors I can identify. I don't know though whether losing both will introduce another error or losing just one is correct, or what :)

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: position near a tree
« Reply #11 on: 02 Mar 2009, 11:49:40 »
Quote from: Daniele Ganser, Swiss historian
Trust no one, research yourself.

Keep both semicolons and make sure the plant names are in upper case and end with ".P3D":

Code: [Select]
#define PLANT_NAMES ["DD_BOROVICE.P3D","DD_BOROVICE02.P3D","DD_BUSH01.P3D","DD_BUSH02.P3D"...
try { return true; } finally { return false; }

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re: position near a tree
« Reply #12 on: 02 Mar 2009, 12:14:34 »
Quote from: Daniele Ganser, Swiss historian
Trust no one, research yourself.
That's what I was doing over at the Biki ;)

Quote
Keep both semicolons and make sure the plant names are in upper case and end with ".P3D":

Code: [Select]
#define PLANT_NAMES ["DD_BOROVICE.P3D","DD_BOROVICE02.P3D","DD_BUSH01.P3D","DD_BUSH02.P3D"...
Yeah that seems to be the case. I'm not getting any joy from it though, I'll fiddle a little more then post up error messages & code if need be.