olseric 0 Posted April 6, 2004 Okay, I feel stupid. How do you use this command effectively? Here's what I'm trying to do: Find the object nearest to a jeep without actually choosing the jeep. Everytime I put it in, all I get back for a return is the jeep itself. Any help would be appreciated. Thanks, Eric Share this post Link to post Share on other sites
sa8gecko 0 Posted April 6, 2004 you have to displace the coordinates of nearestObject a little from the jeep itself (5 meters could be enough). To be sure to find all the objects, you should do this in at least three direction spaced 120 degrees each. Or you could take note of jeep position, then move it to a safer place, check with nearestObject, and put the jeep back. Be sure to check with nearestObject at a height that is not zero: ... nearestObject [getpos jeep select 0,getpos jeep select 1,2] Share this post Link to post Share on other sites
olseric 0 Posted April 6, 2004 I see what you're saying...basically, from the snippet that you posted there, you're using the X,Y,Z format of nearestObject. There is *supposedly* a second format as well, similar to nearestObject [objectname,"type"] The problem is, type means nothing to me and I can't seem to find anything in the editing references to this. I've thought about using the X,Y,Z format, but I feel the other way would be more efficient...if at all possible. Any further thoughts? Share this post Link to post Share on other sites
sa8gecko 0 Posted April 6, 2004 This second format you are talking about, is only useful if you want to get a particular kind of object. I.E.: ...nearestObject[myJeep,"M1A1"] * will find (if there is one) the nearest M1A1 to 'myJeep', but if you write: ...nearestObject[myJeep,"tank"] and you hope to find the nearest tank type (I mean, a T72, a T80 or a BMP, for example) you will end up with nothing, even if there's a T72 two meters away from 'myJeep'. What are you trying to do exactly ? I'm asking this because I can help you better if I know what you want. * can be used even this way: ...nearestObject [[x,y,z],"type"] Share this post Link to post Share on other sites
olseric 0 Posted April 6, 2004 Okay, I see what you're saying now. What I'm trying to do is implement this into a towing script. Â Right now, I have it so I can tow one object with the jeep. Â This is because the object is defined in the script. Â What I want to do is have dynamic assignment to the object to be towed based upon it being closest to my tow truck. Â Bottom line is, I can't turn planes around on the deck of the Nimitz...I need a tug. So, with that in mind, theoretically, if I wrote <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">nearestObject[myJeep,"A10"] it would find the nearest A10. Â But, if what you're saying is correct, I can't use it to find, say, the nearest aircraft. Is it possible to designate that "type" as an array? Â With a loop, I know it is, but just as written? If the above isn't possible, then I guess I'll have to revert to square one and using the x,y,z format. Thanks for your help. Share this post Link to post Share on other sites
Softegg 0 Posted April 6, 2004 to find the closest a10: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">... _distmin = 999 _distakt = 0 _object=ObjNull "_o = nearestObject [jeep1, _x]; _distakt=jeep1 distance _o; if (_distakt < _distmin) then {_distmin = _distakt; _object = _o}" foreach ["a10"] ?isnull _object:exit ... Share this post Link to post Share on other sites
olseric 0 Posted April 6, 2004 Quote[/b] ]<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">..._distmin = 999 _distakt = 0 _object=ObjNull "_o = nearestObject [jeep1, _x]; _distakt=jeep1 distance _o; if (_distakt < _distmin) then {_distmin = _distakt; _object = _o}" foreach ["a10"] ?isnull _object:exit ... Let's try and break this down: Obviously, _o is returning the nearest object to the jeep, with whatever _x stands for. What does _x stand for here? The _distatk is measuring the distance from the jeep to the object...I got that. Next it's checking to make sure it's within range, and if so, assigns _object to the value of _o, sorting for A10's. If I got that right, great. If not, tell me what I'm missing...especially that _x...I should be able to put something there according to the command ref, or, am I misreading that? Share this post Link to post Share on other sites
Softegg 0 Posted April 6, 2004 this code will find the nearest a10, it will be returned as _object. _x is the placeholder for the foreach-loop. nearestobject only finds objects about 50m around the center. Share this post Link to post Share on other sites
sa8gecko 0 Posted April 6, 2004 Quote[/b] ]Is it possible to designate that "type" as an array? With a loop, I know it is, but just as written? Yes, as long as you pass a string to nearestObject, that is the array must be written as: _array = ["A10","Su25",...] and you can write nearestObject as _x = nearestObject [jeep,(_array select _i)] where _i is used as a counter (0,1,2,...) Share this post Link to post Share on other sites
Grendel 0 Posted April 6, 2004 Howdy. (hey sa8gecko!) Need help with nearestObject as well, and figured I wouldn't start another thread (in addition to the one on OFPEC). I'm not sure if I'm understanding this entirely... If you don't specify a type in the array following the NearestObject command, then it will look for whatever the nearest object is regardless of type? (just want to be sure) If I was trying to find a nearest object in 3D space, would I have to put the z coordinates in the array or does it ignore altitude (like a trigger) as long as its over zero? would the following work to find the object (or lack thereof) a bullet impacts (after a bullet tracking script determines the final x,y,z of the round)? <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ;where _bx/_by/_bz are the bullet's final coordinates... ;place gamelogic at impact coordinates for range info... gamelogic setpos [_bx,_by,_bz] ;check to see if impact altitude is greater than 1... ?(_bz>1):goto "goodaltitude" _bz=_bz+1 #goodaltitude ;find nearest object to impact coordinates... _target= nearestObject [_bx,_by,_bz] ;check for null object ***is this syntax right???*** ?(_target isNull):goto "notarget" ;get distance from impact to target _distance=_target distance gamelogic ;see if bullet actually hit target, might be able to reduce value below one ?(_distance>1):goto "nohit" player sidechat format["I just hit %1!",_target] exit #nohit player sidechat format["I just missed %1 by %2 meters", _target, _dis] exit #notarg player sidechat "I didn't even come close!" exit Thanks! -Grendel Share this post Link to post Share on other sites
sa8gecko 0 Posted April 7, 2004 Quote[/b] ]If you don't specify a type in the array following the NearestObject command, then it will look for whatever the nearest object is regardless of type? (just want to be sure) Yes, the unit itself if you call the command this way: ... nearestObject [myUnit,""] Quote[/b] ]If I was trying to find a nearest object in 3D space, would I have to put the z coordinates in the array or does it ignore altitude (like a trigger) as long as its over zero? In my tries with nearestObject I can say that z matters. NearestObject returns the nearest object to the position passed to it in a range of about 50 meters (that is 100 meters diameter). About the code you wrote: it should work, but how do you know bullet final coordinates ? (this, I think, was underlined at OFPEC). Share this post Link to post Share on other sites
olseric 0 Posted April 9, 2004 Just a thanks guys...I did eventually get it to work. The nearestobject (myguy,"string") format didn't work for me. Â Couldn't get it to work correctly. Â But, as I am doing a towing script, I fixed the problem by using x,y,z format and specifing a spot 15m behind me. Â Works great now. Basically, what I created it for was the Nimitz carrier. Â I found that my deck got clutted because I couldn't put the planes away after landing. Â Now, I can tow them around. If anyone wants the script, just drop me a line: Â olseric@charter.net -Eric Share this post Link to post Share on other sites